* [PATCH] posix-clock: initialize cdev state before publishing
@ 2026-11-16 3:28 Haoli Zhang
2026-11-19 16:29 ` Frederic Weisbecker
0 siblings, 1 reply; 2+ messages in thread
From: Haoli Zhang @ 2026-11-16 3:28 UTC (permalink / raw)
To: tglx, anna-maria, frederic
Cc: linux-kernel, richardcochran, syzbot+667788430769ef9ddf25,
stable, 25031212117, byu, Haoli Zhang
cdev_device_add() may expose the cdev before it returns. Initialize
clk->cdev.owner and clk->dev before calling it, so an open racing with
registration takes the matching module and device references.
If cdev_device_add() fails after cdev_add() made the cdev available,
open files may still exist. Mark the clock as a zombie under rwsem before
returning the error, so subsequent read, poll, ioctl, and dynamic clock
operations on those files fail while the caller tears down registration
state. Keep clk->dev valid so the release path can drop any reference
acquired by a successful open.
Fixes: a33121e5487b ("ptp: fix the race between the release of ptp_clock and cdev")
Reported-by: syzbot+667788430769ef9ddf25@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=667788430769ef9ddf25
Cc: stable@vger.kernel.org
Co-developed-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
Signed-off-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Haoli Zhang <26031212468@stu.xidian.edu.cn>
---
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -164,14 +164,18 @@
init_rwsem(&clk->rwsem);
cdev_init(&clk->cdev, &posix_clock_file_operations);
+ /* cdev_device_add() can expose the cdev before it returns. */
+ clk->cdev.owner = clk->ops.owner;
+ clk->dev = dev;
err = cdev_device_add(&clk->cdev, dev);
if (err) {
pr_err("%s unable to add device %d:%d\n",
dev_name(dev), MAJOR(dev->devt), MINOR(dev->devt));
- return err;
- }
- clk->cdev.owner = clk->ops.owner;
- clk->dev = dev;
+ down_write(&clk->rwsem);
+ clk->zombie = true;
+ up_write(&clk->rwsem);
+ return err;
+ }
return 0;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] posix-clock: initialize cdev state before publishing
2026-11-16 3:28 [PATCH] posix-clock: initialize cdev state before publishing Haoli Zhang
@ 2026-11-19 16:29 ` Frederic Weisbecker
0 siblings, 0 replies; 2+ messages in thread
From: Frederic Weisbecker @ 2026-11-19 16:29 UTC (permalink / raw)
To: Haoli Zhang
Cc: tglx, anna-maria, linux-kernel, richardcochran,
syzbot+667788430769ef9ddf25, stable, 25031212117, byu
Le Mon, Nov 16, 2026 at 11:28:53AM +0800, Haoli Zhang a écrit :
> cdev_device_add() may expose the cdev before it returns. Initialize
> clk->cdev.owner and clk->dev before calling it, so an open racing with
> registration takes the matching module and device references.
>
> If cdev_device_add() fails after cdev_add() made the cdev available,
> open files may still exist. Mark the clock as a zombie under rwsem before
> returning the error, so subsequent read, poll, ioctl, and dynamic clock
> operations on those files fail while the caller tears down registration
> state. Keep clk->dev valid so the release path can drop any reference
> acquired by a successful open.
Is the device made available before device_add()?
Thanks.
--
Frederic Weisbecker
SUSE Labs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 16:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 3:28 [PATCH] posix-clock: initialize cdev state before publishing Haoli Zhang
2026-11-19 16:29 ` Frederic Weisbecker
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®