Skip to content

proc: Ensure we see the exit of each process tid exactly

Eric W. Biederman kernel-hardening linux-api linux-fsdevel linux-security-module lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v4 Latest2 patches 6 repliesIn review

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2rculist: Add hlists_swap_heads_rcuinclude/linux/rculist.h+21 -00 replies
2/2proc: Ensure we see the exit of each process tid exactly oncefs/exec.c include/linux/pid.h kernel/pid.c+21 -40 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchLinus Torvalds
SeriesA-b
1/2
2/2

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

Read the v4 thread

Cover letter [PATCH v4 0/2] proc: Ensure we see the exit of each process tid exactly

In the work to remove proc_mnt I noticed that we were calling proc_flush_task now proc_flush_pid possibly multiple times for the same pid because of how de_thread works.

This is a bare minimal patchset to sort out de_thread, by introducing exchange_tids and the helper of exchange_tids hlists_swap_heads_rcu.

The actual call of exchange_tids should be slowpath so I have prioritized readability over getting every last drop of performance.

I have also read through a bunch of the code to see if I could find anything that would be affected by this change. Users of has_group_leader_pid were a good canidates. But I also looked at other cases that might have a pid->task->pid transition. I ignored other sources of races with de_thread and exec as those are preexisting.

I found a close call with send_signals user of task_active_pid_ns, but all pids of a thread group are guaranteeds to be in the same pid namespace so there is not a problem.

I found a few pieces of debugging code that do:

	task = pid_task(pid, PIDTYPE_PID);
        if (task) {
        	printk("%u\n", task->pid);
        }

But I can't see how we care if it happens at the wrong moment that task->pid might not match pid_nr(pid);

Similarly because the code in posix-cpu-timers goes pid->task->pid it feels like there should be a problem. But as the code that works with PIDTYPE_PID is only available within the thread group, and as de_thread kills all of the other threads before it makes any changes of this kind the race can not happen.

In short I don't think this change will introduce any regressions.

Eric W. Biederman (2):
rculist: Add hlists_swap_heads_rcu
proc: Ensure we see the exit of each process tid exactly once

 fs/exec.c               |  5 +----
 include/linux/pid.h     |  1 +
 include/linux/rculist.h | 21 +++++++++++++++++++++
 kernel/pid.c            | 19 +++++++++++++++++++
 4 files changed, 42 insertions(+), 4 deletions(-)

Eric