forked fromtorvalds/linux
- Notifications
You must be signed in to change notification settings - Fork0
Commitc8bcd9c
tty: Fix ->session locking
Currently, locking of ->session is very inconsistent; most placesprotect 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->pgrp), but __proc_set_tty() doesn't do that yet.On a PREEMPT=y system, an unprivileged user can theoretically abusethis broken locking to read 4 bytes of freed memory via TIOCGSID iftiocgsid() is preempted long enough at the right point. (Other thingsmight also go wrong, especially if root-only ioctls are involved; I'mnot sure about that.)Change the locking on ->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.orgSigned-off-by: Jann Horn <jannh@google.com>Reviewed-by: Jiri Slaby <jirislaby@kernel.org>Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent54ffccb commitc8bcd9c
3 files changed
+41
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2897 | 2897 | | |
2898 | 2898 | | |
2899 | 2899 | | |
| 2900 | + | |
2900 | 2901 | | |
2901 | 2902 | | |
2902 | 2903 | | |
2903 | | - | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
2904 | 2908 | | |
2905 | 2909 | | |
2906 | 2910 | | |
| |||
2932 | 2936 | | |
2933 | 2937 | | |
2934 | 2938 | | |
| 2939 | + | |
2935 | 2940 | | |
2936 | 2941 | | |
2937 | 2942 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | 106 | | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | | - | |
297 | 296 | | |
| 297 | + | |
| 298 | + | |
298 | 299 | | |
299 | 300 | | |
| 301 | + | |
| 302 | + | |
300 | 303 | | |
301 | 304 | | |
302 | 305 | | |
303 | 306 | | |
304 | 307 | | |
305 | 308 | | |
| 309 | + | |
306 | 310 | | |
307 | 311 | | |
308 | 312 | | |
309 | | - | |
310 | 313 | | |
311 | 314 | | |
312 | 315 | | |
| |||
477 | 480 | | |
478 | 481 | | |
479 | 482 | | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
| 483 | + | |
484 | 484 | | |
485 | 485 | | |
486 | 486 | | |
487 | 487 | | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
488 | 496 | | |
489 | 497 | | |
490 | 498 | | |
| |||
494 | 502 | | |
495 | 503 | | |
496 | 504 | | |
497 | | - | |
498 | 505 | | |
499 | 506 | | |
500 | | - | |
501 | 507 | | |
502 | 508 | | |
| 509 | + | |
| 510 | + | |
503 | 511 | | |
504 | 512 | | |
505 | 513 | | |
| |||
511 | 519 | | |
512 | 520 | | |
513 | 521 | | |
514 | | - | |
515 | | - | |
516 | 522 | | |
517 | 523 | | |
518 | 524 | | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
519 | 528 | | |
520 | 529 | | |
521 | 530 | | |
522 | 531 | | |
523 | 532 | | |
524 | 533 | | |
| 534 | + | |
| 535 | + | |
525 | 536 | | |
526 | | - | |
527 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
528 | 546 | | |
529 | 547 | | |
530 | 548 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
309 | 313 | | |
310 | 314 | | |
311 | 315 | | |
| |||
0 commit comments
Comments
(0)