From: Edward Adam Davis <eadavis@sina.com>
To: syzbot+667788430769ef9ddf25@syzkaller.appspotmail.com
Cc: anna-maria@linutronix.de, frederic@kernel.org, tglx@kernel.org,
richardcochran@gmail.com, driver-core@lists.linux.dev,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, dakr@kernel.org,
syzkaller-bugs@googlegroups.com
Subject: [PATCH] ptp: posix clock is available after it has been successfully registered
Date: Mon, 16 Nov 2026 11:49:57 +0800 [thread overview]
Message-ID: <20261116034957.40991-1-eadavis@sina.com> (raw)
In-Reply-To: <6af9e1eb.920b2b3a.148c65.002f.GAE@google.com>
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@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=667788430769ef9ddf25
Signed-off-by: Edward Adam Davis <eadavis@sina.com>
---
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
prev parent reply other threads:[~2026-11-16 3:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 16:46 [syzbot] [fs?] [driver-core?] KASAN: slab-use-after-free Read in cdev_put syzbot
2026-11-16 3:23 ` Edward Adam Davis
2026-11-16 3:23 ` syzbot
2026-11-16 3:49 ` Edward Adam Davis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116034957.40991-1-eadavis@sina.com \
--to=eadavis@sina.com \
--cc=anna-maria@linutronix.de \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=frederic@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=syzbot+667788430769ef9ddf25@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tglx@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®