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]
Date:   Thu, 14 Feb 2019 08:38:39 -0800
From:   Kees Cook <keescook@...omium.org>
To:     Oleg Nesterov <oleg@...hat.com>
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        Samuel Dionne-Riel <samuel@...nne-riel.com>,
        Richard Weinberger <richard.weinberger@...il.com>,
        LKML <linux-kernel@...r.kernel.org>,
        Graham Christensen <graham@...hamc.com>,
        Michal Hocko <mhocko@...e.com>,
        Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH] exec: load_script: Allow interpreter argument truncation

On Thu, Feb 14, 2019 at 8:08 AM Oleg Nesterov <oleg@...hat.com> wrote:
>
> On 02/13, Kees Cook wrote:
> >
> > While we want to make sure the kernel doesn't attempt to execute a
> > truncated interpreter path, we must allow the interpreter arguments to
> > be truncated. Perl, for example, will re-read the script itself to parse
> > arguments correctly.
>
> Heh. I still think that 8099b047ecc4 does the right thing.
>
> But I can't argue with the fact that it caused the regression, so it should
> be reverted.
>
> > This documents the parsing steps, and will fail to exec if the string was
> > truncated with neither an end-of-line nor any trailing whitespace.
>
> You know, I have already spent 3 hours trying to write something simple and
> clear, but failed. Still trying...

That's why I added comments too. It's kind of a weird bit of parsing,
and has to protect itself from lack of initial NUL-termination. :P

> Nor I can really understand your fix ;) Will try to read it again, just one
> question for now,
>
> >       for (cp = bprm->buf+2;; cp++) {
> > -             if (cp >= bprm->buf + BINPRM_BUF_SIZE)
> > -                     return -ENOEXEC;
> > -             if (!*cp || (*cp == '\n'))
> > +             if (cp == bprm->buf + BINPRM_BUF_SIZE - 1) {
> > +                     truncated = true;
>
> Off-by-one, no? "bprm->buf + BINPRM_BUF_SIZE - 1" is the very last char, it can
> be '\n' or '\0', this should set end_of_interp.

Ah yeah, this bails out one byte too early. As you suggestion, I
should move that test to after the !*cp || *cp == '\n' test, like so:

        for (cp = bprm->buf+2;; cp++) {
                if (!*cp || (*cp == '\n')) {
                        end_of_interp = true;
                        break;
                }
                if (cp == bprm->buf + BINPRM_BUF_SIZE - 1) {
                        truncated = true;
                        break;
                }
        }
        *cp = '\0';

> >                       break;
> > +             }
> > +             if (!*cp || (*cp == '\n')) {
> > +                     end_of_interp = true;
> > +                     break;
> > +             }
>
> so unless I am totally confused you should move this block up before the
> "bprm->buf + BINPRM_BUF_SIZE - 1" check or that check should use
> "bprm->buf + BINPRM_BUF_SIZE".
>
> No?

Moving the block is right, dropping the -1 would be lead to the
post-loop *cp = '\0' writing past the end of the buffer.

With this change, my tests (after gaining an extra byte of available
interp path name) still pass. I'll send a v2...

Thanks!

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ