All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ethtool: do not vzalloc(0) on registers dump
@ 2017-02-02 11:31 Stanislaw Gruszka
  2017-02-02 12:00 ` kbuild test robot
  2017-02-02 12:22 ` kbuild test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Stanislaw Gruszka @ 2017-02-02 11:31 UTC (permalink / raw)
  To: netdev; +Cc: Ben Hutchings

If ->get_regs_len() callback return 0, we allocate 0 bytes of memory,
what print ugly warning in dmesg, which can be found further below.

This happen on mac80211 devices where ieee80211_get_regs_len() just
return 0 and driver only fills ethtool_regs structure and actually
do not provide any dump. However I assume this can happen on other
drivers i.e. when for some devices driver provide regs dump and for
others do not. Hence preventing to to print warning in ethtool code
seems to be reasonable.

ethtool: vmalloc: allocation failure: 0 bytes, mode:0x24080c2(GFP_KERNEL|__GFP_HIGHMEM|__GFP_ZERO)
<snip>
Call Trace:
[<ffffffff813bde47>] dump_stack+0x63/0x8c
[<ffffffff811b0a1f>] warn_alloc+0x13f/0x170
[<ffffffff811f0476>] __vmalloc_node_range+0x1e6/0x2c0
[<ffffffff811f0874>] vzalloc+0x54/0x60
[<ffffffff8169986c>] dev_ethtool+0xb4c/0x1b30
[<ffffffff816adbb1>] dev_ioctl+0x181/0x520
[<ffffffff816714d2>] sock_do_ioctl+0x42/0x50
<snip>
Mem-Info:
active_anon:435809 inactive_anon:173951 isolated_anon:0
 active_file:835822 inactive_file:196932 isolated_file:0
 unevictable:0 dirty:8 writeback:0 unstable:0
 slab_reclaimable:157732 slab_unreclaimable:10022
 mapped:83042 shmem:306356 pagetables:9507 bounce:0
 free:130041 free_pcp:1080 free_cma:0
Node 0 active_anon:1743236kB inactive_anon:695804kB active_file:3343288kB inactive_file:787728kB unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:332168kB dirty:32kB writeback:0kB shmem:0kB shmem_thp: 0kB shmem_pmdmapped: 0kB anon_thp: 1225424kB writeback_tmp:0kB unstable:0kB pages_scanned:0 all_unreclaimable? no
Node 0 DMA free:15900kB min:136kB low:168kB high:200kB active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB writepending:0kB present:15984kB managed:15900kB mlocked:0kB slab_reclaimable:0kB slab_unreclaimable:0kB kernel_stack:0kB pagetables:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
lowmem_reserve[]: 0 3187 7643 7643
Node 0 DMA32 free:419732kB min:28124kB low:35152kB high:42180kB active_anon:541180kB inactive_anon:248988kB active_file:1466388kB inactive_file:389632kB unevictable:0kB writepending:0kB present:3370280kB managed:3290932kB mlocked:0kB slab_reclaimable:217184kB slab_unreclaimable:4180kB kernel_stack:160kB pagetables:984kB bounce:0kB free_pcp:2236kB local_pcp:660kB free_cma:0kB
lowmem_reserve[]: 0 0 4456 4456

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
 net/core/ethtool.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 6b3eee0..3ec897f 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -1405,9 +1405,11 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
 	if (regs.len > reglen)
 		regs.len = reglen;
 
-	regbuf = vzalloc(reglen);
-	if (reglen && !regbuf)
-		return -ENOMEM;
+	if (reglen) {
+		regbuf = vzalloc(reglen);
+		if (!regbuf)
+			return -ENOMEM;
+	}
 
 	ops->get_regs(dev, &regs, regbuf);
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ethtool: do not vzalloc(0) on registers dump
  2017-02-02 11:31 [PATCH] ethtool: do not vzalloc(0) on registers dump Stanislaw Gruszka
@ 2017-02-02 12:00 ` kbuild test robot
  2017-02-02 12:22 ` kbuild test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kbuild test robot @ 2017-02-02 12:00 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: kbuild-all, netdev, Ben Hutchings

[-- Attachment #1: Type: text/plain, Size: 3384 bytes --]

Hi Stanislaw,

[auto build test WARNING on net-next/master]
[also build test WARNING on v4.10-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Stanislaw-Gruszka/ethtool-do-not-vzalloc-0-on-registers-dump/20170202-194352
config: i386-randconfig-x001-201705 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   In file included from include/linux/uaccess.h:5:0,
                    from include/net/checksum.h:25,
                    from include/linux/skbuff.h:31,
                    from include/linux/if_ether.h:23,
                    from include/uapi/linux/ethtool.h:18,
                    from include/linux/ethtool.h:17,
                    from net/core/ethtool.c:18:
   net/core/ethtool.c: In function 'dev_ethtool':
>> arch/x86/include/asm/uaccess.h:722:5: warning: 'regbuf' may be used uninitialized in this function [-Wmaybe-uninitialized]
      n = _copy_to_user(to, from, n);
      ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   net/core/ethtool.c:1395:8: note: 'regbuf' was declared here
     void *regbuf;
           ^~~~~~

vim +/regbuf +722 arch/x86/include/asm/uaccess.h

0d025d27 Josh Poimboeuf  2016-08-30  706  		__bad_copy_user();
3df7b41a Jan Beulich     2013-10-21  707  
3df7b41a Jan Beulich     2013-10-21  708  	return n;
3df7b41a Jan Beulich     2013-10-21  709  }
3df7b41a Jan Beulich     2013-10-21  710  
e6971009 Kees Cook       2016-09-06  711  static __always_inline unsigned long __must_check
7a3d9b0f Jan Beulich     2013-10-21  712  copy_to_user(void __user *to, const void *from, unsigned long n)
7a3d9b0f Jan Beulich     2013-10-21  713  {
7a3d9b0f Jan Beulich     2013-10-21  714  	int sz = __compiletime_object_size(from);
7a3d9b0f Jan Beulich     2013-10-21  715  
1771c6e1 Andrey Ryabinin 2016-05-20  716  	kasan_check_read(from, n);
1771c6e1 Andrey Ryabinin 2016-05-20  717  
7a3d9b0f Jan Beulich     2013-10-21  718  	might_fault();
7a3d9b0f Jan Beulich     2013-10-21  719  
5b710f34 Kees Cook       2016-06-23  720  	if (likely(sz < 0 || sz >= n)) {
5b710f34 Kees Cook       2016-06-23  721  		check_object_size(from, n, true);
7a3d9b0f Jan Beulich     2013-10-21 @722  		n = _copy_to_user(to, from, n);
0d025d27 Josh Poimboeuf  2016-08-30  723  	} else if (!__builtin_constant_p(n))
0d025d27 Josh Poimboeuf  2016-08-30  724  		copy_user_overflow(sz, n);
7a3d9b0f Jan Beulich     2013-10-21  725  	else
0d025d27 Josh Poimboeuf  2016-08-30  726  		__bad_copy_user();
7a3d9b0f Jan Beulich     2013-10-21  727  
7a3d9b0f Jan Beulich     2013-10-21  728  	return n;
7a3d9b0f Jan Beulich     2013-10-21  729  }
7a3d9b0f Jan Beulich     2013-10-21  730  

:::::: The code at line 722 was first introduced by commit
:::::: 7a3d9b0f3abbea957b829cdfff8169872c575642 x86: Unify copy_to_user() and add size checking to it

:::::: TO: Jan Beulich <JBeulich@suse.com>
:::::: CC: Ingo Molnar <mingo@kernel.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 30831 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ethtool: do not vzalloc(0) on registers dump
  2017-02-02 11:31 [PATCH] ethtool: do not vzalloc(0) on registers dump Stanislaw Gruszka
  2017-02-02 12:00 ` kbuild test robot
@ 2017-02-02 12:22 ` kbuild test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kbuild test robot @ 2017-02-02 12:22 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: kbuild-all, netdev, Ben Hutchings

[-- Attachment #1: Type: text/plain, Size: 4742 bytes --]

Hi Stanislaw,

[auto build test WARNING on net-next/master]
[also build test WARNING on v4.10-rc6 next-20170202]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Stanislaw-Gruszka/ethtool-do-not-vzalloc-0-on-registers-dump/20170202-194352
config: cris-etrax-100lx_v2_defconfig (attached as .config)
compiler: cris-linux-gcc (GCC) 6.2.0
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=cris 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   net/core/ethtool.c: In function 'ethtool_get_feature_mask':
   net/core/ethtool.c:311:1: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
   In file included from include/linux/uaccess.h:5:0,
                    from include/net/checksum.h:25,
                    from include/linux/skbuff.h:31,
                    from include/linux/if_ether.h:23,
                    from include/uapi/linux/ethtool.h:18,
                    from include/linux/ethtool.h:17,
                    from net/core/ethtool.c:18:
   net/core/ethtool.c: In function 'ethtool_get_regs':
>> arch/cris/include/asm/uaccess.h:380:10: warning: 'regbuf' may be used uninitialized in this function [-Wmaybe-uninitialized]
      return __copy_user(to, from, n);
             ^~~~~~~~~~~~~~~~~~~~~~~~
   net/core/ethtool.c:1395:8: note: 'regbuf' was declared here
     void *regbuf;
           ^~~~~~

vim +/regbuf +380 arch/cris/include/asm/uaccess.h

eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  364  		memset(to, 0, n);
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  365  		return n;
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  366  	}
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  367  	if (__builtin_constant_p(n))
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  368  		return __constant_copy_from_user(to, from, n);
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  369  	else
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  370  		return __copy_user_zeroing(to, from, n);
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  371  }
^1da177e4 include/asm-cris/uaccess.h      Linus Torvalds 2005-04-16  372  
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  373  static inline size_t copy_to_user(void __user *to, const void *from, size_t n)
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  374  {
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  375  	if (unlikely(!access_ok(VERIFY_WRITE, to, n)))
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  376  		return n;
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  377  	if (__builtin_constant_p(n))
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  378  		return __constant_copy_to_user(to, from, n);
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  379  	else
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18 @380  		return __copy_user(to, from, n);
eb47e0293 arch/cris/include/asm/uaccess.h Al Viro        2016-08-18  381  }
^1da177e4 include/asm-cris/uaccess.h      Linus Torvalds 2005-04-16  382  
^1da177e4 include/asm-cris/uaccess.h      Linus Torvalds 2005-04-16  383  /* We let the __ versions of copy_from/to_user inline, because they're often
^1da177e4 include/asm-cris/uaccess.h      Linus Torvalds 2005-04-16  384   * used in fast paths and have only a small space overhead.
^1da177e4 include/asm-cris/uaccess.h      Linus Torvalds 2005-04-16  385   */
^1da177e4 include/asm-cris/uaccess.h      Linus Torvalds 2005-04-16  386  
d9b5444ee include/asm-cris/uaccess.h      Adrian Bunk    2005-11-07  387  static inline unsigned long
07f2402b4 include/asm-cris/uaccess.h      Jesper Nilsson 2008-03-04  388  __generic_copy_from_user_nocheck(void *to, const void __user *from,

:::::: The code at line 380 was first introduced by commit
:::::: eb47e0293baaa3044022059f1fa9ff474bfe35cb cris: buggered copy_from_user/copy_to_user/clear_user

:::::: TO: Al Viro <viro@zeniv.linux.org.uk>
:::::: CC: Al Viro <viro@zeniv.linux.org.uk>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 8448 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-02 12:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-02 11:31 [PATCH] ethtool: do not vzalloc(0) on registers dump Stanislaw Gruszka
2017-02-02 12:00 ` kbuild test robot
2017-02-02 12:22 ` kbuild test robot

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.