summaryrefslogtreecommitdiff
path: root/include/linux/pps_gen_kernel.h
diff options
context:
space:
mode:
authorDanish Khateeb <danishkhateeb03@gmail.com>2026-09-29 07:49:34 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-10-01 15:45:00 +0200
commitd19552611cb2eb6329826871565e5309bec2f288 (patch)
treeca6e42556169f1e98b320a732866d2544af3d7bc /include/linux/pps_gen_kernel.h
parentd5e5a7bd7aac1707597479c83b4b2bd78c95831c (diff)
downloadlinux-next-d19552611cb2eb6329826871565e5309bec2f288.tar.gz
linux-next-d19552611cb2eb6329826871565e5309bec2f288.zip
pps: generators: fix use-after-free when closing a removed device
The cdev of a PPS generator is embedded in struct pps_gen_device, but nothing ties the lifetime of that structure to the cdev: pps_gen is freed by the release function of its device, and an open file holds a device reference only until pps_gen_cdev_release() drops it. When the generator is unregistered while /dev/pps-genN is open, that put_device() drops the last reference and frees pps_gen, and __fput() then calls cdev_put() on the freed cdev: BUG: KASAN: slab-use-after-free in cdev_put+0x53/0x60 Read of size 8 at addr ffff88801383e138 by task ppsgen64/149 Call Trace: cdev_put+0x53/0x60 __fput+0x745/0xad0 fput_close_sync+0xd9/0x1b0 __x64_sys_close+0x86/0xf0 ... Freed by task 149: kfree+0x25a/0x6d0 device_release+0xca/0x3c0 kobject_put+0x169/0x320 pps_gen_cdev_release+0x51/0x80 __fput+0x36a/0xad0 pps.c had the same bug, fixed in commit c79a39dc8d06 ("pps: Fix a use-after-free"). Fix it the usual way: embed the struct device in pps_gen_device and register both with cdev_device_add(). This makes the device the parent of the cdev, so the cdev holds a device reference until the last file is closed. Fixes: 86b525bed275 ("drivers pps: add PPS generators support") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com> Acked-by: Rodolfo Giometti <giometti@enneenne.com> Link: https://patch.msgid.link/20260929124937.51114-2-danishkhateeb03@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/pps_gen_kernel.h')
-rw-r--r--include/linux/pps_gen_kernel.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/linux/pps_gen_kernel.h b/include/linux/pps_gen_kernel.h
index 6214c8aa2e02..f26f6aac000d 100644
--- a/include/linux/pps_gen_kernel.h
+++ b/include/linux/pps_gen_kernel.h
@@ -54,7 +54,7 @@ struct pps_gen_device {
unsigned int id; /* PPS generator unique ID */
struct cdev cdev;
- struct device *dev;
+ struct device dev;
struct fasync_struct *async_queue; /* fasync method */
spinlock_t lock;
};