android_kernel_motorola_sm6375/drivers
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Qi Zheng 3219ac364a tty: fix deadlock caused by calling printk() under tty_port->lock
[ Upstream commit 6b9dbedbe3499fef862c4dff5217cf91f34e43b3 ]

pty_write() invokes kmalloc() which may invoke a normal printk() to print
failure message.  This can cause a deadlock in the scenario reported by
syz-bot below:

       CPU0              CPU1                    CPU2
       ----              ----                    ----
                         lock(console_owner);
                                                 lock(&port_lock_key);
  lock(&port->lock);
                         lock(&port_lock_key);
                                                 lock(&port->lock);
  lock(console_owner);

As commit dbdda842fe ("printk: Add console owner and waiter logic to
load balance console writes") said, such deadlock can be prevented by
using printk_deferred() in kmalloc() (which is invoked in the section
guarded by the port->lock).  But there are too many printk() on the
kmalloc() path, and kmalloc() can be called from anywhere, so changing
printk() to printk_deferred() is too complicated and inelegant.

Therefore, this patch chooses to specify __GFP_NOWARN to kmalloc(), so
that printk() will not be called, and this deadlock problem can be
avoided.

Syzbot reported the following lockdep error:

======================================================
WARNING: possible circular locking dependency detected
5.4.143-00237-g08ccc19a-dirty #10 Not tainted
------------------------------------------------------
syz-executor.4/29420 is trying to acquire lock:
ffffffff8aedb2a0 (console_owner){....}-{0:0}, at: console_trylock_spinning kernel/printk/printk.c:1752 [inline]
ffffffff8aedb2a0 (console_owner){....}-{0:0}, at: vprintk_emit+0x2ca/0x470 kernel/printk/printk.c:2023

but task is already holding lock:
ffff8880119c9158 (&port->lock){-.-.}-{2:2}, at: pty_write+0xf4/0x1f0 drivers/tty/pty.c:120

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (&port->lock){-.-.}-{2:2}:
       __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
       _raw_spin_lock_irqsave+0x35/0x50 kernel/locking/spinlock.c:159
       tty_port_tty_get drivers/tty/tty_port.c:288 [inline]          		<-- lock(&port->lock);
       tty_port_default_wakeup+0x1d/0xb0 drivers/tty/tty_port.c:47
       serial8250_tx_chars+0x530/0xa80 drivers/tty/serial/8250/8250_port.c:1767
       serial8250_handle_irq.part.0+0x31f/0x3d0 drivers/tty/serial/8250/8250_port.c:1854
       serial8250_handle_irq drivers/tty/serial/8250/8250_port.c:1827 [inline] 	<-- lock(&port_lock_key);
       serial8250_default_handle_irq+0xb2/0x220 drivers/tty/serial/8250/8250_port.c:1870
       serial8250_interrupt+0xfd/0x200 drivers/tty/serial/8250/8250_core.c:126
       __handle_irq_event_percpu+0x109/0xa50 kernel/irq/handle.c:156
       [...]

-> #1 (&port_lock_key){-.-.}-{2:2}:
       __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
       _raw_spin_lock_irqsave+0x35/0x50 kernel/locking/spinlock.c:159
       serial8250_console_write+0x184/0xa40 drivers/tty/serial/8250/8250_port.c:3198
										<-- lock(&port_lock_key);
       call_console_drivers kernel/printk/printk.c:1819 [inline]
       console_unlock+0x8cb/0xd00 kernel/printk/printk.c:2504
       vprintk_emit+0x1b5/0x470 kernel/printk/printk.c:2024			<-- lock(console_owner);
       vprintk_func+0x8d/0x250 kernel/printk/printk_safe.c:394
       printk+0xba/0xed kernel/printk/printk.c:2084
       register_console+0x8b3/0xc10 kernel/printk/printk.c:2829
       univ8250_console_init+0x3a/0x46 drivers/tty/serial/8250/8250_core.c:681
       console_init+0x49d/0x6d3 kernel/printk/printk.c:2915
       start_kernel+0x5e9/0x879 init/main.c:713
       secondary_startup_64+0xa4/0xb0 arch/x86/kernel/head_64.S:241

-> #0 (console_owner){....}-{0:0}:
       [...]
       lock_acquire+0x127/0x340 kernel/locking/lockdep.c:4734
       console_trylock_spinning kernel/printk/printk.c:1773 [inline]		<-- lock(console_owner);
       vprintk_emit+0x307/0x470 kernel/printk/printk.c:2023
       vprintk_func+0x8d/0x250 kernel/printk/printk_safe.c:394
       printk+0xba/0xed kernel/printk/printk.c:2084
       fail_dump lib/fault-inject.c:45 [inline]
       should_fail+0x67b/0x7c0 lib/fault-inject.c:144
       __should_failslab+0x152/0x1c0 mm/failslab.c:33
       should_failslab+0x5/0x10 mm/slab_common.c:1224
       slab_pre_alloc_hook mm/slab.h:468 [inline]
       slab_alloc_node mm/slub.c:2723 [inline]
       slab_alloc mm/slub.c:2807 [inline]
       __kmalloc+0x72/0x300 mm/slub.c:3871
       kmalloc include/linux/slab.h:582 [inline]
       tty_buffer_alloc+0x23f/0x2a0 drivers/tty/tty_buffer.c:175
       __tty_buffer_request_room+0x156/0x2a0 drivers/tty/tty_buffer.c:273
       tty_insert_flip_string_fixed_flag+0x93/0x250 drivers/tty/tty_buffer.c:318
       tty_insert_flip_string include/linux/tty_flip.h:37 [inline]
       pty_write+0x126/0x1f0 drivers/tty/pty.c:122				<-- lock(&port->lock);
       n_tty_write+0xa7a/0xfc0 drivers/tty/n_tty.c:2356
       do_tty_write drivers/tty/tty_io.c:961 [inline]
       tty_write+0x512/0x930 drivers/tty/tty_io.c:1045
       __vfs_write+0x76/0x100 fs/read_write.c:494
       [...]

other info that might help us debug this:

Chain exists of:
  console_owner --> &port_lock_key --> &port->lock

Link: https://lkml.kernel.org/r/20220511061951.1114-2-zhengqi.arch@bytedance.com
Link: https://lkml.kernel.org/r/20220510113809.80626-2-zhengqi.arch@bytedance.com
Fixes: b6da31b2c0 ("tty: Fix data race in tty_insert_flip_string_fixed_flag")
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Acked-by: Jiri Slaby <jirislaby@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-14 18:11:41 +02:00
..
accessibility
acpi ACPI: PM: Block ASUS B1400CEAE from suspend to idle by default 2022-06-14 18:11:28 +02:00
amba
android binder: fix handling of error during copy 2022-01-27 09:19:38 +01:00
ata ata: pata_marvell: Check the 'bmdma_addr' beforing reading 2022-04-27 13:50:48 +02:00
atm atm: eni: Add check for dma_map_single 2022-03-23 09:12:07 +01:00
auxdisplay auxdisplay: ht16k33: Fix frame buffer device blanking 2021-11-17 09:48:45 +01:00
base drivers/base/node.c: fix compaction sysfs file leak 2022-06-14 18:11:41 +02:00
bcma
block virtio_blk: fix the discard_granularity and discard_alignment queue limits 2022-06-14 18:11:35 +02:00
bluetooth Bluetooth: btmtksdio: Fix kernel oops in btmtksdio_interrupt 2022-04-15 14:18:16 +02:00
bus bus: sunxi-rsb: Fix the return value of sunxi_rsb_device_create() 2022-05-09 09:03:25 +02:00
cdrom
char ipmi: Fix pr_fmt to avoid compilation issues 2022-06-14 18:11:28 +02:00
clk clk: at91: generated: consider range when calculating best rate 2022-05-25 09:14:36 +02:00
clocksource clocksource: acpi_pm: fix return value of __setup handler 2022-04-15 14:18:05 +02:00
connector
counter
cpufreq Revert "cpufreq: Fix possible race in cpufreq online error path" 2022-06-14 18:11:36 +02:00
cpuidle
crypto crypto: marvell/cesa - ECB does not IV 2022-06-14 18:11:40 +02:00
dax dax: make sure inodes are flushed before destroy cache 2022-04-15 14:18:12 +02:00
dca
devfreq PM / devfreq: rk3399_dmc: Disable edev on remove() 2022-06-14 18:11:29 +02:00
dio
dma dma: at_xdmac: fix a missing check on list iterator 2022-04-27 13:50:48 +02:00
dma-buf udmabuf: validate ubuf->pagecount 2022-04-15 14:18:10 +02:00
edac EDAC/synopsys: Read the error count from the correct register 2022-04-27 13:50:48 +02:00
eisa
extcon
firewire firewire: core: extend card->lock in fw_core_handle_bus_reset 2022-05-12 12:23:41 +02:00
firmware firmware: arm_scmi: Fix list protocols enumeration in the base protocol 2022-06-14 18:11:40 +02:00
fpga
fsi
gnss
gpio gpio: mvebu/pwm: Refuse requests with inverted polarity 2022-05-25 09:14:37 +02:00
gpu drm: msm: fix possible memory leak in mdp5_crtc_cursor_set() 2022-06-14 18:11:38 +02:00
greybus greybus: svc: fix an error handling bug in gb_svc_hello() 2022-04-15 14:17:58 +02:00
hid HID: elan: Fix potential double free in elan_input_configured 2022-06-14 18:11:33 +02:00
hsi HSI: core: Fix return freed object in hsi_new_client 2022-01-27 09:19:41 +01:00
hv Drivers: hv: vmbus: Prevent load re-ordering when reading ring buffer 2022-04-20 09:19:36 +02:00
hwmon hwmon: Make chip parameter for with_info API mandatory 2022-06-14 18:11:29 +02:00
hwspinlock
hwtracing coresight: Fix TRCCONFIGR.QE sysfs interface 2022-04-15 14:17:57 +02:00
i2c drivers: i2c: thunderx: Allow driver to work with ACPI defined TWSI controllers 2022-06-06 08:33:49 +02:00
i3c
ide
idle
iio iio: magnetometer: ak8975: Fix the error handling in ak8975_power_on() 2022-05-09 09:03:21 +02:00
infiniband RDMA/hfi1: Prevent panic when SDMA is disabled 2022-06-14 18:11:31 +02:00
input Input: goodix - fix spurious key release events 2022-06-06 08:33:48 +02:00
interconnect
iommu iommu/arm-smmu-v3: fix event handling soft lockup 2022-04-15 14:18:33 +02:00
ipack
irqchip irqchip/aspeed-i2c-ic: Fix irq_of_parse_and_map() return value 2022-06-14 18:11:35 +02:00
isdn mISDN: change function names to avoid conflicts 2022-01-11 15:23:33 +01:00
leds
lightnvm lightnvm: disable the subsystem 2022-05-09 09:03:20 +02:00
macintosh macintosh/via-pmu: Fix build failure when CONFIG_INPUT is disabled 2022-06-14 18:11:31 +02:00
mailbox mailbox: tegra-hsp: Flush whole channel 2022-04-15 14:18:01 +02:00
mcb
md md/bitmap: don't set sb values if can't pass sanity check 2022-06-14 18:11:26 +02:00
media media: ov7670: remove ov7670_power_off from ov7670_remove 2022-06-14 18:11:37 +02:00
memory memory: atmel-ebi: Fix missing of_node_put in atmel_ebi_probe 2022-04-20 09:19:34 +02:00
memstick memstick: jmb38x_ms: use appropriate free function in jmb38x_ms_alloc_host() 2021-11-17 09:48:37 +01:00
message
mfd mfd: ipaq-micro: Fix error check return value of platform_get_irq() 2022-06-14 18:11:40 +02:00
misc misc: ocxl: fix possible double free in ocxl_file_register_afu 2022-06-14 18:11:40 +02:00
mmc mmc: jz4740: Apply DMA engine limits to maximum segment size 2022-06-14 18:11:26 +02:00
mtd mtd: rawnand: Fix return value check of wait_for_completion_timeout 2022-05-09 09:03:24 +02:00
mux
net can: xilinx_can: mark bit timing constants as const 2022-06-14 18:11:39 +02:00
nfc NFC: hci: fix sleep in atomic context bugs in nfc_hci_hcp_message_tx 2022-06-14 18:11:38 +02:00
ntb
nubus
nvdimm nvdimm: Allow overwrite in the presence of disabled dimms 2022-06-14 18:11:40 +02:00
nvme nvme-pci: fix a NULL pointer dereference in nvme_alloc_admin_tags 2022-06-14 18:11:28 +02:00
nvmem
of of: overlay: do not break notify on NOTIFY_{OK|STOP} 2022-06-14 18:11:34 +02:00
opp opp: Fix return in _opp_add_static_v2() 2021-11-17 09:48:44 +01:00
oprofile
parisc parisc: Fix CPU affinity for Lasi, WAX and Dino chips 2022-04-15 14:18:36 +02:00
parport
pci PCI: imx6: Fix PERST# start-up sequence 2022-06-14 18:11:41 +02:00
pcmcia pcmcia: fix setting of kthread task states 2022-01-27 09:19:37 +01:00
perf arm_pmu: Validate single/group leader events 2022-04-27 13:50:50 +02:00
phy phy: ti: Add missing pm_runtime_disable() in serdes_am654_probe 2022-05-09 09:03:24 +02:00
pinctrl pinctrl: mvebu: Fix irq_of_parse_and_map() return value 2022-06-14 18:11:41 +02:00
platform platform/chrome: cros_ec_debugfs: detach log reader wq from devm 2022-05-25 09:14:33 +02:00
pnp
power power: supply: axp288-charger: Set Vhold to 4.4V 2022-04-15 14:18:33 +02:00
powercap
pps
ps3
ptp ptp: replace snprintf with sysfs_emit 2022-04-15 14:18:32 +02:00
pwm pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() 2022-04-15 14:18:17 +02:00
rapidio
ras
regulator regulator: pfuze100: Fix refcount leak in pfuze_parse_regulators_dt 2022-06-14 18:11:37 +02:00
remoteproc remoteproc: qcom_wcnss: Add missing of_node_put() in wcnss_alloc_memory_region 2022-04-15 14:18:19 +02:00
reset reset: tegra-bpmp: Restore Handle errors in BPMP response 2022-04-27 13:50:47 +02:00
rpmsg rpmsg: char: Fix race between the release of rpmsg_eptdev and cdev 2022-02-01 17:24:36 +01:00
rtc rtc: mc146818-lib: Fix the AltCentury for AMD platforms 2022-05-25 09:14:32 +02:00
s390 s390/lcs: fix variable dereferenced before check 2022-05-18 09:47:25 +02:00
sbus
scsi scsi: fcoe: Fix Wstringop-overflow warnings in fcoe_wwn_from_mac() 2022-06-14 18:11:40 +02:00
sfi
sh maple: fix wrong return value of maple_bus_init(). 2021-11-26 10:47:17 +01:00
siox
slimbus slimbus: qcom: Fix IRQ check in qcom_slim_probe 2022-05-18 09:47:27 +02:00
soc soc: qcom: smsm: Fix missing of_node_put() in smsm_parse_ipc 2022-06-14 18:11:39 +02:00
soundwire
spi spi: img-spfi: Fix pm_runtime_get_sync() error checking 2022-06-14 18:11:33 +02:00
spmi
ssb
staging staging: rtl8723bs: prevent ->Ssid overflow in rtw_wx_set_scan() 2022-06-06 08:33:48 +02:00
target scsi: target: tcmu: Fix possible page UAF 2022-04-20 09:19:36 +02:00
tc
tee optee: use driver internal tee_context for some rpc 2022-03-02 11:41:04 +01:00
thermal thermal/drivers/broadcom: Fix potential NULL dereference in sr_thermal_probe 2022-06-14 18:11:38 +02:00
thunderbolt
tty tty: fix deadlock caused by calling printk() under tty_port->lock 2022-06-14 18:11:41 +02:00
uio
usb usb: core: hcd: Add support for deferring roothub registration 2022-06-14 18:11:24 +02:00
vfio
vhost Fix double fget() in vhost_net_set_backend() 2022-05-25 09:14:34 +02:00
video fbcon: Consistently protect deferred_takeover with console_lock() 2022-06-14 18:11:25 +02:00
virt
virtio virtio: acknowledge all features before access 2022-03-16 13:21:48 +01:00
visorbus
vlynq
vme
w1 w1: w1_therm: fixes w1_seq for ds28ea00 sensors 2022-04-15 14:18:35 +02:00
watchdog ar7: fix kernel builds for compiler test 2021-11-17 09:48:46 +01:00
xen xen/gnttab: fix gnttab_end_foreign_access() without page specified 2022-03-11 11:22:39 +01:00
zorro
Kconfig
Makefile