From: Danish Khateeb <danishkhateeb03@gmail.com>
To: Rodolfo Giometti <giometti@enneenne.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Calvin Owens <calvin@wbinvd.org>, Yibo Tan <lhfff@tju.edu.cn>,
linux-kernel@vger.kernel.org,
Danish Khateeb <danishkhateeb03@gmail.com>
Subject: [PATCH v2 4/4] pps: generators: wake up PPS_GEN_FETCHEVENT readers on unregister
Date: Tue, 29 Sep 2026 07:49:37 -0500 [thread overview]
Message-ID: <20260929124937.51114-5-danishkhateeb03@gmail.com> (raw)
In-Reply-To: <20260929124937.51114-1-danishkhateeb03@gmail.com>
A reader sleeping in PPS_GEN_FETCHEVENT waits for the next event, but
no event comes after pps_gen_unregister_source(), so the reader sleeps
until it gets a signal. A PPS_GEN_FETCHEVENT issued after the
unregister sleeps the same way.
Wake up the readers on unregister, and make PPS_GEN_FETCHEVENT fail
with -ENODEV once the generator is gone, like the other ioctls. The
wait checks info without info_lock, so clear it with WRITE_ONCE().
Fixes: 86b525bed275 ("drivers pps: add PPS generators support")
Suggested-by: Rodolfo Giometti <giometti@enneenne.com>
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
---
Notes:
Tested in the same setup. With a reader asleep in PPS_GEN_FETCHEVENT,
unbinding the test driver used to leave it asleep until its alarm(5)
fired (-EINTR after 5 s), and a PPS_GEN_FETCHEVENT after the unbind
did the same. With this patch both return -ENODEV right away. Normal
use of pps_gen-dummy, including PPS_GEN_FETCHEVENT, is unchanged.
drivers/pps/generators/pps_gen.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/pps/generators/pps_gen.c b/drivers/pps/generators/pps_gen.c
index 452cc12a96f2..474e17c36458 100644
--- a/drivers/pps/generators/pps_gen.c
+++ b/drivers/pps/generators/pps_gen.c
@@ -103,11 +103,14 @@ static long pps_gen_cdev_ioctl(struct file *file,
dev_dbg(&pps_gen->dev, "PPS_GEN_FETCHEVENT\n");
ret = wait_event_interruptible(pps_gen->queue,
- ev != pps_gen->last_ev);
+ ev != pps_gen->last_ev ||
+ !READ_ONCE(pps_gen->info));
if (ret == -ERESTARTSYS) {
dev_dbg(&pps_gen->dev, "pending signal caught\n");
return -EINTR;
}
+ if (!READ_ONCE(pps_gen->info))
+ return -ENODEV;
spin_lock_irq(&pps_gen->lock);
info.sequence = pps_gen->sequence;
@@ -238,9 +241,12 @@ static void pps_gen_unregister_cdev(struct pps_gen_device *pps_gen)
pps_gen->info->enable(pps_gen, false);
pps_gen->enabled = false;
}
- pps_gen->info = NULL;
+ WRITE_ONCE(pps_gen->info, NULL);
}
+ /* Wake up the readers in PPS_GEN_FETCHEVENT, they fail now as well */
+ wake_up_interruptible_all(&pps_gen->queue);
+
put_device(&pps_gen->dev);
}
--
2.55.0
next prev parent reply other threads:[~2026-09-29 12:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 12:49 [PATCH v2 0/4] pps: generators: fix use-after-free on unregister with the file open Danish Khateeb
2026-09-29 12:49 ` [PATCH v2 1/4] pps: generators: fix use-after-free when closing a removed device Danish Khateeb
2026-09-30 12:07 ` Rodolfo Giometti
2026-09-29 12:49 ` [PATCH v2 2/4] pps: generators: don't use the driver's info after unregister Danish Khateeb
2026-09-30 12:09 ` Rodolfo Giometti
2026-09-29 12:49 ` [PATCH v2 3/4] pps: generators: stop the generator on unregister Danish Khateeb
2026-09-30 12:10 ` Rodolfo Giometti
2026-09-29 12:49 ` Danish Khateeb [this message]
2026-09-30 12:10 ` [PATCH v2 4/4] pps: generators: wake up PPS_GEN_FETCHEVENT readers " Rodolfo Giometti
2026-09-30 12:07 ` [PATCH v2 0/4] pps: generators: fix use-after-free on unregister with the file open Rodolfo Giometti
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=20260929124937.51114-5-danishkhateeb03@gmail.com \
--to=danishkhateeb03@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=calvin@wbinvd.org \
--cc=giometti@enneenne.com \
--cc=gregkh@linuxfoundation.org \
--cc=lhfff@tju.edu.cn \
--cc=linux-kernel@vger.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®