All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: bonding: Use strscpy() instead of manually-truncated strncpy()
@ 2021-06-02 18:11 Kees Cook
  2021-06-02 19:46 ` Rao Shoaib
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2021-06-02 18:11 UTC (permalink / raw)
  To: Jay Vosburgh
  Cc: Kees Cook, kernel test robot, Veaceslav Falico, Andy Gospodarek,
	David S. Miller, Jakub Kicinski, linux-kernel, netdev,
	linux-hardening

Silence this warning by just using strscpy() 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);
         |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/lkml/202102150705.fdR6obB0-lkp@intel.com
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/bonding/bond_main.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index c5a646d06102..ecfc48f2d0d0 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -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(params->primary, primary, sizeof(params->primary));
 
 	memcpy(params->arp_targets, arp_target, sizeof(arp_target));
 
-- 
2.25.1


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

end of thread, other threads:[~2021-06-02 20:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 18:11 [PATCH] net: bonding: Use strscpy() instead of manually-truncated strncpy() Kees Cook
2021-06-02 19:46 ` Rao Shoaib
2021-06-02 20:02   ` Kees Cook

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.