lkml.org 
[lkml]   [2019]   [Feb]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] exec: load_script: Allow interpreter argument truncation
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...

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.

> 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?

Oleg.

\
 
 \ /
  Last update: 2019-02-14 17:08    [W:2.373 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site