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: <8533a82ace484fe4ab73fccea7dc009b@AcuMS.aculab.com>
Date:   Wed, 5 Oct 2022 13:57:34 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Will Deacon' <will@...nel.org>,
        "xu.panda668@...il.com" <xu.panda668@...il.com>
CC:     "catalin.marinas@....com" <catalin.marinas@....com>,
        "broonie@...nel.org" <broonie@...nel.org>,
        "maz@...nel.org" <maz@...nel.org>,
        "kristina.martsenko@....com" <kristina.martsenko@....com>,
        "vladimir.murzin@....com" <vladimir.murzin@....com>,
        "mark.rutland@....com" <mark.rutland@....com>,
        "ardb@...nel.org" <ardb@...nel.org>,
        "linux-arm-kernel@...ts.infradead.org" 
        <linux-arm-kernel@...ts.infradead.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "cgel.zte@...il.com" <cgel.zte@...il.com>,
        "Xu Panda" <xu.panda@....com.cn>, Zeal Robot <zealci@....com.cn>
Subject: RE: [PATCH linux-next] arm64/idreg: use strscpy() is more robust and
 safer

From: Will Deacon
> Sent: 04 October 2022 12:48
> 
> On Thu, Sep 29, 2022 at 07:29:06AM +0000, xu.panda668@...il.com wrote:
> > From: Xu Panda <xu.panda@....com.cn>
> >
> > The implementation of strscpy() is more robust and safer.
> > That's now the recommended way to copy NUL terminated strings.

In this case the input string isn't NUL terminated....

> >
> > Reported-by: Zeal Robot <zealci@....com.cn>
> > Signed-off-by: Xu Panda <xu.panda@....com.cn>
> > Signed-off-by: Xu Panda <xu.panda668@...il.com>
> > ---
> >  arch/arm64/kernel/idreg-override.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c
> > index 95133765ed29..61bbec7ef62e 100644
> > --- a/arch/arm64/kernel/idreg-override.c
> > +++ b/arch/arm64/kernel/idreg-override.c
> > @@ -246,7 +246,7 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases)
> >                         return;
> >
> >                 len = min(len, ARRAY_SIZE(buf) - 1);
> > -               strncpy(buf, cmdline, len);
> > +               strscpy(buf, cmdline, len);
> >                 buf[len] = 0;
> 
> Aren't we terminating the buffer explicitly here anyway?

I doubt the code was tested.
It is always wrong regardless of the initial value of 'len'.

I think using strscpy() will delete the last character
and always add two '\0'.

On the face of it, that could probably be a memcpy().

But with the checks you don't need any of the length
checks that memcpy() might be gaining.

OTOH, if the code used parameqn() a few lines lower the
entire copy could be removed.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ