]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: netdevsim: Use scnprintf() for avoiding potential buffer overflow
authorTakashi Iwai <tiwai@suse.de>
Sun, 15 Mar 2020 09:35:03 +0000 (10:35 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 16 Mar 2020 00:06:22 +0000 (17:06 -0700)
Since snprintf() returns the would-be-output size instead of the
actual output size, the succeeding calls may go beyond the given
buffer limit.  Fix it by replacing with scnprintf().

Cc: "David S . Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/netdevsim/ipsec.c

index e27fc1a4516dfaa1ad87819b9b7b0cc7f5adde47..3811f1bde84e709a132d378a2411b67616d25290 100644 (file)
@@ -29,9 +29,9 @@ static ssize_t nsim_dbg_netdev_ops_read(struct file *filp,
                return -ENOMEM;
 
        p = buf;
-       p += snprintf(p, bufsize - (p - buf),
-                     "SA count=%u tx=%u\n",
-                     ipsec->count, ipsec->tx);
+       p += scnprintf(p, bufsize - (p - buf),
+                      "SA count=%u tx=%u\n",
+                      ipsec->count, ipsec->tx);
 
        for (i = 0; i < NSIM_IPSEC_MAX_SA_COUNT; i++) {
                struct nsim_sa *sap = &ipsec->sa[i];
@@ -39,18 +39,18 @@ static ssize_t nsim_dbg_netdev_ops_read(struct file *filp,
                if (!sap->used)
                        continue;
 
-               p += snprintf(p, bufsize - (p - buf),
-                             "sa[%i] %cx ipaddr=0x%08x %08x %08x %08x\n",
-                             i, (sap->rx ? 'r' : 't'), sap->ipaddr[0],
-                             sap->ipaddr[1], sap->ipaddr[2], sap->ipaddr[3]);
-               p += snprintf(p, bufsize - (p - buf),
-                             "sa[%i]    spi=0x%08x proto=0x%x salt=0x%08x crypt=%d\n",
-                             i, be32_to_cpu(sap->xs->id.spi),
-                             sap->xs->id.proto, sap->salt, sap->crypt);
-               p += snprintf(p, bufsize - (p - buf),
-                             "sa[%i]    key=0x%08x %08x %08x %08x\n",
-                             i, sap->key[0], sap->key[1],
-                             sap->key[2], sap->key[3]);
+               p += scnprintf(p, bufsize - (p - buf),
+                              "sa[%i] %cx ipaddr=0x%08x %08x %08x %08x\n",
+                              i, (sap->rx ? 'r' : 't'), sap->ipaddr[0],
+                              sap->ipaddr[1], sap->ipaddr[2], sap->ipaddr[3]);
+               p += scnprintf(p, bufsize - (p - buf),
+                              "sa[%i]    spi=0x%08x proto=0x%x salt=0x%08x crypt=%d\n",
+                              i, be32_to_cpu(sap->xs->id.spi),
+                              sap->xs->id.proto, sap->salt, sap->crypt);
+               p += scnprintf(p, bufsize - (p - buf),
+                              "sa[%i]    key=0x%08x %08x %08x %08x\n",
+                              i, sap->key[0], sap->key[1],
+                              sap->key[2], sap->key[3]);
        }
 
        len = simple_read_from_buffer(buffer, count, ppos, buf, p - buf);