All of lore.kernel.org
 help / color / mirror / Atom feed
* [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

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.