* [PATCH v3] net: bonding: Use strscpy_pad() instead of manually-truncated strncpy()
@ 2021-06-02 20:58 Kees Cook
2021-06-03 21:30 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2021-06-02 20:58 UTC (permalink / raw)
To: Jay Vosburgh
Cc: Kees Cook, kernel test robot, Jay Vosburgh, Veaceslav Falico,
Andy Gospodarek, David S. Miller, Jakub Kicinski, linux-kernel,
netdev, linux-hardening
Silence this warning by using strscpy_pad() directly:
drivers/net/bonding/bond_main.c:4877:3: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
4877 | strncpy(params->primary, primary, IFNAMSIZ);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Additionally replace other strncpy() uses, as it is considered deprecated:
https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/lkml/202102150705.fdR6obB0-lkp@intel.com
Acked-by: Jay Vosburgh <jay.vosburgh@canonical.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
v3: - other files in drivers/net/bonding/ too!
v2: https://lore.kernel.org/lkml/20210602203138.4082470-1-keescook@chromium.org
v1: https://lore.kernel.org/lkml/20210602181133.3326856-1-keescook@chromium.org
---
drivers/net/bonding/bond_main.c | 8 +++-----
drivers/net/bonding/bond_options.c | 3 +--
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index c5a646d06102..e9cb716ad849 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -620,7 +620,7 @@ static int bond_check_dev_link(struct bonding *bond,
*/
/* Yes, the mii is overlaid on the ifreq.ifr_ifru */
- strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
+ strscpy_pad(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
mii = if_mii(&ifr);
if (ioctl(slave_dev, &ifr, SIOCGMIIPHY) == 0) {
mii->reg_num = MII_BMSR;
@@ -5329,10 +5329,8 @@ static int bond_check_params(struct bond_params *params)
(struct reciprocal_value) { 0 };
}
- if (primary) {
- strncpy(params->primary, primary, IFNAMSIZ);
- params->primary[IFNAMSIZ - 1] = 0;
- }
+ if (primary)
+ strscpy_pad(params->primary, primary, sizeof(params->primary));
memcpy(params->arp_targets, arp_target, sizeof(arp_target));
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index c9d3604ae129..81c039531e66 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -1206,8 +1206,7 @@ static int bond_option_primary_set(struct bonding *bond,
RCU_INIT_POINTER(bond->primary_slave, NULL);
bond_select_active_slave(bond);
}
- strncpy(bond->params.primary, primary, IFNAMSIZ);
- bond->params.primary[IFNAMSIZ - 1] = 0;
+ strscpy_pad(bond->params.primary, primary, IFNAMSIZ);
netdev_dbg(bond->dev, "Recording %s as primary, but it has not been enslaved yet\n",
primary);
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] net: bonding: Use strscpy_pad() instead of manually-truncated strncpy()
2021-06-02 20:58 [PATCH v3] net: bonding: Use strscpy_pad() instead of manually-truncated strncpy() Kees Cook
@ 2021-06-03 21:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-06-03 21:30 UTC (permalink / raw)
To: Kees Cook
Cc: jay.vosburgh, lkp, j.vosburgh, vfalico, andy, davem, kuba,
linux-kernel, netdev, linux-hardening
Hello:
This patch was applied to netdev/net-next.git (refs/heads/master):
On Wed, 2 Jun 2021 13:58:20 -0700 you wrote:
> Silence this warning by using strscpy_pad() directly:
>
> drivers/net/bonding/bond_main.c:4877:3: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
> 4877 | strncpy(params->primary, primary, IFNAMSIZ);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Additionally replace other strncpy() uses, as it is considered deprecated:
> https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
>
> [...]
Here is the summary with links:
- [v3] net: bonding: Use strscpy_pad() instead of manually-truncated strncpy()
https://git.kernel.org/netdev/net-next/c/43902070fb7b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-03 21:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 20:58 [PATCH v3] net: bonding: Use strscpy_pad() instead of manually-truncated strncpy() Kees Cook
2021-06-03 21:30 ` patchwork-bot+netdevbpf
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.