Re: [syzbot] [net?] KASAN: slab-use-after-free Read in unix_stream_read_actor (2)

From: Lizhi Xu
Date: Thu Sep 05 2024 - 01:26:07 EST


The sock queue oob twice, the first manage_oob (in unix_stream_read_generic) peek next skb only,
and the next skb is the oob skb, so if skb is oob skb we need use manage_oob dealwith it.

#syz test

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 0be0dcb07f7b..2821a8b5dea9 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2918,6 +2918,14 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,

/* Mark read part of skb as used */
if (!(flags & MSG_PEEK)) {
+#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
+ if (skb == u->oob_skb) {
+ skb = manage_oob(skb, sk, flags, copied);
+ if (!skb && copied) {
+ break;
+ }
+ }
+#endif
UNIXCB(skb).consumed += chunk;

sk_peek_offset_bwd(sk, chunk);