mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] watch_queue: keep info_id separate from rcu_head
@ 2026-10-29  5:41 Zhiyu Zhang
  2026-10-29 11:54 ` Bradley Morgan
  2026-10-30 14:53 ` Christian Brauner
  0 siblings, 2 replies; 3+ messages in thread
From: Zhiyu Zhang @ 2026-10-29  5:41 UTC (permalink / raw)
  To: Jarkko Sakkinen, Christian Brauner
  Cc: David Howells, Cen Zhang, Davidlohr Bueso, Bradley Morgan,
	linux-kernel, keyrings, Tong Liu, Qi Tang

struct watch overlays info_id with rcu_head. A notification poster reads
info_id under rcu_read_lock(), but a concurrent final put can enqueue the
watch with call_rcu(). Enqueueing the callback writes rcu_head before the
grace period has elapsed, so it can corrupt info_id while the object
remains legally visible to the reader.

__post_watch_notification() then merges that value into the notification
info word without masking it. Pointer bits can corrupt WATCH_INFO_LENGTH
and make post_one_notification() copy beyond the posting task's stack
record.

Give info_id storage separate from rcu_head so RCU enqueueing cannot modify
it. Place it after the kref, which uses existing tail padding on x86-64.
Mask info_id with WATCH_INFO_ID at the point of use as an additional
invariant check.

An unprivileged shell and keyctl reproducer was run for 30 seconds in QEMU.
The vulnerable baseline produced malformed notification lengths, while this
change completed with 288631 key notifications and no malformed record.

Fixes: c73be61cede5 ("pipe: Add general notification queue support")
Reported-by: Tong Liu <lyutoon@gmail.com>
Reported-by: Qi Tang <tpluszz77@gmail.com>
Reported-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
Closes: https://lore.kernel.org/lkml/CALf2hKveij_sHgANY9Aktm1dPa4wfKjKNkHyp9yPbjORWFXagA@mail.gmail.com/
Link: https://lore.kernel.org/netdev/CALf2hKvp0NPVLwr=a3+jUHtPohxbra8gox+aYAfWathJnn-J+Q@mail.gmail.com/
Signed-off-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
---
 include/linux/watch_queue.h | 6 ++----
 kernel/watch_queue.c        | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h
index 429c7b6afead..b87e1babb5f0 100644
--- a/include/linux/watch_queue.h
+++ b/include/linux/watch_queue.h
@@ -52,10 +52,7 @@ struct watch_queue {
  * Representation of a watch on an object.
  */
 struct watch {
-	union {
-		struct rcu_head	rcu;
-		u32		info_id;	/* ID to be OR'd in to info field */
-	};
+	struct rcu_head		rcu;
 	struct watch_queue __rcu *queue;	/* Queue to post events to */
 	struct hlist_node	queue_node;	/* Link in queue->watches */
 	struct watch_list __rcu	*watch_list;
@@ -64,6 +61,7 @@ struct watch {
 	void			*private;	/* Private data for the watched object */
 	u64			id;		/* Internal identifier */
 	struct kref		usage;		/* Object usage count */
+	u32			info_id;	/* ID to be OR'd in to info field */
 };
 
 /*
diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
index 932a88ac1f39..453dcf613205 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -212,7 +212,7 @@ void __post_watch_notification(struct watch_list *wlist,
 		if (watch->id != id)
 			continue;
 		n->info &= ~WATCH_INFO_ID;
-		n->info |= watch->info_id;
+		n->info |= watch->info_id & WATCH_INFO_ID;
 
 		wqueue = rcu_dereference(watch->queue);
 		wf = rcu_dereference(wqueue->filter);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] watch_queue: keep info_id separate from rcu_head
  2026-10-29  5:41 [PATCH] watch_queue: keep info_id separate from rcu_head Zhiyu Zhang
@ 2026-10-29 11:54 ` Bradley Morgan
  2026-10-30 14:53 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Bradley Morgan @ 2026-10-29 11:54 UTC (permalink / raw)
  To: Zhiyu Zhang, Jarkko Sakkinen, Christian Brauner
  Cc: David Howells, Cen Zhang, Davidlohr Bueso, linux-kernel,
	keyrings, Tong Liu, Qi Tang

On 29 October 2026 05:41:36 GMT, Zhiyu Zhang <zhiyuzhang999@gmail.com>
wrote:
>struct watch overlays info_id with rcu_head. A notification poster reads
>info_id under rcu_read_lock(), but a concurrent final put can enqueue the
>watch with call_rcu(). Enqueueing the callback writes rcu_head before the
>grace period has elapsed, so it can corrupt info_id while the object
>remains legally visible to the reader.
>
>__post_watch_notification() then merges that value into the notification
>info word without masking it. Pointer bits can corrupt WATCH_INFO_LENGTH
>and make post_one_notification() copy beyond the posting task's stack
>record.
>
>Give info_id storage separate from rcu_head so RCU enqueueing cannot
>modify
>it. Place it after the kref, which uses existing tail padding on x86-64.
>Mask info_id with WATCH_INFO_ID at the point of use as an additional
>invariant check.
>
>An unprivileged shell and keyctl reproducer was run for 30 seconds in
>QEMU.
>The vulnerable baseline produced malformed notification lengths, while
>this
>change completed with 288631 key notifications and no malformed record.
>
>Fixes: c73be61cede5 ("pipe: Add general notification queue support")
>Reported-by: Tong Liu <lyutoon@gmail.com>
>Reported-by: Qi Tang <tpluszz77@gmail.com>

Reviewed-by: Bradley Morgan <brads@mainlining.org>

>Reported-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
>Closes: https://lore.kernel.org/lkml/CALf2hKveij_sHgANY9Aktm1dPa4wfKjKNkHyp9yPbjORWFXagA@mail.gmail.com/
>Link: https://lore.kernel.org/netdev/CALf2hKvp0NPVLwr=a3+jUHtPohxbra8gox+aYAfWathJnn-J+Q@mail.gmail.com/
>Signed-off-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
>---
> include/linux/watch_queue.h | 6 ++----
> kernel/watch_queue.c        | 2 +-
> 2 files changed, 3 insertions(+), 5 deletions(-)
>
>diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h
>index 429c7b6afead..b87e1babb5f0 100644
>--- a/include/linux/watch_queue.h
>+++ b/include/linux/watch_queue.h
>@@ -52,10 +52,7 @@ struct watch_queue {
>  * Representation of a watch on an object.
>  */
> struct watch {
>-	union {
>-		struct rcu_head	rcu;
>-		u32		info_id;	/* ID to be OR'd in to info field */
>-	};
>+	struct rcu_head		rcu;
> 	struct watch_queue __rcu *queue;	/* Queue to post events to */
> 	struct hlist_node	queue_node;	/* Link in queue->watches */
> 	struct watch_list __rcu	*watch_list;
>@@ -64,6 +61,7 @@ struct watch {
> 	void			*private;	/* Private data for the watched object */
> 	u64			id;		/* Internal identifier */
> 	struct kref		usage;		/* Object usage count */
>+	u32			info_id;	/* ID to be OR'd in to info field */
> };
> 
> /*
>diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
>index 932a88ac1f39..453dcf613205 100644
>--- a/kernel/watch_queue.c
>+++ b/kernel/watch_queue.c
>@@ -212,7 +212,7 @@ void __post_watch_notification(struct watch_list *wlist,
> 		if (watch->id != id)
> 			continue;
> 		n->info &= ~WATCH_INFO_ID;
>-		n->info |= watch->info_id;
>+		n->info |= watch->info_id & WATCH_INFO_ID;
> 
> 		wqueue = rcu_dereference(watch->queue);
> 		wf = rcu_dereference(wqueue->filter);
>


--- Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] watch_queue: keep info_id separate from rcu_head
  2026-10-29  5:41 [PATCH] watch_queue: keep info_id separate from rcu_head Zhiyu Zhang
  2026-10-29 11:54 ` Bradley Morgan
@ 2026-10-30 14:53 ` Christian Brauner
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2026-10-30 14:53 UTC (permalink / raw)
  To: Jarkko Sakkinen, Zhiyu Zhang
  Cc: David Howells, Cen Zhang, Davidlohr Bueso, Bradley Morgan,
	linux-kernel, keyrings, Tong Liu, Qi Tang

On Thu, 29 Oct 2026 01:41:36 -0400, Zhiyu Zhang wrote:
> struct watch overlays info_id with rcu_head. A notification poster reads
> info_id under rcu_read_lock(), but a concurrent final put can enqueue the
> watch with call_rcu(). Enqueueing the callback writes rcu_head before the
> grace period has elapsed, so it can corrupt info_id while the object
> remains legally visible to the reader.
> 
> __post_watch_notification() then merges that value into the notification
> info word without masking it. Pointer bits can corrupt WATCH_INFO_LENGTH
> and make post_one_notification() copy beyond the posting task's stack
> record.
> 
> [...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] watch_queue: keep info_id separate from rcu_head
      https://git.kernel.org/vfs/vfs/c/53d72818f9e2


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-30 14:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29  5:41 [PATCH] watch_queue: keep info_id separate from rcu_head Zhiyu Zhang
2026-10-29 11:54 ` Bradley Morgan
2026-10-30 14:53 ` Christian Brauner

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®