* Re: [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue
[not found] <20220724052426.2504-1-hdanton@sina.com>
@ 2022-07-24 6:26 ` Siddh Raman Pant via Linux-kernel-mentees
2022-07-27 14:49 ` David Howells
1 sibling, 0 replies; 9+ messages in thread
From: Siddh Raman Pant @ 2022-07-24 6:26 UTC (permalink / raw)
To: Hillf Danton
Cc: David Howells, Fabio M. De Francesco, linux-kernel,
syzbot+c70d87ac1d001f29a058, linux-security-modules,
linux-kernel-mentees
On Sun, 24 Jul 2022 10:54:26 +0530 Hillf Danton <hdanton@sina.com> wrote:
> According to sysbot's report [1], what is proposed fails to fix the
> reported uaf in the scenario below because of no wqueue->lock acquired
> in the post path. Despite of defunct checked, it is checked after taking
> pipe's wait lock - a bit too late.
>
> Hillf
>
> post_one_notification watch_queue_clear
> === ===
> pipe = wqueue->pipe;
> if (!pipe)
> return false;
> spin_lock_bh(&wqueue->lock);
> wqueue->pipe = NULL;
> spin_lock_bh(&wqueue->lock);
>
> pipe is freed
>
> spin_lock_irq(&pipe->rd_wait.lock); // uaf reported
>
> if (wqueue->defunct)
> goto out;
>
> [1] https://lore.kernel.org/lkml/000000000000aa07b205daba6d49@google.com/
>
Before post_one_notification(), in __post_watch_notification(), on line 228
wqueue->lock is acquired (using lock_wqueue()).
The comment on post_one_notification() also tells that it should be called
with wqueue->lock held. So we do acquire the lock in the post path.
The pipe is freed after the execution of watch_queue_clear() in
free_pipe_info().
A side note: Your emails don't seem to pop up on lore's LKML archive. Maybe
check if the email isn't being blocked?
Thanks,
Siddh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue
@ 2022-07-24 6:26 ` Siddh Raman Pant via Linux-kernel-mentees
0 siblings, 0 replies; 9+ messages in thread
From: Siddh Raman Pant via Linux-kernel-mentees @ 2022-07-24 6:26 UTC (permalink / raw)
To: Hillf Danton
Cc: Fabio M. De Francesco, linux-kernel, syzbot+c70d87ac1d001f29a058,
David Howells, linux-security-modules, linux-kernel-mentees
On Sun, 24 Jul 2022 10:54:26 +0530 Hillf Danton <hdanton@sina.com> wrote:
> According to sysbot's report [1], what is proposed fails to fix the
> reported uaf in the scenario below because of no wqueue->lock acquired
> in the post path. Despite of defunct checked, it is checked after taking
> pipe's wait lock - a bit too late.
>
> Hillf
>
> post_one_notification watch_queue_clear
> === ===
> pipe = wqueue->pipe;
> if (!pipe)
> return false;
> spin_lock_bh(&wqueue->lock);
> wqueue->pipe = NULL;
> spin_lock_bh(&wqueue->lock);
>
> pipe is freed
>
> spin_lock_irq(&pipe->rd_wait.lock); // uaf reported
>
> if (wqueue->defunct)
> goto out;
>
> [1] https://lore.kernel.org/lkml/000000000000aa07b205daba6d49@google.com/
>
Before post_one_notification(), in __post_watch_notification(), on line 228
wqueue->lock is acquired (using lock_wqueue()).
The comment on post_one_notification() also tells that it should be called
with wqueue->lock held. So we do acquire the lock in the post path.
The pipe is freed after the execution of watch_queue_clear() in
free_pipe_info().
A side note: Your emails don't seem to pop up on lore's LKML archive. Maybe
check if the email isn't being blocked?
Thanks,
Siddh
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue
2022-07-24 6:26 ` Siddh Raman Pant via Linux-kernel-mentees
(?)
@ 2022-07-24 7:19 ` Hillf Danton
2022-07-24 7:48 ` Siddh Raman Pant via Linux-kernel-mentees
-1 siblings, 1 reply; 9+ messages in thread
From: Hillf Danton @ 2022-07-24 7:19 UTC (permalink / raw)
To: Siddh Raman Pant
Cc: Fabio M. De Francesco, linux-kernel, syzbot+c70d87ac1d001f29a058,
David Howells, linux-security-modules, linux-kernel-mentees
On Sun, 24 Jul 2022 11:56:30 +0530 Siddh Raman Pant wrote:
>
> Before post_one_notification(), in __post_watch_notification(), on line 228
> wqueue->lock is acquired (using lock_wqueue()).
Yes, you are right. I missed 353f7988dd84 ("watchqueue: make sure to serialize
'wqueue->defunct' properly"). Sorry for my noise.
Given defunct serialized, still need to clear wqueue->pipe in the clear
path as proposed?
Hillf
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue
2022-07-24 7:19 ` Hillf Danton
@ 2022-07-24 7:48 ` Siddh Raman Pant via Linux-kernel-mentees
0 siblings, 0 replies; 9+ messages in thread
From: Siddh Raman Pant @ 2022-07-24 7:48 UTC (permalink / raw)
To: Hillf Danton
Cc: David Howells, Fabio M. De Francesco, linux-kernel,
syzbot+c70d87ac1d001f29a058, linux-security-modules,
linux-kernel-mentees
On Sun, 24 Jul 2022 12:49:58 +0530 Hillf Danton <hdanton@sina.com> wrote:
> Given defunct serialized, still need to clear wqueue->pipe in the clear
> path as proposed?
I am not sure what you mean by this...
If you mean freeing the pipe, it is done by free_pipe_info(), which is
the caller of watch_queue_clear().
If you mean making wqueue->pipe NULL, it is being done so in the patch.
Thanks,
Siddh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue
@ 2022-07-24 7:48 ` Siddh Raman Pant via Linux-kernel-mentees
0 siblings, 0 replies; 9+ messages in thread
From: Siddh Raman Pant via Linux-kernel-mentees @ 2022-07-24 7:48 UTC (permalink / raw)
To: Hillf Danton
Cc: Fabio M. De Francesco, linux-kernel, syzbot+c70d87ac1d001f29a058,
David Howells, linux-security-modules, linux-kernel-mentees
On Sun, 24 Jul 2022 12:49:58 +0530 Hillf Danton <hdanton@sina.com> wrote:
> Given defunct serialized, still need to clear wqueue->pipe in the clear
> path as proposed?
I am not sure what you mean by this...
If you mean freeing the pipe, it is done by free_pipe_info(), which is
the caller of watch_queue_clear().
If you mean making wqueue->pipe NULL, it is being done so in the patch.
Thanks,
Siddh
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue
[not found] <20220724052426.2504-1-hdanton@sina.com>
@ 2022-07-27 14:49 ` David Howells
2022-07-27 14:49 ` David Howells
1 sibling, 0 replies; 9+ messages in thread
From: David Howells @ 2022-07-27 14:49 UTC (permalink / raw)
To: Hillf Danton
Cc: dhowells, Siddh Raman Pant, Fabio M. De Francesco, linux-kernel,
syzbot+c70d87ac1d001f29a058, linux-security-modules,
linux-kernel-mentees
Hillf Danton <hdanton@sina.com> wrote:
> Yes, you are right. I missed 353f7988dd84 ("watchqueue: make sure to serialize
> 'wqueue->defunct' properly"). Sorry for my noise.
>
> Given defunct serialized, still need to clear wqueue->pipe in the clear
> path as proposed?
In fact, with the locking, is wqueue->defunct even still needed, I wonder?
David
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue
@ 2022-07-27 14:49 ` David Howells
0 siblings, 0 replies; 9+ messages in thread
From: David Howells @ 2022-07-27 14:49 UTC (permalink / raw)
To: Hillf Danton
Cc: linux-kernel-mentees, linux-kernel, syzbot+c70d87ac1d001f29a058,
dhowells, linux-security-modules, Fabio M. De Francesco
Hillf Danton <hdanton@sina.com> wrote:
> Yes, you are right. I missed 353f7988dd84 ("watchqueue: make sure to serialize
> 'wqueue->defunct' properly"). Sorry for my noise.
>
> Given defunct serialized, still need to clear wqueue->pipe in the clear
> path as proposed?
In fact, with the locking, is wqueue->defunct even still needed, I wonder?
David
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue
@ 2022-07-24 4:02 ` Siddh Raman Pant
0 siblings, 0 replies; 9+ messages in thread
From: Siddh Raman Pant via Linux-kernel-mentees @ 2022-07-24 4:02 UTC (permalink / raw)
To: David Howells, Christophe JAILLET, Eric Dumazet, Fabio M. De Francesco
Cc: linux-security-modules, linux-kernel-mentees, linux-kernel,
syzbot+c70d87ac1d001f29a058
If not done, a reference to a freed pipe remains in the watch_queue,
as this function is called before freeing a pipe in free_pipe_info()
(see line 834 of fs/pipe.c).
This causes a UAF when post_one_notification tries to access the pipe on
a key update, which is reported by syzbot.
Bug report: https://syzkaller.appspot.com/bug?id=1870dd7791ba05f2ea7f47f7cbdde701173973fc
Reported-and-tested-by: syzbot+c70d87ac1d001f29a058@syzkaller.appspotmail.com
Signed-off-by: Siddh Raman Pant <code@siddh.me>
---
Changes since v1:
- Removed the superfluous ifdef guard.
kernel/watch_queue.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
index bb9962b33f95..0357e5c6cf18 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -637,8 +637,15 @@ void watch_queue_clear(struct watch_queue *wqueue)
spin_lock_bh(&wqueue->lock);
}
- spin_unlock_bh(&wqueue->lock);
rcu_read_unlock();
+
+ /* Clearing the watch queue, so we should clean the associated pipe. */
+ if (wqueue->pipe) {
+ wqueue->pipe->watch_queue = NULL;
+ wqueue->pipe = NULL;
+ }
+
+ spin_unlock_bh(&wqueue->lock);
}
/**
--
2.35.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue
@ 2022-07-24 4:02 ` Siddh Raman Pant
0 siblings, 0 replies; 9+ messages in thread
From: Siddh Raman Pant @ 2022-07-24 4:02 UTC (permalink / raw)
To: David Howells, Christophe JAILLET, Eric Dumazet, Fabio M. De Francesco
Cc: linux-security-modules, linux-kernel, linux-kernel-mentees,
syzbot+c70d87ac1d001f29a058
If not done, a reference to a freed pipe remains in the watch_queue,
as this function is called before freeing a pipe in free_pipe_info()
(see line 834 of fs/pipe.c).
This causes a UAF when post_one_notification tries to access the pipe on
a key update, which is reported by syzbot.
Bug report: https://syzkaller.appspot.com/bug?id=1870dd7791ba05f2ea7f47f7cbdde701173973fc
Reported-and-tested-by: syzbot+c70d87ac1d001f29a058@syzkaller.appspotmail.com
Signed-off-by: Siddh Raman Pant <code@siddh.me>
---
Changes since v1:
- Removed the superfluous ifdef guard.
kernel/watch_queue.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
index bb9962b33f95..0357e5c6cf18 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -637,8 +637,15 @@ void watch_queue_clear(struct watch_queue *wqueue)
spin_lock_bh(&wqueue->lock);
}
- spin_unlock_bh(&wqueue->lock);
rcu_read_unlock();
+
+ /* Clearing the watch queue, so we should clean the associated pipe. */
+ if (wqueue->pipe) {
+ wqueue->pipe->watch_queue = NULL;
+ wqueue->pipe = NULL;
+ }
+
+ spin_unlock_bh(&wqueue->lock);
}
/**
--
2.35.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-07-27 14:49 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20220724052426.2504-1-hdanton@sina.com>
2022-07-24 6:26 ` [PATCH v2] kernel/watch_queue: Make pipe NULL while clearing watch_queue Siddh Raman Pant
2022-07-24 6:26 ` Siddh Raman Pant via Linux-kernel-mentees
2022-07-24 7:19 ` Hillf Danton
2022-07-24 7:48 ` Siddh Raman Pant
2022-07-24 7:48 ` Siddh Raman Pant via Linux-kernel-mentees
2022-07-27 14:49 ` David Howells
2022-07-27 14:49 ` David Howells
2022-07-24 4:02 Siddh Raman Pant via Linux-kernel-mentees
2022-07-24 4:02 ` Siddh Raman Pant
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.