linux-stable/drivers
Hyunwoo Kim cacdb14b1c HID: roccat: Fix use-after-free in roccat_read()
roccat_report_event() is responsible for registering
roccat-related reports in struct roccat_device.

int roccat_report_event(int minor, u8 const *data)
{
	struct roccat_device *device;
	struct roccat_reader *reader;
	struct roccat_report *report;
	uint8_t *new_value;

	device = devices[minor];

	new_value = kmemdup(data, device->report_size, GFP_ATOMIC);
	if (!new_value)
		return -ENOMEM;

	report = &device->cbuf[device->cbuf_end];

	/* passing NULL is safe */
	kfree(report->value);
	...

The registered report is stored in the struct roccat_device member
"struct roccat_report cbuf[ROCCAT_CBUF_SIZE];".
If more reports are received than the "ROCCAT_CBUF_SIZE" value,
kfree() the saved report from cbuf[0] and allocates a new reprot.
Since there is no lock when this kfree() is performed,
kfree() can be performed even while reading the saved report.

static ssize_t roccat_read(struct file *file, char __user *buffer,
		size_t count, loff_t *ppos)
{
	struct roccat_reader *reader = file->private_data;
	struct roccat_device *device = reader->device;
	struct roccat_report *report;
	ssize_t retval = 0, len;
	DECLARE_WAITQUEUE(wait, current);

	mutex_lock(&device->cbuf_lock);

	...

	report = &device->cbuf[reader->cbuf_start];
	/*
	 * If report is larger than requested amount of data, rest of report
	 * is lost!
	 */
	len = device->report_size > count ? count : device->report_size;

	if (copy_to_user(buffer, report->value, len)) {
		retval = -EFAULT;
		goto exit_unlock;
	}
	...

The roccat_read() function receives the device->cbuf report and
delivers it to the user through copy_to_user().
If the N+ROCCAT_CBUF_SIZE th report is received while copying of
the Nth report->value is in progress, the pointer that copy_to_user()
is working on is kfree()ed and UAF read may occur. (race condition)

Since the device node of this driver does not set separate permissions,
this is not a security vulnerability, but because it is used for
requesting screen display of profile or dpi settings,
a user using the roccat device can apply udev to this device node or
There is a possibility to use it by giving.

Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2022-09-20 14:49:15 +02:00
..
accessibility speakup: Generate speakupmap.h automatically 2022-06-27 15:15:55 +02:00
acpi Driver core / kernfs changes for 6.0-rc1 2022-08-04 11:31:20 -07:00
amba ARM: 9220/1: amba: Remove deferred device addition 2022-07-28 15:09:23 +01:00
android binder: fix redefinition of seq_file attributes 2022-07-08 15:44:19 +02:00
ata ATA changes for 5.20-rc1 2022-08-03 15:26:04 -07:00
atm atm: he: Use the bitmap API to allocate bitmaps 2022-07-11 19:49:53 -07:00
auxdisplay
base Driver core / kernfs changes for 6.0-rc1 2022-08-04 11:31:20 -07:00
bcma
block for-5.20/block-2022-07-29 2022-08-02 13:46:35 -07:00
bluetooth SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
bus SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
cdrom block: remove blk_cleanup_disk 2022-06-28 06:33:15 -06:00
char SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
clk SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
clocksource - Add the missing DT bindings for the MTU nomadik timer (Linus 2022-07-28 12:33:34 +02:00
comedi
connector
counter counter: 104-quad-8: Implement and utilize register structures 2022-07-14 19:17:41 +02:00
cpufreq SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
cpuidle SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
crypto This update includes the following changes: 2022-08-02 17:45:14 -07:00
cxl cxl/mbox: Fix missing variable payload checks in cmd size validation 2022-06-28 22:03:18 -07:00
dax
dca
devfreq Char / Misc driver changes for 6.0-rc1 2022-08-04 11:05:48 -07:00
dio
dma Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/egtvedt/linux-avr32 2022-08-04 15:20:39 -07:00
dma-buf drm for 5.20/6.0 2022-08-03 19:52:08 -07:00
edac SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
eisa
extcon extcon: Add EXTCON_DISP_CVBS and EXTCON_DISP_EDP 2022-07-15 11:37:41 +09:00
firewire firewire: net: Make use of get_unaligned_be48(), put_unaligned_be48() 2022-07-28 22:21:54 -07:00
firmware Char / Misc driver changes for 6.0-rc1 2022-08-04 11:05:48 -07:00
fpga fpga: fpga-mgr: Fix spelling mistake "bitsream" -> "bitstream" 2022-06-29 15:18:18 +08:00
fsi
gnss
gpio SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
gpu drm/amd/amdgpu: fix build failure due to implicit declaration 2022-08-04 12:29:10 -07:00
greybus
hid HID: roccat: Fix use-after-free in roccat_read() 2022-09-20 14:49:15 +02:00
hsi
hte
hv
hwmon hwmon updates for v5.20 2022-08-02 11:07:04 -07:00
hwspinlock
hwtracing CoreSight self-hosted tracing changes for v5.20. 2022-07-11 20:54:28 +02:00
i2c SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
i3c
idle Power management updates for 5.20-rc1 2022-08-02 11:17:00 -07:00
iio iio: light: isl29028: Fix the warning in isl29028_remove() 2022-07-19 09:42:11 +01:00
infiniband Networking changes for 6.0. 2022-08-03 16:29:08 -07:00
input SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
interconnect Merge branch 'icc-rpm' into icc-next 2022-07-15 17:56:31 +03:00
iommu Driver core / kernfs changes for 6.0-rc1 2022-08-04 11:31:20 -07:00
ipack
irqchip SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
isdn
leds
macintosh
mailbox
mcb drivers: mcb: directly use ida_alloc()/free() 2022-07-12 09:04:55 +02:00
md hardening updates for v5.20-rc1 2022-08-02 14:38:59 -07:00
media SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
memory SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
memstick block: remove blk_cleanup_disk 2022-06-28 06:33:15 -06:00
message
mfd Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/egtvedt/linux-avr32 2022-08-04 15:20:39 -07:00
misc Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/egtvedt/linux-avr32 2022-08-04 15:20:39 -07:00
mmc SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
most
mtd for-5.20/block-2022-07-29 2022-08-02 13:46:35 -07:00
mux
net Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/egtvedt/linux-avr32 2022-08-04 15:20:39 -07:00
nfc NFC: nxp-nci: add error reporting 2022-07-13 18:52:12 -07:00
ntb
nubus
nvdimm for-5.20/block-2022-07-29 2022-08-02 13:46:35 -07:00
nvme iov_iter work, part 1 - isolated cleanups and optimizations. 2022-08-03 13:50:22 -07:00
nvmem SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
of Driver core / kernfs changes for 6.0-rc1 2022-08-04 11:31:20 -07:00
opp PM: EM: convert power field to micro-Watts precision and align drivers 2022-07-15 19:17:30 +02:00
parisc genirq: Add and use an irq_data_update_affinity helper 2022-07-07 09:38:04 +01:00
parport
pci PCI: hv: Take a const cpumask in hv_compose_msi_req_get_cpu() 2022-07-08 08:44:15 +01:00
pcmcia
peci
perf drivers/perf: arm_spe: Fix consistency of SYS_PMSCR_EL1.CX 2022-07-19 18:50:09 +01:00
phy SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
pinctrl SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
platform Merge branch 'acpi-bus' 2022-07-29 19:58:52 +02:00
pnp
power SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
powercap Power management updates for 5.20-rc1 2022-08-02 11:17:00 -07:00
pps
ps3
ptp SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
pwm SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
rapidio
ras
regulator SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
remoteproc Revert "devcoredump: remove the useless gfp_t parameter in dev_coredumpv and dev_coredumpm" 2022-06-27 16:39:29 +02:00
reset SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
rpmsg
rtc
s390 ARM: 2022-08-04 14:59:54 -07:00
sbus
scsi SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
sh genirq: Add and use an irq_data_update_affinity helper 2022-07-07 09:38:04 +01:00
siox
slimbus slimbus: messaging: fix typos in comments 2022-07-08 15:43:42 +02:00
soc SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
soundwire Char / Misc driver changes for 6.0-rc1 2022-08-04 11:05:48 -07:00
spi Driver core / kernfs changes for 6.0-rc1 2022-08-04 11:31:20 -07:00
spmi
ssb
staging Staging driver patches for 6.0-rc1 2022-08-04 12:01:42 -07:00
target for-5.20/block-2022-07-29 2022-08-02 13:46:35 -07:00
tc
tee tee: tee_get_drvdata(): fix description of return value 2022-07-08 10:51:24 +02:00
thermal SPDX changes for 6.0-rc1 2022-08-04 12:12:54 -07:00
thunderbolt USB / Thunderbolt changes for 6.0-rc1 2022-08-04 11:41:28 -07:00
tty ARM: SoC drivers for 6.0 2022-08-02 08:10:10 -07:00
ufs for-5.20/block-2022-07-29 2022-08-02 13:46:35 -07:00
uio
usb Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/egtvedt/linux-avr32 2022-08-04 15:20:39 -07:00
vdpa vduse: Tie vduse mgmtdev and its device 2022-06-24 02:49:48 -04:00
vfio ARM: 2022-08-04 14:59:54 -07:00
vhost vhost-vdpa: call vhost_vdpa_cleanup during the release 2022-06-27 08:05:35 -04:00
video Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/egtvedt/linux-avr32 2022-08-04 15:20:39 -07:00
virt Char / Misc driver changes for 6.0-rc1 2022-08-04 11:05:48 -07:00
virtio xen: branch for v6.0-rc1 2022-08-04 15:10:55 -07:00
vlynq
w1
watchdog
xen xen: branch for v6.0-rc1 2022-08-04 15:10:55 -07:00
zorro
Kconfig
Makefile Staging driver patches for 6.0-rc1 2022-08-04 12:01:42 -07:00