All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] isdnloop: NUL-terminate strings from userspace
@ 2014-04-01 10:08 Vegard Nossum
  2014-04-01 10:30 ` Hannes Frederic Sowa
  2014-04-01 11:23 ` [PATCH] isdnloop: NUL-terminate strings from userspace YOSHIFUJI Hideaki
  0 siblings, 2 replies; 14+ messages in thread
From: Vegard Nossum @ 2014-04-01 10:08 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Vegard Nossum, Dan Carpenter, David S. Miller, stable

Both the in-kernel and BSD strlcpy() require that the source string is
NUL terminated. We could use strncpy() + explicitly terminate the result,
but this relies on src and dest having the same size, so the safest thing
to do seems to explicitly terminate the source string before doing the
strlcpy().

Fixes: f9a23c84486ed35 ("isdnloop: use strlcpy() instead of strcpy()")
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: stable@vger.kernel.org
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
---
 drivers/isdn/isdnloop/isdnloop.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
index 02125e6..50cd348 100644
--- a/drivers/isdn/isdnloop/isdnloop.c
+++ b/drivers/isdn/isdnloop/isdnloop.c
@@ -1070,6 +1070,14 @@ isdnloop_start(isdnloop_card *card, isdnloop_sdef *sdefp)
 		return -EBUSY;
 	if (copy_from_user((char *) &sdef, (char *) sdefp, sizeof(sdef)))
 		return -EFAULT;
+
+	/*
+	 * Null terminate strings from userspace so we don't have to worry
+	 * about this later on.
+	 */
+	for (i = 0; i < 3; i++)
+		sdef.num[i][sizeof(sdef.num[0]) - 1] = '\0';
+
 	spin_lock_irqsave(&card->isdnloop_lock, flags);
 	switch (sdef.ptype) {
 	case ISDN_PTYPE_EURO:
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-04-15 10:38 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-01 10:08 [PATCH] isdnloop: NUL-terminate strings from userspace Vegard Nossum
2014-04-01 10:30 ` Hannes Frederic Sowa
2014-04-01 10:46   ` Vegard Nossum
2014-04-01 11:02     ` Hannes Frederic Sowa
2014-04-01 12:35       ` Dan Carpenter
2014-04-01 20:18         ` David Miller
2014-04-02  3:48           ` [PATCH] isdnloop: Validate NUL-terminated strings from user YOSHIFUJI Hideaki
2014-04-03 15:27             ` David Miller
2014-04-02  8:47           ` [patch 1/2] lib/string.c: use the name "C-string" in comments Dan Carpenter
2014-04-02  8:47           ` [patch 2/2] lib/string.c: strlcpy() might read too far Dan Carpenter
2014-04-14 21:46             ` Andrew Morton
2014-04-15 10:38               ` Dan Carpenter
2014-04-14 22:21             ` Dave Jones
2014-04-01 11:23 ` [PATCH] isdnloop: NUL-terminate strings from userspace YOSHIFUJI Hideaki

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.