public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [GIT PULL] pidfd updates
@ 2021-11-10 14:52 Christian Brauner
  2021-11-11  0:25 ` pr-tracker-bot
  0 siblings, 1 reply; 25+ messages in thread
From: Christian Brauner @ 2021-11-10 14:52 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

Hi Linus,

/* Summary */
Various places in the kernel have picked up pidfds. The two most recent
additions have probably been the ability to use pidfds in bpf maps and the
usage of pidfds in mm-based syscalls such as process_mrelease() and
process_madvise(). The same pattern to turn a pidfd into a struct task exists
in two places. One of those places used PIDTYPE_TGID while the other one used
PIDTYPE_PID even though it is clearly documented in all pidfd-helpers that
pidfds __currently__ only refer to thread-group leaders (subject to change in
the future if need be). This isn't a bug per se but has the potential to be one
if we allow pidfds to refer to individual threads. If that happens we want to
audit all codepaths that make use of them to ensure they can deal with pidfds
refering to individual threads. This pull request adds a simple helper to turn
a pidfd into a struct task making it easy to grep for such places. Plus, it
gets rid of code-duplication.

(This is coming a bit later than usual because of a few fixes I was working on.)

/* Testing */
All patches have been in linux-next since 5.15-rc5. No build failures or
warnings were observed. All old and new tests are passing.

/* Conflicts */
At the time of creating this PR no merge conflicts were reported from
linux-next. However, a trivial merge conflict exists with current mainline.

diff --cc mm/oom_kill.c
index 195b3661da3d,70d399d5817e..000000000000
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@@ -1149,8 -1150,7 +1149,7 @@@ SYSCALL_DEFINE2(process_mrelease, int,
        struct task_struct *task;
        struct task_struct *p;
        unsigned int f_flags;
 -      bool reap = true;
 +      bool reap = false;
-       struct pid *pid;
        long ret = 0;

        if (flags)
@@@ -1200,12 -1194,9 +1193,10 @@@
        mmap_read_unlock(mm);

  drop_mm:
 -      mmdrop(mm);
 +      if (mm)
 +              mmput(mm);
  put_task:
        put_task_struct(task);
- put_pid:
-       put_pid(pid);
        return ret;
  #else
        return -ENOSYS;

The following changes since commit 64570fbc14f8d7cb3fe3995f20e26bc25ce4b2cc:

  Linux 5.15-rc5 (2021-10-10 17:01:59 -0700)

are available in the Git repository at:

  git@gitolite.kernel.org:pub/scm/linux/kernel/git/brauner/linux tags/pidfd.v5.16

for you to fetch changes up to ee9955d61a0a770152f9c3af470bd1689f034c74:

  mm: use pidfd_get_task() (2021-10-14 13:29:22 +0200)

Please consider pulling these changes from the signed pidfd.v5.16 tag.

Thanks!
Christian

----------------------------------------------------------------
pidfd.v5.16

----------------------------------------------------------------
Christian Brauner (2):
      pid: add pidfd_get_task() helper
      mm: use pidfd_get_task()

 include/linux/pid.h |  1 +
 kernel/pid.c        | 36 ++++++++++++++++++++++++++++++++++++
 mm/madvise.c        | 15 +++------------
 mm/oom_kill.c       | 15 +++------------
 4 files changed, 43 insertions(+), 24 deletions(-)

^ permalink raw reply	[flat|nested] 25+ messages in thread
* [GIT PULL] pidfd updates
@ 2023-04-21 13:41 Christian Brauner
  2023-04-24 20:24 ` Linus Torvalds
  2023-04-24 21:45 ` pr-tracker-bot
  0 siblings, 2 replies; 25+ messages in thread
From: Christian Brauner @ 2023-04-21 13:41 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Christian Brauner, linux-fsdevel, linux-kernel

Hey Linus,

/* Summary */
This adds a new pidfd_prepare() helper which allows the caller to
reserve a pidfd number and allocates a new pidfd file that stashes the
provided struct pid.

It should be avoided installing a file descriptor into a task's file
descriptor table just to close it again via close_fd() in case an
error occurs. The fd has been visible to userspace and might already be
in use. Instead, a file descriptor should be reserved but not installed
into the caller's file descriptor table.

If another failure path is hit then the reserved file descriptor and
file can just be put without any userspace visible side-effects. And if
all failure paths are cleared the file descriptor and file can be
installed into the task's file descriptor table.

This helper is now used in all places that open coded this functionality
before. For example, this is currently done during copy_process() and
fanotify used pidfd_create(), which returns a pidfd that has already
been made visibile in the caller's file descriptor table, but then
closed it using close_fd().

In one of the next merge windows there is also new functionality coming
to unix domain sockets that will have to rely on pidfd_prepare().

/* Testing */
clang: Ubuntu clang version 15.0.6
gcc: (Ubuntu 12.2.0-3ubuntu1) 12.2.0

All patches are based on 6.3-rc4 and have been sitting in linux-next.
No build failures or warnings were observed. All old and new tests in
fstests, selftests, and LTP pass without regressions.

/* Conflicts */
At the time of creating this PR no merge conflicts were reported from
linux-next and no merge conflicts showed up doing a test-merge with
current mainline.

The following changes since commit 197b6b60ae7bc51dd0814953c562833143b292aa:

  Linux 6.3-rc4 (2023-03-26 14:40:20 -0700)

are available in the Git repository at:

  git@gitolite.kernel.org:pub/scm/linux/kernel/git/brauner/linux tags/v6.4/pidfd.file

for you to fetch changes up to eee3a0e93924f2aab8ebaa7f2e26fd0f3b33f9e7:

  fanotify: use pidfd_prepare() (2023-04-03 11:16:57 +0200)

Please consider pulling these changes from the signed v6.4/pidfd.file tag.

Thanks!
Christian

----------------------------------------------------------------
v6.4/pidfd.file

----------------------------------------------------------------
Christian Brauner (3):
      pid: add pidfd_prepare()
      fork: use pidfd_prepare()
      fanotify: use pidfd_prepare()

 fs/notify/fanotify/fanotify_user.c | 13 +++--
 include/linux/pid.h                |  1 +
 kernel/fork.c                      | 98 +++++++++++++++++++++++++++++++++-----
 kernel/pid.c                       | 19 +++-----
 4 files changed, 104 insertions(+), 27 deletions(-)

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2023-05-02  7:13 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-10 14:52 [GIT PULL] pidfd updates Christian Brauner
2021-11-11  0:25 ` pr-tracker-bot
  -- strict thread matches above, loose matches on Subject: below --
2023-04-21 13:41 Christian Brauner
2023-04-24 20:24 ` Linus Torvalds
2023-04-24 20:35   ` Linus Torvalds
2023-04-25 12:08     ` Christian Brauner
2023-04-25  6:04   ` Al Viro
2023-04-25 12:34     ` Christian Brauner
2023-04-25 13:54       ` Al Viro
2023-04-25 14:36         ` Christian Brauner
2023-04-25 15:48           ` Al Viro
2023-04-25 16:28       ` Linus Torvalds
2023-04-25 17:19         ` Al Viro
2023-04-28  8:40         ` David Laight
2023-04-28 18:26           ` Linus Torvalds
2023-04-27  1:07       ` Al Viro
2023-04-27  7:39         ` Al Viro
2023-04-27  8:33           ` Christian Brauner
2023-04-27  8:59             ` Al Viro
2023-04-27  9:40               ` Christian Brauner
2023-04-27 15:21           ` Linus Torvalds
2023-04-27 17:02             ` Al Viro
2023-05-02  7:11               ` Christian Brauner
2023-04-27  8:11         ` Christian Brauner
2023-04-24 21:45 ` pr-tracker-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox