Commit 902e02e
tty: n_gsm: avoid call of sleeping functions from atomic context
Syzkaller reports the following problem:
BUG: sleeping function called from invalid context at kernel/printk/printk.c:2347
in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 1105, name: syz-executor423
3 locks held by syz-executor423/1105:
#0: ffff8881468b9098 (&tty->ldisc_sem){++++}-{0:0}, at: tty_ldisc_ref_wait+0x22/0x90 drivers/tty/tty_ldisc.c:266
#1: ffff8881468b9130 (&tty->atomic_write_lock){+.+.}-{3:3}, at: tty_write_lock drivers/tty/tty_io.c:952 [inline]
#1: ffff8881468b9130 (&tty->atomic_write_lock){+.+.}-{3:3}, at: do_tty_write drivers/tty/tty_io.c:975 [inline]
#1: ffff8881468b9130 (&tty->atomic_write_lock){+.+.}-{3:3}, at: file_tty_write.constprop.0+0x2a8/0x8e0 drivers/tty/tty_io.c:1118
#2: ffff88801b06c398 (&gsm->tx_lock){....}-{2:2}, at: gsmld_write+0x5e/0x150 drivers/tty/n_gsm.c:2717
irq event stamp: 3482
hardirqs last enabled at (3481): [<ffffffff81d13343>] __get_reqs_available+0x143/0x2f0 fs/aio.c:946
hardirqs last disabled at (3482): [<ffffffff87d39722>] __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:108 [inline]
hardirqs last disabled at (3482): [<ffffffff87d39722>] _raw_spin_lock_irqsave+0x52/0x60 kernel/locking/spinlock.c:159
softirqs last enabled at (3408): [<ffffffff87e01002>] asm_call_irq_on_stack+0x12/0x20
softirqs last disabled at (3401): [<ffffffff87e01002>] asm_call_irq_on_stack+0x12/0x20
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 2 PID: 1105 Comm: syz-executor423 Not tainted 5.10.137-syzkaller #0
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x107/0x167 lib/dump_stack.c:118
___might_sleep.cold+0x1e8/0x22e kernel/sched/core.c:7304
console_lock+0x19/0x80 kernel/printk/printk.c:2347
do_con_write+0x113/0x1de0 drivers/tty/vt/vt.c:2909
con_write+0x22/0xc0 drivers/tty/vt/vt.c:3296
gsmld_write+0xd0/0x150 drivers/tty/n_gsm.c:2720
do_tty_write drivers/tty/tty_io.c:1028 [inline]
file_tty_write.constprop.0+0x502/0x8e0 drivers/tty/tty_io.c:1118
call_write_iter include/linux/fs.h:1903 [inline]
aio_write+0x355/0x7b0 fs/aio.c:1580
__io_submit_one fs/aio.c:1952 [inline]
io_submit_one+0xf45/0x1a90 fs/aio.c:1999
__do_sys_io_submit fs/aio.c:2058 [inline]
__se_sys_io_submit fs/aio.c:2028 [inline]
__x64_sys_io_submit+0x18c/0x2f0 fs/aio.c:2028
do_syscall_64+0x33/0x40 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x61/0xc6
The problem happens in the following control flow:
gsmld_write(...)
spin_lock_irqsave(&gsm->tx_lock, flags) // taken a spinlock on TX data
con_write(...)
do_con_write(...)
console_lock()
might_sleep() // -> bug
As far as console_lock() might sleep it should not be called with
spinlock held.
The patch replaces tx_lock spinlock with mutex in order to avoid the
problem.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Fixes: 32dd59f ("tty: n_gsm: fix race condition in gsmld_write()")
Cc: stable <stable@kernel.org>
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Link: https://lore.kernel.org/r/20220829131640.69254-3-pchelkin@ispras.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent c9ab053 commit 902e02e
1 file changed
Lines changed: 24 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
| 251 | + | |
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| |||
680 | 680 | | |
681 | 681 | | |
682 | 682 | | |
683 | | - | |
684 | 683 | | |
685 | 684 | | |
686 | 685 | | |
| |||
702 | 701 | | |
703 | 702 | | |
704 | 703 | | |
705 | | - | |
| 704 | + | |
706 | 705 | | |
707 | 706 | | |
708 | | - | |
| 707 | + | |
709 | 708 | | |
710 | 709 | | |
711 | 710 | | |
| |||
730 | 729 | | |
731 | 730 | | |
732 | 731 | | |
733 | | - | |
| 732 | + | |
734 | 733 | | |
735 | 734 | | |
736 | 735 | | |
737 | 736 | | |
738 | 737 | | |
739 | 738 | | |
740 | 739 | | |
741 | | - | |
| 740 | + | |
742 | 741 | | |
743 | 742 | | |
744 | 743 | | |
| |||
1024 | 1023 | | |
1025 | 1024 | | |
1026 | 1025 | | |
1027 | | - | |
1028 | | - | |
| 1026 | + | |
1029 | 1027 | | |
1030 | | - | |
| 1028 | + | |
1031 | 1029 | | |
1032 | 1030 | | |
1033 | 1031 | | |
| |||
1039 | 1037 | | |
1040 | 1038 | | |
1041 | 1039 | | |
1042 | | - | |
| 1040 | + | |
1043 | 1041 | | |
1044 | 1042 | | |
1045 | 1043 | | |
| |||
1099 | 1097 | | |
1100 | 1098 | | |
1101 | 1099 | | |
1102 | | - | |
| 1100 | + | |
1103 | 1101 | | |
1104 | 1102 | | |
1105 | 1103 | | |
| |||
1115 | 1113 | | |
1116 | 1114 | | |
1117 | 1115 | | |
1118 | | - | |
| 1116 | + | |
1119 | 1117 | | |
1120 | 1118 | | |
1121 | 1119 | | |
| |||
1169 | 1167 | | |
1170 | 1168 | | |
1171 | 1169 | | |
1172 | | - | |
| 1170 | + | |
1173 | 1171 | | |
1174 | 1172 | | |
1175 | 1173 | | |
| |||
1283 | 1281 | | |
1284 | 1282 | | |
1285 | 1283 | | |
1286 | | - | |
1287 | 1284 | | |
1288 | 1285 | | |
1289 | 1286 | | |
1290 | 1287 | | |
1291 | 1288 | | |
1292 | | - | |
| 1289 | + | |
1293 | 1290 | | |
1294 | 1291 | | |
1295 | 1292 | | |
| |||
1300 | 1297 | | |
1301 | 1298 | | |
1302 | 1299 | | |
1303 | | - | |
| 1300 | + | |
1304 | 1301 | | |
1305 | 1302 | | |
1306 | 1303 | | |
| |||
1994 | 1991 | | |
1995 | 1992 | | |
1996 | 1993 | | |
1997 | | - | |
1998 | 1994 | | |
1999 | 1995 | | |
2000 | | - | |
| 1996 | + | |
2001 | 1997 | | |
2002 | 1998 | | |
2003 | 1999 | | |
2004 | | - | |
| 2000 | + | |
2005 | 2001 | | |
2006 | 2002 | | |
2007 | 2003 | | |
| |||
2531 | 2527 | | |
2532 | 2528 | | |
2533 | 2529 | | |
| 2530 | + | |
2534 | 2531 | | |
2535 | 2532 | | |
2536 | 2533 | | |
| |||
2602 | 2599 | | |
2603 | 2600 | | |
2604 | 2601 | | |
| 2602 | + | |
2605 | 2603 | | |
2606 | 2604 | | |
2607 | 2605 | | |
| |||
2610 | 2608 | | |
2611 | 2609 | | |
2612 | 2610 | | |
2613 | | - | |
2614 | 2611 | | |
2615 | 2612 | | |
2616 | 2613 | | |
| |||
2635 | 2632 | | |
2636 | 2633 | | |
2637 | 2634 | | |
| 2635 | + | |
2638 | 2636 | | |
2639 | 2637 | | |
2640 | 2638 | | |
| |||
2790 | 2788 | | |
2791 | 2789 | | |
2792 | 2790 | | |
2793 | | - | |
2794 | 2791 | | |
2795 | 2792 | | |
2796 | 2793 | | |
2797 | 2794 | | |
2798 | 2795 | | |
2799 | 2796 | | |
2800 | | - | |
| 2797 | + | |
2801 | 2798 | | |
2802 | 2799 | | |
2803 | | - | |
| 2800 | + | |
2804 | 2801 | | |
2805 | 2802 | | |
2806 | 2803 | | |
| |||
3008 | 3005 | | |
3009 | 3006 | | |
3010 | 3007 | | |
3011 | | - | |
3012 | 3008 | | |
3013 | 3009 | | |
3014 | 3010 | | |
3015 | 3011 | | |
3016 | 3012 | | |
3017 | 3013 | | |
3018 | 3014 | | |
3019 | | - | |
| 3015 | + | |
3020 | 3016 | | |
3021 | 3017 | | |
3022 | 3018 | | |
3023 | 3019 | | |
3024 | 3020 | | |
3025 | | - | |
| 3021 | + | |
3026 | 3022 | | |
3027 | 3023 | | |
3028 | 3024 | | |
| |||
3319 | 3315 | | |
3320 | 3316 | | |
3321 | 3317 | | |
3322 | | - | |
3323 | 3318 | | |
3324 | 3319 | | |
3325 | 3320 | | |
3326 | 3321 | | |
3327 | | - | |
| 3322 | + | |
3328 | 3323 | | |
3329 | | - | |
| 3324 | + | |
3330 | 3325 | | |
3331 | 3326 | | |
3332 | 3327 | | |
| |||
0 commit comments