<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-stable.git/kernel/signal.c, branch v5.7.3</title>
<subtitle>Linux kernel stable tree</subtitle>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/'/>
<entry>
<title>Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace</title>
<updated>2020-04-23T20:30:18+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2020-04-23T20:30:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=b4f633221f0aeac102e463a4be46a643b2e3b819'/>
<id>b4f633221f0aeac102e463a4be46a643b2e3b819</id>
<content type='text'>
Pull SIGCHLD fix from Eric Biederman:
 "Christof Meerwald reported that do_notify_parent has not been
  successfully populating si_pid and si_uid for multi-threaded
  processes.

  This is the one-liner fix. Strictly speaking a one-liner plus
  comment"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace:
  signal: Avoid corrupting si_pid and si_uid in do_notify_parent
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Pull SIGCHLD fix from Eric Biederman:
 "Christof Meerwald reported that do_notify_parent has not been
  successfully populating si_pid and si_uid for multi-threaded
  processes.

  This is the one-liner fix. Strictly speaking a one-liner plus
  comment"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace:
  signal: Avoid corrupting si_pid and si_uid in do_notify_parent
</pre>
</div>
</content>
</entry>
<entry>
<title>signal: Avoid corrupting si_pid and si_uid in do_notify_parent</title>
<updated>2020-04-21T14:55:30+00:00</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2020-04-20T16:41:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=61e713bdca3678e84815f2427f7a063fc353a1fc'/>
<id>61e713bdca3678e84815f2427f7a063fc353a1fc</id>
<content type='text'>
Christof Meerwald &lt;cmeerw@cmeerw.org&gt; writes:
&gt; Hi,
&gt;
&gt; this is probably related to commit
&gt; 7a0cf094944e2540758b7f957eb6846d5126f535 (signal: Correct namespace
&gt; fixups of si_pid and si_uid).
&gt;
&gt; With a 5.6.5 kernel I am seeing SIGCHLD signals that don't include a
&gt; properly set si_pid field - this seems to happen for multi-threaded
&gt; child processes.
&gt;
&gt; A simple test program (based on the sample from the signalfd man page):
&gt;
&gt; #include &lt;sys/signalfd.h&gt;
&gt; #include &lt;signal.h&gt;
&gt; #include &lt;unistd.h&gt;
&gt; #include &lt;spawn.h&gt;
&gt; #include &lt;stdlib.h&gt;
&gt; #include &lt;stdio.h&gt;
&gt;
&gt; #define handle_error(msg) \
&gt;     do { perror(msg); exit(EXIT_FAILURE); } while (0)
&gt;
&gt; int main(int argc, char *argv[])
&gt; {
&gt;   sigset_t mask;
&gt;   int sfd;
&gt;   struct signalfd_siginfo fdsi;
&gt;   ssize_t s;
&gt;
&gt;   sigemptyset(&amp;mask);
&gt;   sigaddset(&amp;mask, SIGCHLD);
&gt;
&gt;   if (sigprocmask(SIG_BLOCK, &amp;mask, NULL) == -1)
&gt;     handle_error("sigprocmask");
&gt;
&gt;   pid_t chldpid;
&gt;   char *chldargv[] = { "./sfdclient", NULL };
&gt;   posix_spawn(&amp;chldpid, "./sfdclient", NULL, NULL, chldargv, NULL);
&gt;
&gt;   sfd = signalfd(-1, &amp;mask, 0);
&gt;   if (sfd == -1)
&gt;     handle_error("signalfd");
&gt;
&gt;   for (;;) {
&gt;     s = read(sfd, &amp;fdsi, sizeof(struct signalfd_siginfo));
&gt;     if (s != sizeof(struct signalfd_siginfo))
&gt;       handle_error("read");
&gt;
&gt;     if (fdsi.ssi_signo == SIGCHLD) {
&gt;       printf("Got SIGCHLD %d %d %d %d\n",
&gt;           fdsi.ssi_status, fdsi.ssi_code,
&gt;           fdsi.ssi_uid, fdsi.ssi_pid);
&gt;       return 0;
&gt;     } else {
&gt;       printf("Read unexpected signal\n");
&gt;     }
&gt;   }
&gt; }
&gt;
&gt;
&gt; and a multi-threaded client to test with:
&gt;
&gt; #include &lt;unistd.h&gt;
&gt; #include &lt;pthread.h&gt;
&gt;
&gt; void *f(void *arg)
&gt; {
&gt;   sleep(100);
&gt; }
&gt;
&gt; int main()
&gt; {
&gt;   pthread_t t[8];
&gt;
&gt;   for (int i = 0; i != 8; ++i)
&gt;   {
&gt;     pthread_create(&amp;t[i], NULL, f, NULL);
&gt;   }
&gt; }
&gt;
&gt; I tried to do a bit of debugging and what seems to be happening is
&gt; that
&gt;
&gt;   /* From an ancestor pid namespace? */
&gt;   if (!task_pid_nr_ns(current, task_active_pid_ns(t))) {
&gt;
&gt; fails inside task_pid_nr_ns because the check for "pid_alive" fails.
&gt;
&gt; This code seems to be called from do_notify_parent and there we
&gt; actually have "tsk != current" (I am assuming both are threads of the
&gt; current process?)

I instrumented the code with a warning and received the following backtrace:
&gt; WARNING: CPU: 0 PID: 777 at kernel/pid.c:501 __task_pid_nr_ns.cold.6+0xc/0x15
&gt; Modules linked in:
&gt; CPU: 0 PID: 777 Comm: sfdclient Not tainted 5.7.0-rc1userns+ #2924
&gt; Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
&gt; RIP: 0010:__task_pid_nr_ns.cold.6+0xc/0x15
&gt; Code: ff 66 90 48 83 ec 08 89 7c 24 04 48 8d 7e 08 48 8d 74 24 04 e8 9a b6 44 00 48 83 c4 08 c3 48 c7 c7 59 9f ac 82 e8 c2 c4 04 00 &lt;0f&gt; 0b e9 3fd
&gt; RSP: 0018:ffffc9000042fbf8 EFLAGS: 00010046
&gt; RAX: 000000000000000c RBX: 0000000000000000 RCX: ffffc9000042faf4
&gt; RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff81193d29
&gt; RBP: ffffc9000042fc18 R08: 0000000000000000 R09: 0000000000000001
&gt; R10: 000000100f938416 R11: 0000000000000309 R12: ffff8880b941c140
&gt; R13: 0000000000000000 R14: 0000000000000000 R15: ffff8880b941c140
&gt; FS:  0000000000000000(0000) GS:ffff8880bca00000(0000) knlGS:0000000000000000
&gt; CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
&gt; CR2: 00007f2e8c0a32e0 CR3: 0000000002e10000 CR4: 00000000000006f0
&gt; Call Trace:
&gt;  send_signal+0x1c8/0x310
&gt;  do_notify_parent+0x50f/0x550
&gt;  release_task.part.21+0x4fd/0x620
&gt;  do_exit+0x6f6/0xaf0
&gt;  do_group_exit+0x42/0xb0
&gt;  get_signal+0x13b/0xbb0
&gt;  do_signal+0x2b/0x670
&gt;  ? __audit_syscall_exit+0x24d/0x2b0
&gt;  ? rcu_read_lock_sched_held+0x4d/0x60
&gt;  ? kfree+0x24c/0x2b0
&gt;  do_syscall_64+0x176/0x640
&gt;  ? trace_hardirqs_off_thunk+0x1a/0x1c
&gt;  entry_SYSCALL_64_after_hwframe+0x49/0xb3

The immediate problem is as Christof noticed that "pid_alive(current) == false".
This happens because do_notify_parent is called from the last thread to exit
in a process after that thread has been reaped.

The bigger issue is that do_notify_parent can be called from any
process that manages to wait on a thread of a multi-threaded process
from wait_task_zombie.  So any logic based upon current for
do_notify_parent is just nonsense, as current can be pretty much
anything.

So change do_notify_parent to call __send_signal directly.

Inspecting the code it appears this problem has existed since the pid
namespace support started handling this case in 2.6.30.  This fix only
backports to 7a0cf094944e ("signal: Correct namespace fixups of si_pid and si_uid")
where the problem logic was moved out of __send_signal and into send_signal.

Cc: stable@vger.kernel.org
Fixes: 6588c1e3ff01 ("signals: SI_USER: Masquerade si_pid when crossing pid ns boundary")
Ref: 921cf9f63089 ("signals: protect cinit from unblocked SIG_DFL signals")
Link: https://lore.kernel.org/lkml/20200419201336.GI22017@edge.cmeerw.net/
Reported-by: Christof Meerwald &lt;cmeerw@cmeerw.org&gt;
Acked-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Acked-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Christof Meerwald &lt;cmeerw@cmeerw.org&gt; writes:
&gt; Hi,
&gt;
&gt; this is probably related to commit
&gt; 7a0cf094944e2540758b7f957eb6846d5126f535 (signal: Correct namespace
&gt; fixups of si_pid and si_uid).
&gt;
&gt; With a 5.6.5 kernel I am seeing SIGCHLD signals that don't include a
&gt; properly set si_pid field - this seems to happen for multi-threaded
&gt; child processes.
&gt;
&gt; A simple test program (based on the sample from the signalfd man page):
&gt;
&gt; #include &lt;sys/signalfd.h&gt;
&gt; #include &lt;signal.h&gt;
&gt; #include &lt;unistd.h&gt;
&gt; #include &lt;spawn.h&gt;
&gt; #include &lt;stdlib.h&gt;
&gt; #include &lt;stdio.h&gt;
&gt;
&gt; #define handle_error(msg) \
&gt;     do { perror(msg); exit(EXIT_FAILURE); } while (0)
&gt;
&gt; int main(int argc, char *argv[])
&gt; {
&gt;   sigset_t mask;
&gt;   int sfd;
&gt;   struct signalfd_siginfo fdsi;
&gt;   ssize_t s;
&gt;
&gt;   sigemptyset(&amp;mask);
&gt;   sigaddset(&amp;mask, SIGCHLD);
&gt;
&gt;   if (sigprocmask(SIG_BLOCK, &amp;mask, NULL) == -1)
&gt;     handle_error("sigprocmask");
&gt;
&gt;   pid_t chldpid;
&gt;   char *chldargv[] = { "./sfdclient", NULL };
&gt;   posix_spawn(&amp;chldpid, "./sfdclient", NULL, NULL, chldargv, NULL);
&gt;
&gt;   sfd = signalfd(-1, &amp;mask, 0);
&gt;   if (sfd == -1)
&gt;     handle_error("signalfd");
&gt;
&gt;   for (;;) {
&gt;     s = read(sfd, &amp;fdsi, sizeof(struct signalfd_siginfo));
&gt;     if (s != sizeof(struct signalfd_siginfo))
&gt;       handle_error("read");
&gt;
&gt;     if (fdsi.ssi_signo == SIGCHLD) {
&gt;       printf("Got SIGCHLD %d %d %d %d\n",
&gt;           fdsi.ssi_status, fdsi.ssi_code,
&gt;           fdsi.ssi_uid, fdsi.ssi_pid);
&gt;       return 0;
&gt;     } else {
&gt;       printf("Read unexpected signal\n");
&gt;     }
&gt;   }
&gt; }
&gt;
&gt;
&gt; and a multi-threaded client to test with:
&gt;
&gt; #include &lt;unistd.h&gt;
&gt; #include &lt;pthread.h&gt;
&gt;
&gt; void *f(void *arg)
&gt; {
&gt;   sleep(100);
&gt; }
&gt;
&gt; int main()
&gt; {
&gt;   pthread_t t[8];
&gt;
&gt;   for (int i = 0; i != 8; ++i)
&gt;   {
&gt;     pthread_create(&amp;t[i], NULL, f, NULL);
&gt;   }
&gt; }
&gt;
&gt; I tried to do a bit of debugging and what seems to be happening is
&gt; that
&gt;
&gt;   /* From an ancestor pid namespace? */
&gt;   if (!task_pid_nr_ns(current, task_active_pid_ns(t))) {
&gt;
&gt; fails inside task_pid_nr_ns because the check for "pid_alive" fails.
&gt;
&gt; This code seems to be called from do_notify_parent and there we
&gt; actually have "tsk != current" (I am assuming both are threads of the
&gt; current process?)

I instrumented the code with a warning and received the following backtrace:
&gt; WARNING: CPU: 0 PID: 777 at kernel/pid.c:501 __task_pid_nr_ns.cold.6+0xc/0x15
&gt; Modules linked in:
&gt; CPU: 0 PID: 777 Comm: sfdclient Not tainted 5.7.0-rc1userns+ #2924
&gt; Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
&gt; RIP: 0010:__task_pid_nr_ns.cold.6+0xc/0x15
&gt; Code: ff 66 90 48 83 ec 08 89 7c 24 04 48 8d 7e 08 48 8d 74 24 04 e8 9a b6 44 00 48 83 c4 08 c3 48 c7 c7 59 9f ac 82 e8 c2 c4 04 00 &lt;0f&gt; 0b e9 3fd
&gt; RSP: 0018:ffffc9000042fbf8 EFLAGS: 00010046
&gt; RAX: 000000000000000c RBX: 0000000000000000 RCX: ffffc9000042faf4
&gt; RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff81193d29
&gt; RBP: ffffc9000042fc18 R08: 0000000000000000 R09: 0000000000000001
&gt; R10: 000000100f938416 R11: 0000000000000309 R12: ffff8880b941c140
&gt; R13: 0000000000000000 R14: 0000000000000000 R15: ffff8880b941c140
&gt; FS:  0000000000000000(0000) GS:ffff8880bca00000(0000) knlGS:0000000000000000
&gt; CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
&gt; CR2: 00007f2e8c0a32e0 CR3: 0000000002e10000 CR4: 00000000000006f0
&gt; Call Trace:
&gt;  send_signal+0x1c8/0x310
&gt;  do_notify_parent+0x50f/0x550
&gt;  release_task.part.21+0x4fd/0x620
&gt;  do_exit+0x6f6/0xaf0
&gt;  do_group_exit+0x42/0xb0
&gt;  get_signal+0x13b/0xbb0
&gt;  do_signal+0x2b/0x670
&gt;  ? __audit_syscall_exit+0x24d/0x2b0
&gt;  ? rcu_read_lock_sched_held+0x4d/0x60
&gt;  ? kfree+0x24c/0x2b0
&gt;  do_syscall_64+0x176/0x640
&gt;  ? trace_hardirqs_off_thunk+0x1a/0x1c
&gt;  entry_SYSCALL_64_after_hwframe+0x49/0xb3

The immediate problem is as Christof noticed that "pid_alive(current) == false".
This happens because do_notify_parent is called from the last thread to exit
in a process after that thread has been reaped.

The bigger issue is that do_notify_parent can be called from any
process that manages to wait on a thread of a multi-threaded process
from wait_task_zombie.  So any logic based upon current for
do_notify_parent is just nonsense, as current can be pretty much
anything.

So change do_notify_parent to call __send_signal directly.

Inspecting the code it appears this problem has existed since the pid
namespace support started handling this case in 2.6.30.  This fix only
backports to 7a0cf094944e ("signal: Correct namespace fixups of si_pid and si_uid")
where the problem logic was moved out of __send_signal and into send_signal.

Cc: stable@vger.kernel.org
Fixes: 6588c1e3ff01 ("signals: SI_USER: Masquerade si_pid when crossing pid ns boundary")
Ref: 921cf9f63089 ("signals: protect cinit from unblocked SIG_DFL signals")
Link: https://lore.kernel.org/lkml/20200419201336.GI22017@edge.cmeerw.net/
Reported-by: Christof Meerwald &lt;cmeerw@cmeerw.org&gt;
Acked-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Acked-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>signal: use kill_proc_info instead of kill_pid_info in kill_something_info</title>
<updated>2020-04-12T20:46:34+00:00</updated>
<author>
<name>Zhiqiang Liu</name>
<email>liuzhiqiang26@huawei.com</email>
</author>
<published>2020-03-30T02:44:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=3075afdf15b89a063f8d31c0db08a50472bb7faf'/>
<id>3075afdf15b89a063f8d31c0db08a50472bb7faf</id>
<content type='text'>
signal.c provides kill_proc_info, we can use it instead of kill_pid_info
in kill_something_info func gracefully.

Signed-off-by: Zhiqiang Liu &lt;liuzhiqiang26@huawei.com&gt;
Acked-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Acked-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
Link: https://lore.kernel.org/r/80236965-f0b5-c888-95ff-855bdec75bb3@huawei.com
Signed-off-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
signal.c provides kill_proc_info, we can use it instead of kill_pid_info
in kill_something_info func gracefully.

Signed-off-by: Zhiqiang Liu &lt;liuzhiqiang26@huawei.com&gt;
Acked-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Acked-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
Link: https://lore.kernel.org/r/80236965-f0b5-c888-95ff-855bdec75bb3@huawei.com
Signed-off-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>signal: check sig before setting info in kill_pid_usb_asyncio</title>
<updated>2020-04-12T20:46:34+00:00</updated>
<author>
<name>Zhiqiang Liu</name>
<email>liuzhiqiang26@huawei.com</email>
</author>
<published>2020-03-30T02:18:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=eaec2b0bd30690575c581eebffae64bfb7f684ac'/>
<id>eaec2b0bd30690575c581eebffae64bfb7f684ac</id>
<content type='text'>
In kill_pid_usb_asyncio, if signal is not valid, we do not need to
set info struct.

Signed-off-by: Zhiqiang Liu &lt;liuzhiqiang26@huawei.com&gt;
Acked-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
Link: https://lore.kernel.org/r/f525fd08-1cf7-fb09-d20c-4359145eb940@huawei.com
Signed-off-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In kill_pid_usb_asyncio, if signal is not valid, we do not need to
set info struct.

Signed-off-by: Zhiqiang Liu &lt;liuzhiqiang26@huawei.com&gt;
Acked-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
Link: https://lore.kernel.org/r/f525fd08-1cf7-fb09-d20c-4359145eb940@huawei.com
Signed-off-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace</title>
<updated>2020-04-02T18:22:17+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2020-04-02T18:22:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=d987ca1c6b7e22fbd30664111e85cec7aa66000d'/>
<id>d987ca1c6b7e22fbd30664111e85cec7aa66000d</id>
<content type='text'>
Pull exec/proc updates from Eric Biederman:
 "This contains two significant pieces of work: the work to sort out
  proc_flush_task, and the work to solve a deadlock between strace and
  exec.

  Fixing proc_flush_task so that it no longer requires a persistent
  mount makes improvements to proc possible. The removal of the
  persistent mount solves an old regression that that caused the hidepid
  mount option to only work on remount not on mount. The regression was
  found and reported by the Android folks. This further allows Alexey
  Gladkov's work making proc mount options specific to an individual
  mount of proc to move forward.

  The work on exec starts solving a long standing issue with exec that
  it takes mutexes of blocking userspace applications, which makes exec
  extremely deadlock prone. For the moment this adds a second mutex with
  a narrower scope that handles all of the easy cases. Which makes the
  tricky cases easy to spot. With a little luck the code to solve those
  deadlocks will be ready by next merge window"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (25 commits)
  signal: Extend exec_id to 64bits
  pidfd: Use new infrastructure to fix deadlocks in execve
  perf: Use new infrastructure to fix deadlocks in execve
  proc: io_accounting: Use new infrastructure to fix deadlocks in execve
  proc: Use new infrastructure to fix deadlocks in execve
  kernel/kcmp.c: Use new infrastructure to fix deadlocks in execve
  kernel: doc: remove outdated comment cred.c
  mm: docs: Fix a comment in process_vm_rw_core
  selftests/ptrace: add test cases for dead-locks
  exec: Fix a deadlock in strace
  exec: Add exec_update_mutex to replace cred_guard_mutex
  exec: Move exec_mmap right after de_thread in flush_old_exec
  exec: Move cleanup of posix timers on exec out of de_thread
  exec: Factor unshare_sighand out of de_thread and call it separately
  exec: Only compute current once in flush_old_exec
  pid: Improve the comment about waiting in zap_pid_ns_processes
  proc: Remove the now unnecessary internal mount of proc
  uml: Create a private mount of proc for mconsole
  uml: Don't consult current to find the proc_mnt in mconsole_proc
  proc: Use a list of inodes to flush from proc
  ...
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Pull exec/proc updates from Eric Biederman:
 "This contains two significant pieces of work: the work to sort out
  proc_flush_task, and the work to solve a deadlock between strace and
  exec.

  Fixing proc_flush_task so that it no longer requires a persistent
  mount makes improvements to proc possible. The removal of the
  persistent mount solves an old regression that that caused the hidepid
  mount option to only work on remount not on mount. The regression was
  found and reported by the Android folks. This further allows Alexey
  Gladkov's work making proc mount options specific to an individual
  mount of proc to move forward.

  The work on exec starts solving a long standing issue with exec that
  it takes mutexes of blocking userspace applications, which makes exec
  extremely deadlock prone. For the moment this adds a second mutex with
  a narrower scope that handles all of the easy cases. Which makes the
  tricky cases easy to spot. With a little luck the code to solve those
  deadlocks will be ready by next merge window"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: (25 commits)
  signal: Extend exec_id to 64bits
  pidfd: Use new infrastructure to fix deadlocks in execve
  perf: Use new infrastructure to fix deadlocks in execve
  proc: io_accounting: Use new infrastructure to fix deadlocks in execve
  proc: Use new infrastructure to fix deadlocks in execve
  kernel/kcmp.c: Use new infrastructure to fix deadlocks in execve
  kernel: doc: remove outdated comment cred.c
  mm: docs: Fix a comment in process_vm_rw_core
  selftests/ptrace: add test cases for dead-locks
  exec: Fix a deadlock in strace
  exec: Add exec_update_mutex to replace cred_guard_mutex
  exec: Move exec_mmap right after de_thread in flush_old_exec
  exec: Move cleanup of posix timers on exec out of de_thread
  exec: Factor unshare_sighand out of de_thread and call it separately
  exec: Only compute current once in flush_old_exec
  pid: Improve the comment about waiting in zap_pid_ns_processes
  proc: Remove the now unnecessary internal mount of proc
  uml: Create a private mount of proc for mconsole
  uml: Don't consult current to find the proc_mnt in mconsole_proc
  proc: Use a list of inodes to flush from proc
  ...
</pre>
</div>
</content>
</entry>
<entry>
<title>signal: Extend exec_id to 64bits</title>
<updated>2020-04-01T17:04:24+00:00</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2020-03-31T00:01:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=d1e7fd6462ca9fc76650fbe6ca800e35b24267da'/>
<id>d1e7fd6462ca9fc76650fbe6ca800e35b24267da</id>
<content type='text'>
Replace the 32bit exec_id with a 64bit exec_id to make it impossible
to wrap the exec_id counter.  With care an attacker can cause exec_id
wrap and send arbitrary signals to a newly exec'd parent.  This
bypasses the signal sending checks if the parent changes their
credentials during exec.

The severity of this problem can been seen that in my limited testing
of a 32bit exec_id it can take as little as 19s to exec 65536 times.
Which means that it can take as little as 14 days to wrap a 32bit
exec_id.  Adam Zabrocki has succeeded wrapping the self_exe_id in 7
days.  Even my slower timing is in the uptime of a typical server.
Which means self_exec_id is simply a speed bump today, and if exec
gets noticably faster self_exec_id won't even be a speed bump.

Extending self_exec_id to 64bits introduces a problem on 32bit
architectures where reading self_exec_id is no longer atomic and can
take two read instructions.  Which means that is is possible to hit
a window where the read value of exec_id does not match the written
value.  So with very lucky timing after this change this still
remains expoiltable.

I have updated the update of exec_id on exec to use WRITE_ONCE
and the read of exec_id in do_notify_parent to use READ_ONCE
to make it clear that there is no locking between these two
locations.

Link: https://lore.kernel.org/kernel-hardening/20200324215049.GA3710@pi3.com.pl
Fixes: 2.3.23pre2
Cc: stable@vger.kernel.org
Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Replace the 32bit exec_id with a 64bit exec_id to make it impossible
to wrap the exec_id counter.  With care an attacker can cause exec_id
wrap and send arbitrary signals to a newly exec'd parent.  This
bypasses the signal sending checks if the parent changes their
credentials during exec.

The severity of this problem can been seen that in my limited testing
of a 32bit exec_id it can take as little as 19s to exec 65536 times.
Which means that it can take as little as 14 days to wrap a 32bit
exec_id.  Adam Zabrocki has succeeded wrapping the self_exe_id in 7
days.  Even my slower timing is in the uptime of a typical server.
Which means self_exec_id is simply a speed bump today, and if exec
gets noticably faster self_exec_id won't even be a speed bump.

Extending self_exec_id to 64bits introduces a problem on 32bit
architectures where reading self_exec_id is no longer atomic and can
take two read instructions.  Which means that is is possible to hit
a window where the read value of exec_id does not match the written
value.  So with very lucky timing after this change this still
remains expoiltable.

I have updated the update of exec_id on exec to use WRITE_ONCE
and the read of exec_id in do_notify_parent to use READ_ONCE
to make it clear that there is no locking between these two
locations.

Link: https://lore.kernel.org/kernel-hardening/20200324215049.GA3710@pi3.com.pl
Fixes: 2.3.23pre2
Cc: stable@vger.kernel.org
Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>signal: avoid double atomic counter increments for user accounting</title>
<updated>2020-02-26T17:54:03+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2020-02-24T20:47:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=fda31c50292a5062332fa0343c084bd9f46604d9'/>
<id>fda31c50292a5062332fa0343c084bd9f46604d9</id>
<content type='text'>
When queueing a signal, we increment both the users count of pending
signals (for RLIMIT_SIGPENDING tracking) and we increment the refcount
of the user struct itself (because we keep a reference to the user in
the signal structure in order to correctly account for it when freeing).

That turns out to be fairly expensive, because both of them are atomic
updates, and particularly under extreme signal handling pressure on big
machines, you can get a lot of cache contention on the user struct.
That can then cause horrid cacheline ping-pong when you do these
multiple accesses.

So change the reference counting to only pin the user for the _first_
pending signal, and to unpin it when the last pending signal is
dequeued.  That means that when a user sees a lot of concurrent signal
queuing - which is the only situation when this matters - the only
atomic access needed is generally the 'sigpending' count update.

This was noticed because of a particularly odd timing artifact on a
dual-socket 96C/192T Cascade Lake platform: when you get into bad
contention, on that machine for some reason seems to be much worse when
the contention happens in the upper 32-byte half of the cacheline.

As a result, the kernel test robot will-it-scale 'signal1' benchmark had
an odd performance regression simply due to random alignment of the
'struct user_struct' (and pointed to a completely unrelated and
apparently nonsensical commit for the regression).

Avoiding the double increments (and decrements on the dequeueing side,
of course) makes for much less contention and hugely improved
performance on that will-it-scale microbenchmark.

Quoting Feng Tang:

 "It makes a big difference, that the performance score is tripled! bump
  from original 17000 to 54000. Also the gap between 5.0-rc6 and
  5.0-rc6+Jiri's patch is reduced to around 2%"

[ The "2% gap" is the odd cacheline placement difference on that
  platform: under the extreme contention case, the effect of which half
  of the cacheline was hot was 5%, so with the reduced contention the
  odd timing artifact is reduced too ]

It does help in the non-contended case too, but is not nearly as
noticeable.

Reported-and-tested-by: Feng Tang &lt;feng.tang@intel.com&gt;
Cc: Eric W. Biederman &lt;ebiederm@xmission.com&gt;
Cc: Huang, Ying &lt;ying.huang@intel.com&gt;
Cc: Philip Li &lt;philip.li@intel.com&gt;
Cc: Andi Kleen &lt;andi.kleen@intel.com&gt;
Cc: Jiri Olsa &lt;jolsa@redhat.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When queueing a signal, we increment both the users count of pending
signals (for RLIMIT_SIGPENDING tracking) and we increment the refcount
of the user struct itself (because we keep a reference to the user in
the signal structure in order to correctly account for it when freeing).

That turns out to be fairly expensive, because both of them are atomic
updates, and particularly under extreme signal handling pressure on big
machines, you can get a lot of cache contention on the user struct.
That can then cause horrid cacheline ping-pong when you do these
multiple accesses.

So change the reference counting to only pin the user for the _first_
pending signal, and to unpin it when the last pending signal is
dequeued.  That means that when a user sees a lot of concurrent signal
queuing - which is the only situation when this matters - the only
atomic access needed is generally the 'sigpending' count update.

This was noticed because of a particularly odd timing artifact on a
dual-socket 96C/192T Cascade Lake platform: when you get into bad
contention, on that machine for some reason seems to be much worse when
the contention happens in the upper 32-byte half of the cacheline.

As a result, the kernel test robot will-it-scale 'signal1' benchmark had
an odd performance regression simply due to random alignment of the
'struct user_struct' (and pointed to a completely unrelated and
apparently nonsensical commit for the regression).

Avoiding the double increments (and decrements on the dequeueing side,
of course) makes for much less contention and hugely improved
performance on that will-it-scale microbenchmark.

Quoting Feng Tang:

 "It makes a big difference, that the performance score is tripled! bump
  from original 17000 to 54000. Also the gap between 5.0-rc6 and
  5.0-rc6+Jiri's patch is reduced to around 2%"

[ The "2% gap" is the odd cacheline placement difference on that
  platform: under the extreme contention case, the effect of which half
  of the cacheline was hot was 5%, so with the reduced contention the
  odd timing artifact is reduced too ]

It does help in the non-contended case too, but is not nearly as
noticeable.

Reported-and-tested-by: Feng Tang &lt;feng.tang@intel.com&gt;
Cc: Eric W. Biederman &lt;ebiederm@xmission.com&gt;
Cc: Huang, Ying &lt;ying.huang@intel.com&gt;
Cc: Philip Li &lt;philip.li@intel.com&gt;
Cc: Andi Kleen &lt;andi.kleen@intel.com&gt;
Cc: Jiri Olsa &lt;jolsa@redhat.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>sched.h: Annotate sighand_struct with __rcu</title>
<updated>2020-01-26T09:54:47+00:00</updated>
<author>
<name>Madhuparna Bhowmik</name>
<email>madhuparnabhowmik10@gmail.com</email>
</author>
<published>2020-01-24T04:59:08+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=913292c97d750fe4188b4f5aa770e5e0ca1e5a91'/>
<id>913292c97d750fe4188b4f5aa770e5e0ca1e5a91</id>
<content type='text'>
This patch fixes the following sparse errors by annotating the
sighand_struct with __rcu

kernel/fork.c:1511:9: error: incompatible types in comparison expression
kernel/exit.c:100:19: error: incompatible types in comparison expression
kernel/signal.c:1370:27: error: incompatible types in comparison expression

This fix introduces the following sparse error in signal.c due to
checking the sighand pointer without rcu primitives:

kernel/signal.c:1386:21: error: incompatible types in comparison expression

This new sparse error is also fixed in this patch.

Signed-off-by: Madhuparna Bhowmik &lt;madhuparnabhowmik10@gmail.com&gt;
Acked-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
Link: https://lore.kernel.org/r/20200124045908.26389-1-madhuparnabhowmik10@gmail.com
Signed-off-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch fixes the following sparse errors by annotating the
sighand_struct with __rcu

kernel/fork.c:1511:9: error: incompatible types in comparison expression
kernel/exit.c:100:19: error: incompatible types in comparison expression
kernel/signal.c:1370:27: error: incompatible types in comparison expression

This fix introduces the following sparse error in signal.c due to
checking the sighand pointer without rcu primitives:

kernel/signal.c:1386:21: error: incompatible types in comparison expression

This new sparse error is also fixed in this patch.

Signed-off-by: Madhuparna Bhowmik &lt;madhuparnabhowmik10@gmail.com&gt;
Acked-by: Paul E. McKenney &lt;paulmck@kernel.org&gt;
Link: https://lore.kernel.org/r/20200124045908.26389-1-madhuparnabhowmik10@gmail.com
Signed-off-by: Christian Brauner &lt;christian.brauner@ubuntu.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>cgroup: freezer: call cgroup_enter_frozen() with preemption disabled in ptrace_stop()</title>
<updated>2019-10-11T15:39:57+00:00</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2019-10-09T15:02:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=937c6b27c73e02cd4114f95f5c37ba2c29fadba1'/>
<id>937c6b27c73e02cd4114f95f5c37ba2c29fadba1</id>
<content type='text'>
ptrace_stop() does preempt_enable_no_resched() to avoid the preemption,
but after that cgroup_enter_frozen() does spin_lock/unlock and this adds
another preemption point.

Reported-and-tested-by: Bruce Ashfield &lt;bruce.ashfield@gmail.com&gt;
Fixes: 76f969e8948d ("cgroup: cgroup v2 freezer")
Cc: stable@vger.kernel.org # v5.2+
Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Acked-by: Roman Gushchin &lt;guro@fb.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
ptrace_stop() does preempt_enable_no_resched() to avoid the preemption,
but after that cgroup_enter_frozen() does spin_lock/unlock and this adds
another preemption point.

Reported-and-tested-by: Bruce Ashfield &lt;bruce.ashfield@gmail.com&gt;
Fixes: 76f969e8948d ("cgroup: cgroup v2 freezer")
Cc: stable@vger.kernel.org # v5.2+
Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Acked-by: Roman Gushchin &lt;guro@fb.com&gt;
Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge tag 'core-process-v5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux</title>
<updated>2019-09-16T16:28:19+00:00</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2019-09-16T16:28:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=c17112a5c413f20188da276c138484e7127cdc84'/>
<id>c17112a5c413f20188da276c138484e7127cdc84</id>
<content type='text'>
Pull pidfd/waitid updates from Christian Brauner:
 "This contains two features and various tests.

  First, it adds support for waiting on process through pidfds by adding
  the P_PIDFD type to the waitid() syscall. This completes the basic
  functionality of the pidfd api (cf. [1]). In the meantime we also have
  a new adition to the userspace projects that make use of the pidfd
  api. The qt project was nice enough to send a mail pointing out that
  they have a pr up to switch to the pidfd api (cf. [2]).

  Second, this tag contains an extension to the waitid() syscall to make
  it possible to wait on the current process group in a race free manner
  (even though the actual problem is very unlikely) by specifing 0
  together with the P_PGID type. This extension traces back to a
  discussion on the glibc development mailing list.

  There are also a range of tests for the features above. Additionally,
  the test-suite which detected the pidfd-polling race we fixed in [3]
  is included in this tag"

[1] https://lwn.net/Articles/794707/
[2] https://codereview.qt-project.org/c/qt/qtbase/+/108456
[3] commit b191d6491be6 ("pidfd: fix a poll race when setting exit_state")

* tag 'core-process-v5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux:
  waitid: Add support for waiting for the current process group
  tests: add pidfd poll tests
  tests: move common definitions and functions into pidfd.h
  pidfd: add pidfd_wait tests
  pidfd: add P_PIDFD to waitid()
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Pull pidfd/waitid updates from Christian Brauner:
 "This contains two features and various tests.

  First, it adds support for waiting on process through pidfds by adding
  the P_PIDFD type to the waitid() syscall. This completes the basic
  functionality of the pidfd api (cf. [1]). In the meantime we also have
  a new adition to the userspace projects that make use of the pidfd
  api. The qt project was nice enough to send a mail pointing out that
  they have a pr up to switch to the pidfd api (cf. [2]).

  Second, this tag contains an extension to the waitid() syscall to make
  it possible to wait on the current process group in a race free manner
  (even though the actual problem is very unlikely) by specifing 0
  together with the P_PGID type. This extension traces back to a
  discussion on the glibc development mailing list.

  There are also a range of tests for the features above. Additionally,
  the test-suite which detected the pidfd-polling race we fixed in [3]
  is included in this tag"

[1] https://lwn.net/Articles/794707/
[2] https://codereview.qt-project.org/c/qt/qtbase/+/108456
[3] commit b191d6491be6 ("pidfd: fix a poll race when setting exit_state")

* tag 'core-process-v5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux:
  waitid: Add support for waiting for the current process group
  tests: add pidfd poll tests
  tests: move common definitions and functions into pidfd.h
  pidfd: add pidfd_wait tests
  pidfd: add P_PIDFD to waitid()
</pre>
</div>
</content>
</entry>
</feed>
