Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Yu Zhang
Mon, 26 Oct 2026 10:05
[PATCH] ptp: fix use-after-free in extts_fifo_show() reading tsevqs unlocked
Author: Yu Zhang
Date: Mon, 26 Oct 2026 10:05
Date: Mon, 26 Oct 2026 10:05
61 lines
12723 bytes
12723 bytes
extts_fifo_show() walks ptp->tsevqs with list_count_nodes() and then
list_first_entry() without holding ptp->tsevqs_lock, the spinlock that
"protects tsevqs from concurrent access". Every other accessor of the
list honours it: ptp_open() (list_add_tail), ptp_release() (list_del
followed by kfree of the per-fd queue), ptp_clock_release() and
ptp_clock_event() all take tsevqs_lock. extts_fifo_show() is the only
one that does not.
A per-fd timestamp queue is appended to tsevqs on open("/dev/ptpN") and
removed and freed on close(), both under tsevqs_lock:
scoped_guard(spinlock_irq, &ptp->tsevqs_lock)
list_del(&queue->qlist);
bitmap_free(queue->mask);
kfree(queue);
So a read of /sys/class/ptp/ptpN/fifo running concurrently with a
close() of a /dev/ptpN fd can have list_count_nodes() walk into the
queue that close() is removing and freeing, dereferencing freed memory
(use-after-free) or a poisoned list pointer.
Take tsevqs_lock around the list walk. The fifo only ever draws from the
first queue, which is the registration-time queue created in
ptp_clock_register() and freed only in ptp_clock_release(); that cannot
run while the sysfs attribute is being read, so the dequeue from
queue->buf under queue->lock may stay outside tsevqs_lock and the lock
order is unchanged.
Fixes: d26ab5a35ad9 ("ptp: Replace timestamp event queue with linked list")
Cc: stable@vger.kernel.org
Signed-off-by: Yu Zhang <yuz08559@gmail.com>
---
drivers/ptp/ptp_sysfs.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
index dc398c6..7d09256 100644
--- a/drivers/ptp/ptp_sysfs.c
+++ b/drivers/ptp/ptp_sysfs.c
@@ -80,13 +80,17 @@ static ssize_t extts_fifo_show(struct device *dev,
size_t qcnt;
int cnt = 0;
+ spin_lock_irqsave(&ptp->tsevqs_lock, flags);
cnt = list_count_nodes(&ptp->tsevqs);
- if (cnt <= 0)
+ if (cnt <= 0) {
+ spin_unlock_irqrestore(&ptp->tsevqs_lock, flags);
goto out;
+ }
/* The sysfs fifo will always draw from the fist queue */
queue = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue,
qlist);
+ spin_unlock_irqrestore(&ptp->tsevqs_lock, flags);
memset(&event, 0, sizeof(event));
spin_lock_irqsave(&queue->lock, flags);
--
2.43.0
Re: [PATCH] ptp: fix use-after-free in extts_fifo_show() reading tsevqs unlocked
Author: netdev-bot+sinfo
Date: Mon, 26 Oct 2026 10:10
Date: Mon, 26 Oct 2026 10:10
22 lines
8506 bytes
8506 bytes
Hi! This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information: - How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan. - Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages. Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then. The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Re: [PATCH] ptp: fix use-after-free in extts_fifo_show() reading tsevqs unlocked
Author: patchwork-bot+netdevbpf
Date: Fri, 30 Oct 2026 23:20
Date: Fri, 30 Oct 2026 23:20
25 lines
8667 bytes
8667 bytes
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 26 Oct 2026 20:05:35 +1000 you wrote:
> extts_fifo_show() walks ptp->tsevqs with list_count_nodes() and then
> list_first_entry() without holding ptp->tsevqs_lock, the spinlock that
> "protects tsevqs from concurrent access". Every other accessor of the
> list honours it: ptp_open() (list_add_tail), ptp_release() (list_del
> followed by kfree of the per-fd queue), ptp_clock_release() and
> ptp_clock_event() all take tsevqs_lock. extts_fifo_show() is the only
> one that does not.
>
> [...]
Here is the summary with links:
- ptp: fix use-after-free in extts_fifo_show() reading tsevqs unlocked
https://git.kernel.org/netdev/net/c/603a0c40d414
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads