datapath: Always null-terminate network device name in create_dp().
authorBen Pfaff <blp@nicira.com>
Tue, 27 Apr 2010 17:43:24 +0000 (10:43 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 27 Apr 2010 17:43:24 +0000 (10:43 -0700)
strncpy() does not null-terminate its output buffer if the source string's
length is at least as large as its 'count' argument.  We know that the
source and destination buffers are the same size and that the source buffer
is null-terminated, so just use strcpy().

This fixes a kernel BUG message that often occurred when strlen(devname)
was exactly IFNAMSIZ-1.  In such a case, if
internal_dev_port.devname[IFNAMSIZ-1] happened to be nonzero, it would
eventually fail the following check in alloc_netdev_mq():
BUG_ON(strlen(name) >= sizeof(dev->name));

Bug #2722.

datapath/datapath.c

index be16044d5a44a60ab6a751273187827aedbee8cc..e9590f75fdde32b61b12b4563cca123bc85f4596 100644 (file)
@@ -246,7 +246,8 @@ static int create_dp(int dp_idx, const char __user *devnamep)
                goto err_free_dp;
 
        /* Set up our datapath device. */
-       strncpy(internal_dev_port.devname, devname, IFNAMSIZ - 1);
+       BUILD_BUG_ON(sizeof(internal_dev_port.devname) != sizeof(devname));
+       strcpy(internal_dev_port.devname, devname);
        internal_dev_port.flags = ODP_PORT_INTERNAL;
        err = new_dp_port(dp, &internal_dev_port, ODPP_LOCAL);
        if (err) {