[PATCH] Fix KMSAN infoleak, initialize unused data in pskb_expand_head

From: Daniel Yang
Date: Wed Oct 02 2024 - 01:39:14 EST


pskb_expand_head doesn't initialize extra nhead bytes in header and
tail bytes, leading to KMSAN infoleak error. Fix by initializing data to
0 with memset.

Reported-by: syzbot+346474e3bf0b26bd3090@xxxxxxxxxxxxxxxxxxxxxxxxx
Tested-by: Daniel Yang <danielyangkang@xxxxxxxxx>
Signed-off-by: Daniel Yang <danielyangkang@xxxxxxxxx>
---
net/core/skbuff.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 74149dc4e..348161dcb 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -2286,6 +2286,11 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
skb_shinfo(skb),
offsetof(struct skb_shared_info, frags[skb_shinfo(skb)->nr_frags]));

+ /* Initialize newly allocated headroom and tailroom
+ */
+ memset(data, 0, nhead);
+ memset(data + nhead + skb->tail, 0, skb_tailroom(skb) + ntail);
+
/*
* if shinfo is shared we must drop the old head gracefully, but if it
* is not we can just drop the old head and let the existing refcount
--
2.39.2