[PATCH] ptp: posix clock is available after it has been successfully registered
From: Edward Adam Davis
Date: Sun Nov 15 2026 - 22:50:21 EST
In posix_clock_register() (kernel/time/posix-clock.c), clk->dev and
clk->cdev.owner are assigned only after cdev_device_add(&clk->cdev, dev)
returns. As soon as cdev_add() executes inside cdev_device_add(), the
character device is live and can be opened by userspace.
If posix_clock_open() runs in this window while clk->dev is still NULL,
get_device(clk->dev) is a no-op and fails to acquire a reference on the
device. When the file is later closed, posix_clock_release() calls
put_device(clk->dev) on the now-initialized pointer, causing an unbalanced
reference drop that prematurely frees the struct ptp_clock; subsequent
invocation of cdev_put(inode->i_cdev) in __fput() then accesses the freed
memory, causing a slab use-after-free.
Reject posix clock open if it has not been successfully registered.
Fixes: a33121e5487b ("ptp: fix the race between the release of ptp_clock and cdev")
Reported-by: syzbot+667788430769ef9ddf25@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=667788430769ef9ddf25
Signed-off-by: Edward Adam Davis <eadavis@xxxxxxxx>
---
kernel/time/posix-clock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index dab37295c8c2..37cc015cd8b0 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -99,7 +99,7 @@ static int posix_clock_open(struct inode *inode, struct file *fp)
down_read(&clk->rwsem);
- if (clk->zombie) {
+ if (clk->zombie || !clk->dev) {
err = -ENODEV;
goto out;
}
--
2.43.0