net: add debug info to __skb_pull()
authorEric Dumazet <edumazet@google.com>
Thu, 2 Jun 2022 16:18:58 +0000 (09:18 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 2 Jun 2022 17:15:05 +0000 (10:15 -0700)
While analyzing yet another syzbot report, I found the following
patch very useful. It allows to better understand what went wrong.

This debug info is only enabled if CONFIG_DEBUG_NET=y,
which is the case for syzbot builds.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/skbuff.h

index da96f0d..d3d1055 100644 (file)
@@ -2696,7 +2696,14 @@ void *skb_pull(struct sk_buff *skb, unsigned int len);
 static inline void *__skb_pull(struct sk_buff *skb, unsigned int len)
 {
        skb->len -= len;
-       BUG_ON(skb->len < skb->data_len);
+       if (unlikely(skb->len < skb->data_len)) {
+#if defined(CONFIG_DEBUG_NET)
+               skb->len += len;
+               pr_err("__skb_pull(len=%u)\n", len);
+               skb_dump(KERN_ERR, skb, false);
+#endif
+               BUG();
+       }
        return skb->data += len;
 }