Skip to content

fix a race in release_task when flushing the dentry

Wen Yang lkml stable 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest7 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7clone: add CLONE_PIDFDinclude/linux/pid.h include/uapi/linux/sched.h kernel/fork.c+106 -40 replies
2/7pidfd: add polling supportinclude/linux/pid.h kernel/fork.c kernel/pid.c +1 more+42 -00 replies
3/7proc: Rename in proc_inode rename sysctl_inodes sibling_inodesfs/proc/inode.c fs/proc/internal.h fs/proc/proc_sysctl.c+6 -50 replies
4/7proc: Generalize proc_sys_prune_dcache into proc_prune_siblings_dcachefs/proc/inode.c fs/proc/internal.h fs/proc/proc_sysctl.c+40 -340 replies
5/7proc: Clear the pieces of proc_inode that proc_evict_inode cares aboutfs/proc/inode.c+11 -50 replies
6/7proc: Use d_invalidate in proc_prune_siblings_dcachefs/proc/inode.c fs/proc/internal.h fs/proc/proc_sysctl.c+19 -70 replies
7/7proc: Use a list of inodes to flush from procfs/proc/base.c fs/proc/inode.c fs/proc/internal.h +4 more+45 -790 replies

Reviews trailers per patch

2 of 7 patches have a Reviewed-by or Acked-by.

PatchOleg Nesterov
1/7R-b
2/7R-b
3/7
4/7
5/7
6/7
7/7

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 4.19 0/7] fix a race in release_task when flushing the dentry

The dentries such as /proc/<pid>/ns/ have the DCACHE_OP_DELETE flag, they should be deleted when the process exits.

Suppose the following race appears:

release_task dput
-> proc_flush_task

                             -> dentry->d_op->d_delete(dentry) 
-> __exit_signal 
                             -> dentry->d_lockref.count--  and return. 

In the proc_flush_task(), if another process is using this dentry, it will not be deleted. At the same time, in dput(), d_op->d_delete() can be executed before __exit_signal(pid has not been hashed), d_delete returns false, so this dentry still cannot be deleted.

This dentry will always be cached (although its count is 0 and the DCACHE_OP_DELETE flag is set), its parent denry will also be cached too, and these dentries can only be deleted when drop_caches is manually triggered.

This will result in wasted memory. What's more troublesome is that these dentries reference pid, according to the commit f333c700c610 ("pidns: Add a limit on the number of pid namespaces"), if the pid cannot be released, it may result in the inability to create a new pid_ns.

This issue was introduced by 60347f6716aa ("pid namespaces: prepare proc_flust_task() to flush entries from multiple proc trees"), exposed by f333c700c610 ("pidns: Add a limit on the number of pid namespaces"), and then fixed by 7bc3e6e55acf ("proc: Use a list of inodes to flush from proc").

Christian Brauner (1):
clone: add CLONE_PIDFD

Eric W. Biederman (5):
proc: Rename in proc_inode rename sysctl_inodes sibling_inodes
proc: Generalize proc_sys_prune_dcache into proc_prune_siblings_dcache
proc: Clear the pieces of proc_inode that proc_evict_inode cares about
proc: Use d_invalidate in proc_prune_siblings_dcache
proc: Use a list of inodes to flush from proc

Joel Fernandes (Google) (1):
pidfd: add polling support

 fs/proc/base.c             | 111 ++++++++++++-------------------------
 fs/proc/inode.c            |  67 +++++++++++++++++++++--
 fs/proc/internal.h         |   4 +-
 fs/proc/proc_sysctl.c      |  45 ++-------------
 include/linux/pid.h        |   6 ++
 include/linux/proc_fs.h    |   4 +-
 include/uapi/linux/sched.h |   1 +
 kernel/exit.c              |   4 +-
 kernel/fork.c              | 133 +++++++++++++++++++++++++++++++++++++++++++--
 kernel/pid.c               |   3 +
 kernel/signal.c            |  11 ++++
 11 files changed, 262 insertions(+), 127 deletions(-)
Signature · 1 line
1.8.3.1