From: Kees Cook <keescook@chromium.org>
To: Jay Vosburgh <jay.vosburgh@canonical.com>
Cc: kernel test robot <lkp@intel.com>,
Veaceslav Falico <vfalico@gmail.com>,
Andy Gospodarek <andy@greyhouse.net>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] net: bonding: Use strscpy() instead of manually-truncated strncpy()
Date: Wed, 2 Jun 2021 13:52:59 -0700 [thread overview]
Message-ID: <202106021352.484D660@keescook> (raw)
In-Reply-To: <7214.1622666840@famine>
On Wed, Jun 02, 2021 at 01:47:20PM -0700, Jay Vosburgh wrote:
> Kees Cook <keescook@chromium.org> wrote:
>
> >Silence this warning by just 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
> >Signed-off-by: Kees Cook <keescook@chromium.org>
>
> There's one more "strncpy(...); primary[IFNAMSIZ - 1] = 0;" set
> in bond_options.c:bond_option_primary_set(), doesn't it also generate
> this warning?
Gah, I was looking only in the same file not the whole directory. :)
v3 on the way!
>
> Either way, the change looks good to me.
Thanks!
>
> Acked-by: Jay Vosburgh <jay.vosburgh@canonical.com>
>
> -J
>
>
> >---
> >v2:
> > - switch to strscpy_pad() and replace earlier strncpy() too
> >v1: https://lore.kernel.org/lkml/20210602181133.3326856-1-keescook@chromium.org
> >---
> > drivers/net/bonding/bond_main.c | 8 +++-----
> > 1 file changed, 3 insertions(+), 5 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));
> >
> >--
> >2.25.1
>
> ---
> -Jay Vosburgh, jay.vosburgh@canonical.com
--
Kees Cook
prev parent reply other threads:[~2021-06-02 20:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-02 20:31 [PATCH v2] net: bonding: Use strscpy() instead of manually-truncated strncpy() Kees Cook
2021-06-02 20:47 ` Jay Vosburgh
2021-06-02 20:52 ` Kees Cook [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202106021352.484D660@keescook \
--to=keescook@chromium.org \
--cc=andy@greyhouse.net \
--cc=davem@davemloft.net \
--cc=jay.vosburgh@canonical.com \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=netdev@vger.kernel.org \
--cc=vfalico@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).