linux/drivers/char
Jaewon Yang f20d61c22b tpm: Make the TPM character devices non-seekable
The TPM character devices expose a sequential command/response
interface, but their open handlers leave FMODE_PREAD and FMODE_PWRITE
enabled.

After a command leaves a response pending, pread(fd, buf, 16, 0x1400)
passes 0x1400 as *off to tpm_common_read(). The transfer length is
bounded by response_length, but the offset is used unchecked when
forming data_buffer + *off. A sufficiently large offset therefore causes
an out-of-bounds heap read through copy_to_user() and, if the copy
succeeds, an out-of-bounds zero-write through the following memset().

Positional I/O does not provide coherent semantics for this interface.
An arbitrary pread offset cannot represent how much of a response has
been consumed sequentially. The write callback always stores a command
at the start of data_buffer, while pwrite() does not update file->f_pos
and can leave the sequential read cursor stale.

Call nonseekable_open() from both open handlers. This removes
FMODE_PREAD and FMODE_PWRITE, causing positional reads and writes to
fail with -ESPIPE before reaching the TPM callbacks, and explicitly
marks the files non-seekable. Normal read() and write() continue to use
the existing sequential f_pos cursor, leaving the response state machine
unchanged.

Tested on Linux 6.12 with KASAN and a swtpm TPM2 device:

 - sequential partial reads returned the complete response
 - pread() and preadv() with offset 0x1400 returned -ESPIPE
 - pwrite() and pwritev() with offset zero returned -ESPIPE
 - the pending response remained intact after the rejected operations
 - a subsequent normal command/response cycle completed normally
 - no KASAN report was produced.

Fixes: 9488585b21 ("tpm: add support for partial reads")
Link: https://lore.kernel.org/all/20260710090217.191289-1-yong010301@gmail.com/
Cc: stable@vger.kernel.org
Signed-off-by: Jaewon Yang <yong010301@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-07-12 12:52:34 -07:00
..
agp drm-next for 7.2-rc1 2026-06-17 10:21:00 +01:00
hw_random Replace <linux/mod_devicetable.h> by more specific <linux/device-id/*.h> (c files) 2026-07-03 07:38:17 +02:00
ipmi ipmi: Drop unused assignment of platform_device_id driver data 2026-06-16 14:26:36 -05:00
tpm tpm: Make the TPM character devices non-seekable 2026-07-12 12:52:34 -07:00
xilinx_hwicap xilinx_hwicap: fifo_icap.c: fix all kernel-doc warnings 2026-01-16 16:36:04 +01:00
xillybus Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
adi.c char/adi: Use min_t(size_t,,) in adi_read() + adi_write() 2025-10-22 07:53:49 +02:00
apm-emulation.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
bsr.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ds1620.c
dsp56k.c
hangcheck-timer.c hangcheck-timer: fix coding style spacing 2025-11-26 15:11:15 +01:00
hpet.c hpet: Check ACPI_COMPANION() against NULL at probe time 2026-05-23 13:47:34 +02:00
Kconfig char: applicom: remove low-quality, unused driver 2026-05-23 13:47:34 +02:00
lp.c
Makefile char: applicom: remove low-quality, unused driver 2026-05-23 13:47:34 +02:00
mem.c mm/vma: eliminate mmap_action->error_hook, introduce error_override 2026-06-04 14:45:00 -07:00
misc_minor_kunit.c char: misc: Use IS_ERR() for filp_open() return value 2025-12-29 11:59:22 +01:00
misc.c char: Use list_del_init() in misc_deregister() to reinitialize list pointer 2025-09-06 19:43:18 +02:00
nsc_gpio.c char: remove unnecessary module_init/exit functions 2026-04-02 17:05:53 +02:00
nvram.c char/nvram: Remove redundant nvram_mutex 2026-05-23 13:47:34 +02:00
nwbutton.c
nwbutton.h
nwflash.c
pc8736x_gpio.c
powernv-op-panel.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ppdev.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ps3flash.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
random.c random: vDSO: Remove ifdeffery 2026-03-11 15:22:49 +01:00
scx200_gpio.c
sonypi.c platform-drivers-x86 for v7.2-1 2026-06-23 08:31:33 -07:00
tlclk.c char: tlclk: fix use-after-free in tlclk_cleanup() 2026-05-23 13:47:33 +02:00
toshiba.c
ttyprintk.c
uv_mmtimer.c
virtio_console.c virtio_console: read size from config space during device init 2026-06-10 02:14:02 -04:00