linux-stable/drivers
Sebastian Andrzej Siewior 8334ab419d random: add a spinlock_t to struct batched_entropy
[ Upstream commit b7d5dc2107 ]

The per-CPU variable batched_entropy_uXX is protected by get_cpu_var().
This is just a preempt_disable() which ensures that the variable is only
from the local CPU. It does not protect against users on the same CPU
from another context. It is possible that a preemptible context reads
slot 0 and then an interrupt occurs and the same value is read again.

The above scenario is confirmed by lockdep if we add a spinlock:
| ================================
| WARNING: inconsistent lock state
| 5.1.0-rc3+ #42 Not tainted
| --------------------------------
| inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
| ksoftirqd/9/56 [HC0[0]:SC1[1]:HE0:SE0] takes:
| (____ptrval____) (batched_entropy_u32.lock){+.?.}, at: get_random_u32+0x3e/0xe0
| {SOFTIRQ-ON-W} state was registered at:
|   _raw_spin_lock+0x2a/0x40
|   get_random_u32+0x3e/0xe0
|   new_slab+0x15c/0x7b0
|   ___slab_alloc+0x492/0x620
|   __slab_alloc.isra.73+0x53/0xa0
|   kmem_cache_alloc_node+0xaf/0x2a0
|   copy_process.part.41+0x1e1/0x2370
|   _do_fork+0xdb/0x6d0
|   kernel_thread+0x20/0x30
|   kthreadd+0x1ba/0x220
|   ret_from_fork+0x3a/0x50
…
| other info that might help us debug this:
|  Possible unsafe locking scenario:
|
|        CPU0
|        ----
|   lock(batched_entropy_u32.lock);
|   <Interrupt>
|     lock(batched_entropy_u32.lock);
|
|  *** DEADLOCK ***
|
| stack backtrace:
| Call Trace:
…
|  kmem_cache_alloc_trace+0x20e/0x270
|  ipmi_alloc_recv_msg+0x16/0x40
…
|  __do_softirq+0xec/0x48d
|  run_ksoftirqd+0x37/0x60
|  smpboot_thread_fn+0x191/0x290
|  kthread+0xfe/0x130
|  ret_from_fork+0x3a/0x50

Add a spinlock_t to the batched_entropy data structure and acquire the
lock while accessing it. Acquire the lock with disabled interrupts
because this function may be used from interrupt context.

Remove the batched_entropy_reset_lock lock. Now that we have a lock for
the data scructure, we can access it from a remote CPU.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-05-31 06:47:25 -07:00
..
accessibility
acpi ACPI / property: fix handling of data_nodes in acpi_get_next_subnode() 2019-05-31 06:47:17 -07:00
amba
android binder: fix handling of misaligned binder object 2019-05-02 09:40:31 +02:00
ata libata: fix using DMA buffers on stack 2019-05-04 09:15:22 +02:00
atm
auxdisplay auxdisplay: hd44780: Fix memory leak on ->remove() 2019-04-20 09:15:00 +02:00
base driver core: Postpone DMA tear-down until after devres release for probe failure 2019-05-25 18:25:37 +02:00
bcma
block virtio-blk: limit number of hw queues by nr_cpu_ids 2019-05-10 17:53:12 +02:00
bluetooth Bluetooth: btusb: request wake pin with NOAUTOEN 2019-05-08 07:20:51 +02:00
bus
cdrom cdrom: Fix race condition in cdrom_sysctl_register 2019-04-05 22:31:35 +02:00
char random: add a spinlock_t to struct batched_entropy 2019-05-31 06:47:25 -07:00
clk clk: rockchip: undo several noc and special clocks as critical on rk3288 2019-05-31 06:47:24 -07:00
clocksource clocksource/drivers/oxnas: Fix OX820 compatible 2019-05-16 19:42:21 +02:00
connector
cpufreq sched/cpufreq: Fix kobject memleak 2019-05-31 06:47:19 -07:00
cpuidle
crypto crypto: sun4i-ss - Fix invalid calculation of hash end 2019-05-31 06:47:23 -07:00
dax
dca
devfreq
dio
dma dmaengine: at_xdmac: remove BUG_ON macro in tasklet 2019-05-31 06:47:24 -07:00
dma-buf
edac x86/cpu: Sanitize FAM6_ATOM naming 2019-05-14 19:18:42 +02:00
eisa
extcon
firewire
firmware efi/arm/arm64: Allow SetVirtualAddressMap() to be omitted 2019-04-05 22:31:36 +02:00
fmc
fpga
fsi
gpio gpio: of: Fix of_gpiochip_add() error path 2019-05-04 09:15:22 +02:00
gpu drm/rockchip: fix for mailbox read validation. 2019-05-16 19:42:30 +02:00
hid HID: logitech-hidpp: use RAP instead of FAP to get the protocol version 2019-05-31 06:47:24 -07:00
hsi
hv Drivers: hv: vmbus: Remove the undesired put_cpu_ptr() in hv_synic_cleanup() 2019-05-10 17:53:08 +02:00
hwmon hwmon: (pwm-fan) Disable PWM if fetching cooling data fails 2019-05-16 19:42:19 +02:00
hwspinlock
hwtracing intel_th: msu: Fix single mode with IOMMU 2019-05-25 18:25:19 +02:00
i2c i2c: i2c-stm32f7: Fix SDADEL minimum formula 2019-05-08 07:20:53 +02:00
ide
idle x86/cpu: Sanitize FAM6_ATOM naming 2019-05-14 19:18:42 +02:00
iio iio: adc: xilinx: fix potential use-after-free on remove 2019-05-16 19:42:19 +02:00
infiniband IB/hfi1: Fix WQ_MEM_RECLAIM warning 2019-05-31 06:47:14 -07:00
input Input: elan_i2c - add hardware ID for multiple Lenovo laptops 2019-05-16 19:42:30 +02:00
iommu iommu/tegra-smmu: Fix invalid ASID bits on Tegra30/114 2019-05-25 18:25:22 +02:00
ipack
irqchip MIPS: perf: ath79: Fix perfcount IRQ assignment 2019-05-16 19:42:23 +02:00
isdn mISDN: Check address length before reading address family 2019-05-16 19:42:21 +02:00
leds leds: pwm: silently error out on EPROBE_DEFER 2019-05-16 19:42:29 +02:00
lightnvm
macintosh
mailbox
mcb
md bcache: avoid clang -Wunintialized warning 2019-05-31 06:47:23 -07:00
media media: pvrusb2: Prevent a buffer overflow 2019-05-31 06:47:25 -07:00
memory memory: tegra: Fix integer overflow on tick value calculation 2019-05-25 18:25:25 +02:00
memstick
message
mfd
misc lkdtm: Add tests for NULL pointer dereference 2019-04-20 09:15:06 +02:00
mmc mmc: core: Verify SD bus width 2019-05-31 06:47:15 -07:00
mtd mtd: spi-nor: intel-spi: Avoid crossing 4K address boundary on read/write 2019-05-21 18:50:17 +02:00
mux
net net: cw1200: fix a NULL pointer dereference 2019-05-31 06:47:22 -07:00
nfc spi: ST ST95HF NFC: declare missing of table 2019-05-16 19:42:24 +02:00
ntb
nubus
nvdimm libnvdimm/namespace: Fix label tracking error 2019-05-31 06:47:11 -07:00
nvme nvme-loop: init nvmet_ctrl fatal_err_work when allocate 2019-05-08 07:20:47 +02:00
nvmem
of
oprofile
parisc parisc: Skip registering LED when running in QEMU 2019-05-25 18:25:18 +02:00
parport
pci PCI: Work around Pericom PCIe-to-PCI bridge Retrain Link erratum 2019-05-25 18:25:32 +02:00
pcmcia
perf
phy
pinctrl pinctrl: samsung: fix leaked of_node references 2019-05-31 06:47:24 -07:00
platform platform/x86: thinkpad_acpi: Disable Bluetooth for some machines 2019-05-16 19:42:19 +02:00
pnp
power power: supply: sysfs: prevent endless uevent loop with CONFIG_POWER_SUPPLY_DEBUG 2019-05-25 18:25:35 +02:00
powercap x86/cpu: Sanitize FAM6_ATOM naming 2019-05-14 19:18:42 +02:00
pps
ps3
ptp
pwm
rapidio
ras
regulator regulator: act8865: Fix act8600_sudcdc_voltage_ranges setting 2019-04-05 22:31:39 +02:00
remoteproc
reset
rpmsg
rtc rtc: 88pm860x: prevent use-after-free on device remove 2019-05-31 06:47:21 -07:00
s390 vfio-ccw: Release any channel program when releasing/removing vfio-ccw mdev 2019-05-31 06:47:23 -07:00
sbus
scsi scsi: qedi: Abort ep termination if offload not scheduled 2019-05-31 06:47:21 -07:00
sfi
sh
sn
soc soc/tegra: pmc: Drop locking from tegra_powergate_is_powered() 2019-04-20 09:15:06 +02:00
spi spi: pxa2xx: fix SCR (divisor) calculation 2019-05-31 06:47:17 -07:00
spmi
ssb ssb: Fix possible NULL pointer dereference in ssb_host_pcmcia_exit 2019-05-31 06:47:13 -07:00
staging staging: olpc_dcon: add a missing dependency 2019-05-16 19:42:28 +02:00
target
tc
tee
thermal x86/cpu: Sanitize FAM6_ATOM naming 2019-05-14 19:18:42 +02:00
thunderbolt
tty tty/vt: fix write/write race in ioctl(KDSKBSENT) handler 2019-05-21 18:50:18 +02:00
uio
usb USB: serial: fix unthrottle races 2019-05-16 19:42:19 +02:00
uwb
vfio vfio/pci: use correct format characters 2019-05-08 07:20:49 +02:00
vhost vhost: reject zero size iova range 2019-04-27 09:35:34 +02:00
video fbdev: fix WARNING in __alloc_pages_nodemask bug 2019-05-31 06:47:13 -07:00
virt drivers/virt/fsl_hypervisor.c: prevent integer overflow in ioctl 2019-05-16 19:42:35 +02:00
virtio virtio_pci: fix a NULL pointer reference in vp_del_vqs 2019-05-10 17:53:11 +02:00
vlynq
vme
w1 w1: fix the resume command API 2019-05-31 06:47:21 -07:00
watchdog
xen
zorro
Kconfig
Makefile