Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da183c7a authored by Roland Dreier's avatar Roland Dreier
Browse files

IB/uverbs: Use get_unused_fd_flags(O_CLOEXEC) instead of get_unused_fd()



The macro get_unused_fd() is used to allocate a file descriptor with
default flags.  Those default flags (0) can be "unsafe": O_CLOEXEC must
be used by default to not leak file descriptor across exec().

Replace calls to get_unused_fd() in uverbs with calls to
get_unused_fd_flags(O_CLOEXEC).  Inheriting uverbs fds across exec()
cannot be used to do anything useful.

Based on a patch/suggestion from Yann Droneaud <ydroneaud@opteya.com>.

Signed-off-by: default avatarRoland Dreier <roland@purestorage.com>
parent 80b15043
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -334,7 +334,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,


	resp.num_comp_vectors = file->device->num_comp_vectors;
	resp.num_comp_vectors = file->device->num_comp_vectors;


	ret = get_unused_fd();
	ret = get_unused_fd_flags(O_CLOEXEC);
	if (ret < 0)
	if (ret < 0)
		goto err_free;
		goto err_free;
	resp.async_fd = ret;
	resp.async_fd = ret;
@@ -1184,7 +1184,7 @@ ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file,
	if (copy_from_user(&cmd, buf, sizeof cmd))
	if (copy_from_user(&cmd, buf, sizeof cmd))
		return -EFAULT;
		return -EFAULT;


	ret = get_unused_fd();
	ret = get_unused_fd_flags(O_CLOEXEC);
	if (ret < 0)
	if (ret < 0)
		return ret;
		return ret;
	resp.fd = ret;
	resp.fd = ret;