* [PATCH] mISDN: make sure device name is NUL terminated
@ 2019-05-22 8:45 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2019-05-22 8:45 UTC (permalink / raw)
To: Karsten Keil
Cc: David S. Miller, zhong jiang, Deepa Dinamani, Tetsuo Handa,
netdev, kernel-janitors
The user can change the device_name with the IMSETDEVNAME ioctl, but we
need to ensure that the user's name is NUL terminated. Otherwise it
could result in a buffer overflow when we copy the name back to the user
with IMGETDEVINFO ioctl.
I also changed two strcpy() calls which handle the name to strscpy().
Hopefully, there aren't any other ways to create a too long name, but
it's nice to do this as a kernel hardening measure.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/isdn/mISDN/socket.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
index a14e35d40538..84e1d4c2db66 100644
--- a/drivers/isdn/mISDN/socket.c
+++ b/drivers/isdn/mISDN/socket.c
@@ -393,7 +393,7 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
memcpy(di.channelmap, dev->channelmap,
sizeof(di.channelmap));
di.nrbchan = dev->nrbchan;
- strcpy(di.name, dev_name(&dev->dev));
+ strscpy(di.name, dev_name(&dev->dev), sizeof(di.name));
if (copy_to_user((void __user *)arg, &di, sizeof(di)))
err = -EFAULT;
} else
@@ -676,7 +676,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
memcpy(di.channelmap, dev->channelmap,
sizeof(di.channelmap));
di.nrbchan = dev->nrbchan;
- strcpy(di.name, dev_name(&dev->dev));
+ strscpy(di.name, dev_name(&dev->dev), sizeof(di.name));
if (copy_to_user((void __user *)arg, &di, sizeof(di)))
err = -EFAULT;
} else
@@ -690,6 +690,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
err = -EFAULT;
break;
}
+ dn.name[sizeof(dn.name) - 1] = '\0';
dev = get_mdevice(dn.id);
if (dev)
err = device_rename(&dev->dev, dn.name);
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] mISDN: make sure device name is NUL terminated
@ 2019-05-22 8:45 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2019-05-22 8:45 UTC (permalink / raw)
To: Karsten Keil
Cc: David S. Miller, zhong jiang, Deepa Dinamani, Tetsuo Handa,
netdev, kernel-janitors
The user can change the device_name with the IMSETDEVNAME ioctl, but we
need to ensure that the user's name is NUL terminated. Otherwise it
could result in a buffer overflow when we copy the name back to the user
with IMGETDEVINFO ioctl.
I also changed two strcpy() calls which handle the name to strscpy().
Hopefully, there aren't any other ways to create a too long name, but
it's nice to do this as a kernel hardening measure.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/isdn/mISDN/socket.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
index a14e35d40538..84e1d4c2db66 100644
--- a/drivers/isdn/mISDN/socket.c
+++ b/drivers/isdn/mISDN/socket.c
@@ -393,7 +393,7 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
memcpy(di.channelmap, dev->channelmap,
sizeof(di.channelmap));
di.nrbchan = dev->nrbchan;
- strcpy(di.name, dev_name(&dev->dev));
+ strscpy(di.name, dev_name(&dev->dev), sizeof(di.name));
if (copy_to_user((void __user *)arg, &di, sizeof(di)))
err = -EFAULT;
} else
@@ -676,7 +676,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
memcpy(di.channelmap, dev->channelmap,
sizeof(di.channelmap));
di.nrbchan = dev->nrbchan;
- strcpy(di.name, dev_name(&dev->dev));
+ strscpy(di.name, dev_name(&dev->dev), sizeof(di.name));
if (copy_to_user((void __user *)arg, &di, sizeof(di)))
err = -EFAULT;
} else
@@ -690,6 +690,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
err = -EFAULT;
break;
}
+ dn.name[sizeof(dn.name) - 1] = '\0';
dev = get_mdevice(dn.id);
if (dev)
err = device_rename(&dev->dev, dn.name);
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mISDN: make sure device name is NUL terminated
2019-05-22 8:45 ` Dan Carpenter
@ 2019-05-23 0:22 ` David Miller
-1 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-05-23 0:22 UTC (permalink / raw)
To: dan.carpenter
Cc: isdn, zhongjiang, deepa.kernel, penguin-kernel, netdev, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 22 May 2019 11:45:13 +0300
> The user can change the device_name with the IMSETDEVNAME ioctl, but we
> need to ensure that the user's name is NUL terminated. Otherwise it
> could result in a buffer overflow when we copy the name back to the user
> with IMGETDEVINFO ioctl.
>
> I also changed two strcpy() calls which handle the name to strscpy().
> Hopefully, there aren't any other ways to create a too long name, but
> it's nice to do this as a kernel hardening measure.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mISDN: make sure device name is NUL terminated
@ 2019-05-23 0:22 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-05-23 0:22 UTC (permalink / raw)
To: dan.carpenter
Cc: isdn, zhongjiang, deepa.kernel, penguin-kernel, netdev, kernel-janitors
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 22 May 2019 11:45:13 +0300
> The user can change the device_name with the IMSETDEVNAME ioctl, but we
> need to ensure that the user's name is NUL terminated. Otherwise it
> could result in a buffer overflow when we copy the name back to the user
> with IMGETDEVINFO ioctl.
>
> I also changed two strcpy() calls which handle the name to strscpy().
> Hopefully, there aren't any other ways to create a too long name, but
> it's nice to do this as a kernel hardening measure.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-05-23 0:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 8:45 [PATCH] mISDN: make sure device name is NUL terminated Dan Carpenter
2019-05-22 8:45 ` Dan Carpenter
2019-05-23 0:22 ` David Miller
2019-05-23 0:22 ` David Miller
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.