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-prev] [day] [month] [year] [list]
Message-ID: <CAFhGd8oLmKA7L_YDps+aYLVJTPxWNaKKTgCX3Ji=ZLoGMv7a6g@mail.gmail.com>
Date:   Sat, 30 Sep 2023 10:08:34 +0900
From:   Justin Stitt <justinstitt@...gle.com>
To:     Kees Cook <keescook@...omium.org>
Cc:     Miguel Ojeda <miguel.ojeda.sandonis@...il.com>,
        kernel test robot <lkp@...el.com>,
        Alasdair Kergon <agk@...hat.com>,
        Mike Snitzer <snitzer@...nel.org>,
        oe-kbuild-all@...ts.linux.dev, linux-kernel@...r.kernel.org,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Luc Van Oostenryck <luc.vanoostenryck@...il.com>
Subject: Re: drivers/md/dm-cache-metadata.c:1705:9: warning: 'strncpy'
 specified bound 16 equals destination size

On Sat, Sep 30, 2023 at 2:49 AM Kees Cook <keescook@...omium.org> wrote:
>
> On Thu, Sep 28, 2023 at 11:36:46AM +0200, Miguel Ojeda wrote:
> > On Thu, Sep 28, 2023 at 12:24 AM kernel test robot <lkp@...el.com> wrote:
> > >
> > >    In function 'write_hints',
> > >        inlined from 'dm_cache_write_hints' at drivers/md/dm-cache-metadata.c:1729:6:
> > > >> drivers/md/dm-cache-metadata.c:1705:9: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
> > >     1705 |         strncpy(cmd->policy_name, policy_name, sizeof(cmd->policy_name));
> > >          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > This looks fine given the check above it. In any case, since it
> > appears the code wants to terminate the string, this should use
> > `strscpy*()`, right?
>
> I agree. I can't tell if _pad is needed though. I think struct
> dm_cache_metadata is only used internally? And I see at least the
> initial allocation is zeroed:
>
>         cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
>
> Regardless, for background,
>
> struct has:
>         char policy_name[CACHE_POLICY_NAME_SIZE];
>
> code does:
>         const char *policy_name = dm_cache_policy_get_name(policy);
>
>         if (!policy_name[0] ||
>             (strlen(policy_name) > sizeof(cmd->policy_name) - 1))
>                 return -EINVAL;
>
>         strncpy(cmd->policy_name, policy_name, sizeof(cmd->policy_name));
>
>
> Justin, can you add this to your queue (if it's not already there)?

I sent a patch out earlier this week [1].

The line # on the diff v.s the warning is off though. I suspect I may
need a rebase if it doesn't apply clean.

>
> -Kees
>
> --
> Kees Cook

[1]: https://lore.kernel.org/all/20230925-strncpy-drivers-md-dm-cache-metadata-c-v1-1-4b75c7db0cfe@google.com/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ