Skip to content

Commit b2a5bf1

Browse files
braunergregkh
authored andcommitted
fork: use pidfd_prepare()
commit ca7707f5430ad6b1c9cb7cee0a7f67d69328bb2d upstream. Stop open-coding get_unused_fd_flags() and anon_inode_getfile(). That's brittle just for keeping the flags between both calls in sync. Use the dedicated helper. Message-Id: <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1ced79b commit b2a5bf1

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

kernel/fork.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,21 +2378,12 @@ static __latent_entropy struct task_struct *copy_process(
23782378
* if the fd table isn't shared).
23792379
*/
23802380
if (clone_flags & CLONE_PIDFD) {
2381-
retval = get_unused_fd_flags(O_RDWR | O_CLOEXEC);
2381+
/* Note that no task has been attached to @pid yet. */
2382+
retval = __pidfd_prepare(pid, O_RDWR | O_CLOEXEC, &pidfile);
23822383
if (retval < 0)
23832384
goto bad_fork_free_pid;
2384-
23852385
pidfd = retval;
23862386

2387-
pidfile = anon_inode_getfile("[pidfd]", &pidfd_fops, pid,
2388-
O_RDWR | O_CLOEXEC);
2389-
if (IS_ERR(pidfile)) {
2390-
put_unused_fd(pidfd);
2391-
retval = PTR_ERR(pidfile);
2392-
goto bad_fork_free_pid;
2393-
}
2394-
get_pid(pid); /* held by pidfile now */
2395-
23962387
retval = put_user(pidfd, args->pidfd);
23972388
if (retval)
23982389
goto bad_fork_put_pidfd;

0 commit comments

Comments
 (0)