<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/drivers/tty/tty_jobctrl.c, branch v6.19.11</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.19.11'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2023-09-18T09:14:43+00:00</updated>
<entry>
<title>tty: tty_jobctrl: fix pid memleak in disassociate_ctty()</title>
<updated>2023-09-18T09:14:43+00:00</updated>
<author>
<name>Yi Yang</name>
<email>yiyang13@huawei.com</email>
</author>
<published>2023-08-31T02:33:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=11e7f27b79757b6586645d87b95d5b78375ecdfc'/>
<id>urn:sha1:11e7f27b79757b6586645d87b95d5b78375ecdfc</id>
<content type='text'>
There is a pid leakage:
------------------------------
unreferenced object 0xffff88810c181940 (size 224):
  comm "sshd", pid 8191, jiffies 4294946950 (age 524.570s)
  hex dump (first 32 bytes):
    01 00 00 00 00 00 00 00 00 00 00 00 ad 4e ad de  .............N..
    ff ff ff ff 6b 6b 6b 6b ff ff ff ff ff ff ff ff  ....kkkk........
  backtrace:
    [&lt;ffffffff814774e6&gt;] kmem_cache_alloc+0x5c6/0x9b0
    [&lt;ffffffff81177342&gt;] alloc_pid+0x72/0x570
    [&lt;ffffffff81140ac4&gt;] copy_process+0x1374/0x2470
    [&lt;ffffffff81141d77&gt;] kernel_clone+0xb7/0x900
    [&lt;ffffffff81142645&gt;] __se_sys_clone+0x85/0xb0
    [&lt;ffffffff8114269b&gt;] __x64_sys_clone+0x2b/0x30
    [&lt;ffffffff83965a72&gt;] do_syscall_64+0x32/0x80
    [&lt;ffffffff83a00085&gt;] entry_SYSCALL_64_after_hwframe+0x61/0xc6

It turns out that there is a race condition between disassociate_ctty() and
tty_signal_session_leader(), which caused this leakage.

The pid memleak is triggered by the following race:
task[sshd]                     task[bash]
-----------------------        -----------------------
                               disassociate_ctty();
                               spin_lock_irq(&amp;current-&gt;sighand-&gt;siglock);
                               put_pid(current-&gt;signal-&gt;tty_old_pgrp);
                               current-&gt;signal-&gt;tty_old_pgrp = NULL;
                               tty = tty_kref_get(current-&gt;signal-&gt;tty);
                               spin_unlock_irq(&amp;current-&gt;sighand-&gt;siglock);
tty_vhangup();
tty_lock(tty);
...
tty_signal_session_leader();
spin_lock_irq(&amp;p-&gt;sighand-&gt;siglock);
...
if (tty-&gt;ctrl.pgrp) //tty-&gt;ctrl.pgrp is not NULL
p-&gt;signal-&gt;tty_old_pgrp = get_pid(tty-&gt;ctrl.pgrp); //An extra get
spin_unlock_irq(&amp;p-&gt;sighand-&gt;siglock);
...
tty_unlock(tty);
                               if (tty) {
                                   tty_lock(tty);
                                   ...
                                   put_pid(tty-&gt;ctrl.pgrp);
                                   tty-&gt;ctrl.pgrp = NULL; //It's too late
                                   ...
                                   tty_unlock(tty);
                               }

The issue is believed to be introduced by commit c8bcd9c5be24 ("tty:
Fix -&gt;session locking") who moves the unlock of siglock in
disassociate_ctty() above "if (tty)", making a small window allowing
tty_signal_session_leader() to kick in. It can be easily reproduced by
adding a delay before "if (tty)" and at the entrance of
tty_signal_session_leader().

To fix this issue, we move "put_pid(current-&gt;signal-&gt;tty_old_pgrp)" after
"tty-&gt;ctrl.pgrp = NULL".

Fixes: c8bcd9c5be24 ("tty: Fix -&gt;session locking")
Signed-off-by: Yi Yang &lt;yiyang13@huawei.com&gt;
Co-developed-by: GUO Zihua &lt;guozihua@huawei.com&gt;
Signed-off-by: GUO Zihua &lt;guozihua@huawei.com&gt;
Link: https://lore.kernel.org/r/20230831023329.165737-1-yiyang13@huawei.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>signal: Replace __group_send_sig_info with send_signal_locked</title>
<updated>2022-05-11T19:33:17+00:00</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2022-04-22T14:28:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=e71ba124078e391879e0bf111529fa2d630d106c'/>
<id>urn:sha1:e71ba124078e391879e0bf111529fa2d630d106c</id>
<content type='text'>
The function __group_send_sig_info is just a light wrapper around
send_signal_locked with one parameter fixed to a constant value.  As
the wrapper adds no real value update the code to directly call the
wrapped function.

Tested-by: Kees Cook &lt;keescook@chromium.org&gt;
Reviewed-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Link: https://lkml.kernel.org/r/20220505182645.497868-2-ebiederm@xmission.com
Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
</content>
</entry>
<entry>
<title>tty: tty_jobctrl: Fix 2 incorrectly documented functions</title>
<updated>2021-05-20T15:06:15+00:00</updated>
<author>
<name>Lee Jones</name>
<email>lee.jones@linaro.org</email>
</author>
<published>2021-05-20T12:19:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6ef6785d781e9cea207cdd9e530878fa7cda8e2a'/>
<id>urn:sha1:6ef6785d781e9cea207cdd9e530878fa7cda8e2a</id>
<content type='text'>
Fixes the following W=1 kernel build warning(s):

 drivers/tty/tty_jobctrl.c:33: warning: expecting prototype for tty_check_change(). Prototype was for __tty_check_change() instead
 drivers/tty/tty_jobctrl.c:97: warning: expecting prototype for proc_set_tty(). Prototype was for __proc_set_tty() instead

Cc: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Cc: Jiri Slaby &lt;jirislaby@kernel.org&gt;
Signed-off-by: Lee Jones &lt;lee.jones@linaro.org&gt;
Link: https://lore.kernel.org/r/20210520121906.3468725-7-lee.jones@linaro.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: cumulate and document tty_struct::ctrl* members</title>
<updated>2021-05-13T14:57:16+00:00</updated>
<author>
<name>Jiri Slaby</name>
<email>jslaby@suse.cz</email>
</author>
<published>2021-05-05T09:19:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=64d608db38ffc0c7a25455387096e0aad9410397'/>
<id>urn:sha1:64d608db38ffc0c7a25455387096e0aad9410397</id>
<content type='text'>
Group the ctrl members under a single struct called ctrl. The new struct
contains 'pgrp', 'session', 'pktstatus', and 'packet'. 'pktstatus' and
'packet' used to be bits in a bitfield. The struct also contains the
lock protecting them to share the same cache line.

Note that commit c545b66c6922b (tty: Serialize tcflow() with other tty
flow control changes) added a padding to the original bitfield. It was
for the bitfield to occupy a whole 64b word to avoid interferring stores
on Alpha (cannot we evaporate this arch with weird implications to C
code yet?). But it doesn't work as expected as the padding
(tty_struct::ctrl_unused) is aligned to a 8B boundary too and occupies
some bytes from the next word.

So make it reliable by:
1) setting __aligned of the struct -- that aligns the start, and
2) making 'unsigned long unused[0]' as the last member of the struct --
   pads the end.

Add a kerneldoc comment for this grouped members.

Signed-off-by: Jiri Slaby &lt;jslaby@suse.cz&gt;
Cc: "David S. Miller" &lt;davem@davemloft.net&gt;
Cc: Jakub Kicinski &lt;kuba@kernel.org&gt;
Cc: netdev@vger.kernel.org
Link: https://lore.kernel.org/r/20210505091928.22010-14-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: create internal tty.h file</title>
<updated>2021-04-15T08:22:17+00:00</updated>
<author>
<name>Greg Kroah-Hartman</name>
<email>gregkh@linuxfoundation.org</email>
</author>
<published>2021-04-08T12:51:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=98602c010ceba82f2c2384122dbd07bc965fd367'/>
<id>urn:sha1:98602c010ceba82f2c2384122dbd07bc965fd367</id>
<content type='text'>
There are a number of functions and #defines in include/linux/tty.h that
do not belong there as they are private to the tty core code.

Create an initial drivers/tty/tty.h file and copy the odd "tty logging"
macros into it to seed the file with some initial things that we know
nothing outside of the tty core should be calling.

Cc: Tetsuo Handa &lt;penguin-kernel@i-love.sakura.ne.jp&gt;
Cc: Jiri Slaby &lt;jirislaby@kernel.org&gt;
Link: https://lore.kernel.org/r/20210408125134.3016837-2-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: tty_jobctrl: Remove spaces before tabs</title>
<updated>2021-04-10T08:33:00+00:00</updated>
<author>
<name>Xiaofei Tan</name>
<email>tanxiaofei@huawei.com</email>
</author>
<published>2021-04-07T07:06:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=96d508259c188862b92db4142bfb235058636664'/>
<id>urn:sha1:96d508259c188862b92db4142bfb235058636664</id>
<content type='text'>
Remove spaces before tabs following the advice of checkpatch.pl.

Signed-off-by: Xiaofei Tan &lt;tanxiaofei@huawei.com&gt;
Link: https://lore.kernel.org/r/1617779210-51576-6-git-send-email-tanxiaofei@huawei.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: tty_jobctrl: Fix coding style issues of block comments</title>
<updated>2021-04-10T08:33:00+00:00</updated>
<author>
<name>Xiaofei Tan</name>
<email>tanxiaofei@huawei.com</email>
</author>
<published>2021-04-07T07:06:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=63eeafd43951fd3f07c5b83366e3eaac810ca72b'/>
<id>urn:sha1:63eeafd43951fd3f07c5b83366e3eaac810ca72b</id>
<content type='text'>
Fix coding style issues of block comments, reported by checkpatch.pl.
Besides, do some expression optimization for the sentenses.

Signed-off-by: Xiaofei Tan &lt;tanxiaofei@huawei.com&gt;
Link: https://lore.kernel.org/r/1617779210-51576-5-git-send-email-tanxiaofei@huawei.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: tty_jobctrl: Add a blank line after declarations</title>
<updated>2021-04-10T08:33:00+00:00</updated>
<author>
<name>Xiaofei Tan</name>
<email>tanxiaofei@huawei.com</email>
</author>
<published>2021-04-07T07:06:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=d4e1d903a31e6551fff224628c65e4c923799ba6'/>
<id>urn:sha1:d4e1d903a31e6551fff224628c65e4c923799ba6</id>
<content type='text'>
Add a blank line after declarations, reported by checkpatch.pl.

Signed-off-by: Xiaofei Tan &lt;tanxiaofei@huawei.com&gt;
Link: https://lore.kernel.org/r/1617779210-51576-4-git-send-email-tanxiaofei@huawei.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>Merge 5.10-rc7 into tty-next</title>
<updated>2020-12-07T09:19:31+00:00</updated>
<author>
<name>Greg Kroah-Hartman</name>
<email>gregkh@linuxfoundation.org</email>
</author>
<published>2020-12-07T09:19:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ba3b8bb1263dfb87914ef0ccf5f3a78604b3686b'/>
<id>urn:sha1:ba3b8bb1263dfb87914ef0ccf5f3a78604b3686b</id>
<content type='text'>
We want the tty fixes in here as well.

Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>tty: Fix -&gt;session locking</title>
<updated>2020-12-04T16:39:58+00:00</updated>
<author>
<name>Jann Horn</name>
<email>jannh@google.com</email>
</author>
<published>2020-12-03T01:25:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c8bcd9c5be24fb9e6132e97da5a35e55a83e36b9'/>
<id>urn:sha1:c8bcd9c5be24fb9e6132e97da5a35e55a83e36b9</id>
<content type='text'>
Currently, locking of -&gt;session is very inconsistent; most places
protect it using the legacy tty mutex, but disassociate_ctty(),
__do_SAK(), tiocspgrp() and tiocgsid() don't.
Two of the writers hold the ctrl_lock (because they already need it for
-&gt;pgrp), but __proc_set_tty() doesn't do that yet.

On a PREEMPT=y system, an unprivileged user can theoretically abuse
this broken locking to read 4 bytes of freed memory via TIOCGSID if
tiocgsid() is preempted long enough at the right point. (Other things
might also go wrong, especially if root-only ioctls are involved; I'm
not sure about that.)

Change the locking on -&gt;session such that:

 - tty_lock() is held by all writers: By making disassociate_ctty()
   hold it. This should be fine because the same lock can already be
   taken through the call to tty_vhangup_session().
   The tricky part is that we need to shorten the area covered by
   siglock to be able to take tty_lock() without ugly retry logic; as
   far as I can tell, this should be fine, since nothing in the
   signal_struct is touched in the `if (tty)` branch.
 - ctrl_lock is held by all writers: By changing __proc_set_tty() to
   hold the lock a little longer.
 - All readers that aren't holding tty_lock() hold ctrl_lock: By
   adding locking to tiocgsid() and __do_SAK(), and expanding the area
   covered by ctrl_lock in tiocspgrp().

Cc: stable@kernel.org
Signed-off-by: Jann Horn &lt;jannh@google.com&gt;
Reviewed-by: Jiri Slaby &lt;jirislaby@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
