Thread (7 messages) flat view 7 messages, 5 authors, 2011-02-14

Re: [PATCH v2] core: dev: don't call BUG() on bad input

From: Alexey Dobriyan <hidden>
Date: 2011-02-14 15:16:04
Also in: lkml

On Mon, Feb 14, 2011 at 4:42 PM, Vasiliy Kulikov [off-list ref] wrote:
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.
quoted hunk ↗ jump to hunk
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help