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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdW3Wruazi=A+0HcWu8juzp+NdXPt7rtxtyhYjRLnD3QCw@mail.gmail.com>
Date:   Thu, 1 Sep 2022 21:14:26 +0200
From:   Geert Uytterhoeven <geert@...ux-m68k.org>
To:     Kees Cook <keescook@...omium.org>
Cc:     Wolfram Sang <wsa+renesas@...g-engineering.com>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Guenter Roeck <linux@...ck-us.net>,
        Paolo Abeni <pabeni@...hat.com>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        linux-hardening@...r.kernel.org,
        Linus Torvalds <torvalds@...ux-foundation.org>
Subject: Re: [PATCH] string: Introduce strtomem() and strtomem_pad()

Hi Kees,

On Thu, Sep 1, 2022 at 8:35 PM Kees Cook <keescook@...omium.org> wrote:
> On Thu, Sep 01, 2022 at 10:39:19AM +0200, Geert Uytterhoeven wrote:
> > > --- a/include/linux/string.h
> > > +++ b/include/linux/string.h
> > > @@ -260,6 +260,49 @@ static inline const char *kbasename(const char *path)
> > >  void memcpy_and_pad(void *dest, size_t dest_len, const void *src, size_t count,
> > >                     int pad);
> > >
> > > +/**
> > > + * strtomem_pad - Copy NUL-terminated string to non-NUL-terminated buffer
> > > + *
> > > + * @dest: Pointer of destination character array (marked as __nonstring)
> > > + * @src: Pointer to NUL-terminated string
> > > + * @pad: Padding character to fill any remaining bytes of @dest after copy
> > > + *
> > > + * This is a replacement for strncpy() uses where the destination is not
> > > + * a NUL-terminated string, but with bounds checking on the source size, and
> > > + * an explicit padding character. If padding is not required, use strtomem().
> > > + *
> > > + * Note that the size of @dest is not an argument, as the length of @dest
> > > + * must be discoverable by the compiler.
> > > + */
> > > +#define strtomem_pad(dest, src, pad)   do {                            \
> > > +       const size_t _dest_len = __builtin_object_size(dest, 1);        \
> > > +                                                                       \
> > > +       BUILD_BUG_ON(!__builtin_constant_p(_dest_len) ||                \
> > > +                    _dest_len == (size_t)-1);                          \
> >
> > I think you want to include __must_be_array(dest) here.
>
> I didn't do that for the cases where we may be writing to non-array
> destinations (e.g. see the cast from u64 in the strncpy use in
> tools/perf/arch/x86/util/intel-pt.c). Since what we need to know is the
> object size, it does not strictly need to be an array.

IC.  That does mean we cannot catch silly mistakes where the
caller passes a pointer instead of the address of an array?

> > > +       for (int i = 2; i < sizeof(wrap.output); i++)
> >
> > unsigned int i (everywhere)
>
> I guess, but why? This could even be u8.

sizeof() is unsigned, so using int may cause signed/unsigned comparison
warnings.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ