lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250619144934348-KObAuS33g0yI9ulIjMjE@zte.com.cn>
Date: Thu, 19 Jun 2025 14:49:34 +0800 (CST)
From: <jiang.peng9@....com.cn>
To: <pabeni@...hat.com>
Cc: <davem@...emloft.net>, <edumazet@...gle.com>, <kuba@...nel.org>,
        <horms@...nel.org>, <jiang.peng9@....com.cn>, <jiri@...nulli.us>,
        <linux@...blig.org>, <oscmaes92@...il.com>, <netdev@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>, <xu.xin16@....com.cn>,
        <yang.yang29@....com.cn>
Subject: [PATCH net] net: vlan: fix format-truncation warnings in
 register_vlan_device

From: Peng Jiang <jiang.peng9@....com.cn>

Building with W=1 triggers format-truncation warnings in the
register_vlan_device function when compiled with GCC 12.3.0.
These warnings occur due to the use of %i and %.4i format
specifiers with a buffer size that might be insufficient
for the formatted string, potentially causing truncation.

The original warning trace:
net/8021q/vlan.c:247:17: note: 'snprintf' output between 3 and 22 bytes into a destination of size 16
247 | snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);

Signed-off-by: Peng Jiang <jiang.peng9@....com.cn>
---
 net/8021q/vlan.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 06908e37c3d9..f2c17035f625 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -217,7 +217,7 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
        struct vlan_dev_priv *vlan;
        struct net *net = dev_net(real_dev);
        struct vlan_net *vn = net_generic(net, vlan_net_id);
-       char name[IFNAMSIZ];
+       char name[IFNAMSIZ + 6]; /* plus extra 6 bytes for vlan_id */
        int err;
 
        if (vlan_id >= VLAN_VID_MASK)
@@ -232,26 +232,26 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
        switch (vn->name_type) {
        case VLAN_NAME_TYPE_RAW_PLUS_VID:
                /* name will look like:  eth1.0005 */
-               snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
+               snprintf(name, sizeof(name), "%s.%.4i", real_dev->name, vlan_id);
                break;
        case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
                /* Put our vlan.VID in the name.
                 * Name will look like:  vlan5
                 */
-               snprintf(name, IFNAMSIZ, "vlan%i", vlan_id);
+               snprintf(name, sizeof(name), "vlan%i", vlan_id);
                break;
        case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
                /* Put our vlan.VID in the name.
                 * Name will look like:  eth0.5
                 */
-               snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
+               snprintf(name, sizeof(name), "%s.%i", real_dev->name, vlan_id);
                break;
        case VLAN_NAME_TYPE_PLUS_VID:
                /* Put our vlan.VID in the name.
                 * Name will look like:  vlan0005
                 */
        default:
-               snprintf(name, IFNAMSIZ, "vlan%.4i", vlan_id);
+               snprintf(name, sizeof(name), "vlan%.4i", vlan_id);
        }
 
        new_dev = alloc_netdev(sizeof(struct vlan_dev_priv), name,
-- 
2.25.1
<div class="zcontentRow"><p>From: Peng Jiang &lt;jiang.peng9@....com.cn&gt;<br></p><p><br></p><p>Building with W=1 triggers format-truncation warnings in the</p><p>register_vlan_device function when compiled with GCC 12.3.0.</p><p>These warnings occur due to the use of %i and %.4i format</p><p>specifiers with a buffer size that might be insufficient</p><p>for the formatted string, potentially causing truncation.</p><p><br></p><p>The original warning trace:</p><p>net/8021q/vlan.c:247:17: note: 'snprintf' output between 3 and 22 bytes into a destination of size 16</p><p>247 | snprintf(name, IFNAMSIZ, "%s.%i", real_dev-&gt;name, vlan_id);</p><p><br></p><p>Signed-off-by: Peng Jiang &lt;jiang.peng9@....com.cn&gt;</p><p>---</p><p>&nbsp;net/8021q/vlan.c | 10 +++++-----</p><p>&nbsp;1 file changed, 5 insertions(+), 5 deletions(-)</p><p><br></p><p>diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c</p><p>index 06908e37c3d9..f2c17035f625 100644</p><p>--- a/net/8021q/vlan.c</p><p>+++ b/net/8021q/vlan.c</p><p>@@ -217,7 +217,7 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; struct vlan_dev_priv *vlan;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; struct net *net = dev_net(real_dev);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; struct vlan_net *vn = net_generic(net, vlan_net_id);</p><p>-&nbsp; &nbsp; &nbsp; &nbsp;char name[IFNAMSIZ];</p><p>+&nbsp; &nbsp; &nbsp; &nbsp;char name[IFNAMSIZ + 6]; /* plus extra 6 bytes for vlan_id */</p><p>&nbsp; &nbsp; &nbsp; &nbsp; int err;</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (vlan_id &gt;= VLAN_VID_MASK)</p><p>@@ -232,26 +232,26 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; switch (vn-&gt;name_type) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; case VLAN_NAME_TYPE_RAW_PLUS_VID:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* name will look like:&nbsp; eth1.0005 */</p><p>-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev-&gt;name, vlan_id);</p><p>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;snprintf(name, sizeof(name), "%s.%.4i", real_dev-&gt;name, vlan_id);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Put our vlan.VID in the name.</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Name will look like:&nbsp; vlan5</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</p><p>-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;snprintf(name, IFNAMSIZ, "vlan%i", vlan_id);</p><p>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;snprintf(name, sizeof(name), "vlan%i", vlan_id);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Put our vlan.VID in the name.</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Name will look like:&nbsp; eth0.5</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</p><p>-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;snprintf(name, IFNAMSIZ, "%s.%i", real_dev-&gt;name, vlan_id);</p><p>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;snprintf(name, sizeof(name), "%s.%i", real_dev-&gt;name, vlan_id);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; case VLAN_NAME_TYPE_PLUS_VID:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Put our vlan.VID in the name.</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Name will look like:&nbsp; vlan0005</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</p><p>&nbsp; &nbsp; &nbsp; &nbsp; default:</p><p>-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;snprintf(name, IFNAMSIZ, "vlan%.4i", vlan_id);</p><p>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;snprintf(name, sizeof(name), "vlan%.4i", vlan_id);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; new_dev = alloc_netdev(sizeof(struct vlan_dev_priv), name,</p><p>--&nbsp;</p><p>2.25.1</p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p></div>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ