diff mbox series

[net,1/2] net: add debug info to __skb_pull()

Message ID 20220531185933.1086667-2-eric.dumazet@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: af_packet: be careful when expanding mac header size | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net, async
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5746 this patch: 5746
netdev/cc_maintainers warning 1 maintainers not CCed: imagedong@tencent.com
netdev/build_clang success Errors and warnings before: 1224 this patch: 1224
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5894 this patch: 5894
netdev/checkpatch warning WARNING: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Eric Dumazet May 31, 2022, 6:59 p.m. UTC
From: Eric Dumazet <edumazet@google.com>

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>
---
 include/linux/skbuff.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Willem de Bruijn May 31, 2022, 7:31 p.m. UTC | #1
On Tue, May 31, 2022 at 2:59 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
> From: Eric Dumazet <edumazet@google.com>
>
> 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>

The skb_dump output (including packet headers) on these bugs will make
root causing these failures a lot easier in the future. Thanks!
kernel test robot June 1, 2022, 7:27 a.m. UTC | #2
Hi Eric,

I love your patch! Yet something to improve:

[auto build test ERROR on net/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Eric-Dumazet/net-af_packet-be-careful-when-expanding-mac-header-size/20220601-030146
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 09e545f7381459c015b6fa0cd0ac6f010ef8cc25
config: arc-randconfig-r021-20220531 (https://download.01.org/0day-ci/archive/20220601/202206011509.Rpp82wrl-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/a907c048e7699133feedaa06948c15c719a59f94
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Eric-Dumazet/net-af_packet-be-careful-when-expanding-mac-header-size/20220601-030146
        git checkout a907c048e7699133feedaa06948c15c719a59f94
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arc-elf-ld: kernel/bpf/cgroup.o: in function `__skb_pull':
   include/linux/skbuff.h:2703: undefined reference to `skb_dump'
>> arc-elf-ld: include/linux/skbuff.h:2703: undefined reference to `skb_dump'
Eric Dumazet June 1, 2022, 5:26 p.m. UTC | #3
On Wed, Jun 1, 2022 at 12:28 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Eric,
>
> I love your patch! Yet something to improve:
>
> [auto build test ERROR on net/master]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Eric-Dumazet/net-af_packet-be-careful-when-expanding-mac-header-size/20220601-030146
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 09e545f7381459c015b6fa0cd0ac6f010ef8cc25
> config: arc-randconfig-r021-20220531 (https://download.01.org/0day-ci/archive/20220601/202206011509.Rpp82wrl-lkp@intel.com/config)
> compiler: arc-elf-gcc (GCC) 11.3.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/intel-lab-lkp/linux/commit/a907c048e7699133feedaa06948c15c719a59f94
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Eric-Dumazet/net-af_packet-be-careful-when-expanding-mac-header-size/20220601-030146
>         git checkout a907c048e7699133feedaa06948c15c719a59f94
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
>    arc-elf-ld: kernel/bpf/cgroup.o: in function `__skb_pull':
>    include/linux/skbuff.h:2703: undefined reference to `skb_dump'
> >> arc-elf-ld: include/linux/skbuff.h:2703: undefined reference to `skb_dump'
>


So... CONFIG_NET=n  and yet __cgroup_bpf_run_filter_skb() is using skbs ?

Not sure if this makes any sense.



>
> --
> 0-DAY CI Kernel Test Service
> https://01.org/lkp
kernel test robot June 1, 2022, 10:01 p.m. UTC | #4
Hi Eric,

I love your patch! Yet something to improve:

[auto build test ERROR on net/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Eric-Dumazet/net-af_packet-be-careful-when-expanding-mac-header-size/20220601-030146
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 09e545f7381459c015b6fa0cd0ac6f010ef8cc25
config: hexagon-randconfig-r002-20220531 (https://download.01.org/0day-ci/archive/20220602/202206020557.QyvlGs0H-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project c825abd6b0198fb088d9752f556a70705bc99dfd)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/a907c048e7699133feedaa06948c15c719a59f94
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Eric-Dumazet/net-af_packet-be-careful-when-expanding-mac-header-size/20220601-030146
        git checkout a907c048e7699133feedaa06948c15c719a59f94
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> ld.lld: error: undefined symbol: skb_dump
   >>> referenced by cgroup.c
   >>>               bpf/cgroup.o:(__cgroup_bpf_run_filter_skb) in archive kernel/built-in.a
   >>> referenced by cgroup.c
   >>>               bpf/cgroup.o:(__cgroup_bpf_run_filter_skb) in archive kernel/built-in.a
diff mbox series

Patch

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index da96f0d3e753fb7996631bc9350c0c8e0ec5966e..d3d10556f0faea8c8c1deed5715716d4916011d1 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -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;
 }