From: David S. Miller Date: Fri, 24 Mar 2006 06:54:18 +0000 (-0800) Subject: [PATCH] NET: Ensure device name passed to SO_BINDTODEVICE is NULL terminated. X-Git-Tag: v2.6.15.7~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=107d25ba4fcacf8e29bcad240b95fd9ef7314dac;p=thirdparty%2Fkernel%2Fstable.git [PATCH] NET: Ensure device name passed to SO_BINDTODEVICE is NULL terminated. The user can pass us arbitrary garbage so we should ensure the string they give us is null terminated before we pass it on to dev_get_by_index() et al. Found by Solar Designer. Signed-off-by: David S. Miller Signed-off-by: Chris Wright Signed-off-by: Greg Kroah-Hartman --- diff --git a/net/core/sock.c b/net/core/sock.c index 13cc3be4f056f..2a3e235bd1bc5 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -403,8 +403,9 @@ set_rcvbuf: if (!valbool) { sk->sk_bound_dev_if = 0; } else { - if (optlen > IFNAMSIZ) - optlen = IFNAMSIZ; + if (optlen > IFNAMSIZ - 1) + optlen = IFNAMSIZ - 1; + memset(devname, 0, sizeof(devname)); if (copy_from_user(devname, optval, optlen)) { ret = -EFAULT; break;