core: dev: don't call BUG() on bad input
Subsystems (2)
PATCH v2 1/1 core: dev: don't call BUG() on bad input
alloc_netdev() may be called with too long name (more that IFNAMSIZ bytes). Currently this leads to BUG(). Other insane inputs (bad txqs, rxqs) and even OOM don't lead to BUG(). Made alloc_netdev() return NULL, like on other errors.
---
Compile tested.
v2 - fixed checkpatch warning - space before "\n".
net/core/dev.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
net/core/dev.c +4 -1
@@ -5761,7 +5761,10 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,size_t alloc_size;struct net_device *p; -BUG_ON (strlen (name) >=sizeof (dev->name)); +if (strnlen (name,sizeof (dev->name)) >=sizeof (dev->name)) { +pr_err ("alloc_netdev: Too long device name\n" ); +return NULL ; + }if (txqs <1 ) { pr_err("alloc_netdev: Unable to allocate device "
Signature · 1 line
1.7.0.4
Quoted 8 lines · Vasiliy Kulikov
alloc_netdev()may be called with too long name (more that IFNAMSIZ bytes). Currently this leads toBUG(). Other insane inputs (bad txqs, rxqs) and even OOM don't lead toBUG(). Madealloc_netdev()return NULL, like on other errors.
net/core/dev.c struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, · line 5767
Quoted 8 lines
net/core/dev.c +4
-1@@ -5761,7 +5761,10 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, size_t alloc_size; struct net_device *p; - BUG_ON(strlen(name) >= sizeof(dev->name)); + if (strnlen(name, sizeof(dev->name)) >= sizeof(dev->name)) { + pr_err("alloc_netdev: Too long device name\n"); + return NULL; + }
Netdevice name isn't some random junk you get from userspace, so BUG is fine.
Alexey,
Quoted 12 lines · Alexey Dobriyan
Quoted 11 lines · Vasiliy Kulikov
alloc_netdev()may be called with too long name (more that IFNAMSIZ bytes). Currently this leads toBUG(). Other insane inputs (bad txqs, rxqs) and even OOM don't lead toBUG(). Madealloc_netdev()return NULL, like on other errors.net/core/dev.c +0
-0@@ -5761,7 +5761,10 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, size_t alloc_size; struct net_device *p;
Quoted 7 lines
net/core/dev.c struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, · line 5767
Quoted 5 lines
net/core/dev.c +4
-1- BUG_ON(strlen(name) >= sizeof(dev->name)); + if (strnlen(name, sizeof(dev->name)) >= sizeof(dev->name)) { + pr_err("alloc_netdev: Too long device name\n"); + return NULL; + }Netdevice name isn't some random junk you get from userspace, so BUG is fine.
It IS for bluetooth, see net/bluetooth/bnep/core.c: bnep_add_connection() and net/bluetooth/bnep/sock.c: bnep_sock_ioctl().
And txqs, txqs? Then why do not BUG() on bad txqs too? Why so insonsistent? BUG() should be called in some critical situation, net device creation is probably not such a thing.
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Am 14.02.2011 16:16, schrieb Alexey Dobriyan:
Quoted 12 lines · Vasiliy Kulikov
Quoted 11 lines
alloc_netdev()may be called with too long name (more that IFNAMSIZ bytes). Currently this leads toBUG(). Other insane inputs (bad txqs, rxqs) and even OOM don't lead toBUG(). Madealloc_netdev()return NULL, like on other errors.net/core/dev.c +0
-0@@ -5761,7 +5761,10 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,size_t alloc_size;struct net_device *p;
Quoted 7 lines
net/core/dev.c struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, · line 5767
Quoted 5 lines
net/core/dev.c +4
-1-BUG_ON (strlen (name) >=sizeof (dev->name)); +if (strnlen (name,sizeof (dev->name)) >=sizeof (dev->name)) { +pr_err ("alloc_netdev: Too long device name\n" ); +return NULL ; + }Netdevice name isn't some random junk you get from userspace, so BUG is fine.
I agree, misuse of kernel APIs is not something we need to catch verbosely.
David Miller
maintainerFrom: Vasiliy Kulikov <[email protected]>
Date: Mon, 14 Feb 2011 18:23:10 +0300
Quoted 5 lines · Alexey Dobriyan
Quoted 1 line
Netdevice name isn't some random junk you get from userspace, so BUG is fine.
It IS for bluetooth, see
net/bluetooth/bnep/core.c:bnep_add_connection()andnet/bluetooth/bnep/sock.c:bnep_sock_ioctl().
If bluetooth wants to allow something so foolish, then it's bluetooth's responsibility to sanity check the arguments before blinding passing them into kernel APIs which expect sane inputs.
I'm not applying this.
Quoted 6 lines · David Miller
From: Vasiliy Kulikov <[email protected]>
Date: Mon, 14 Feb 2011 18:23:10 +0300Quoted 3 lines · Alexey Dobriyan
Quoted 1 line
Netdevice name isn't some random junk you get from userspace, so BUG is fine.
Quoted 9 lines
Quoted 2 lines
It IS for bluetooth, see
net/bluetooth/bnep/core.c:bnep_add_connection()andnet/bluetooth/bnep/sock.c:bnep_sock_ioctl().If bluetooth wants to allow something so foolish, then it's bluetooth's responsibility to sanity check the arguments before blinding passing them into kernel APIs which expect sane inputs.
I'm not applying this.
Changing to BUG_ON(txqs < 1) and BUG_ON(rxqs < 1) does make sense I think.
Tom
David Miller
maintainerFrom: Tom Herbert <[email protected]>
Date: Mon, 14 Feb 2011 11:33:29 -0800
Quoted 10 lines · David Miller
Quoted 9 lines
From: Vasiliy Kulikov <[email protected]>
Date: Mon, 14 Feb 2011 18:23:10 +0300Quoted 5 lines · Alexey Dobriyan
Quoted 1 line
Netdevice name isn't some random junk you get from userspace, so BUG is fine.
It IS for bluetooth, see
net/bluetooth/bnep/core.c:bnep_add_connection()andnet/bluetooth/bnep/sock.c:bnep_sock_ioctl().
Quoted 8 lines
Quoted 6 lines
If bluetooth wants to allow something so foolish, then it's bluetooth's responsibility to sanity check the arguments before blinding passing them into kernel APIs which expect sane inputs.
I'm not applying this.
Changing to
BUG_ON(txqs < 1)andBUG_ON(rxqs < 1)does make sense I think.
Sure.