[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wg=0nAA9qGAogiFjpf0oCDcjkQE-u6umWCW-PkhrC8jrQ@mail.gmail.com>
Date: Sat, 9 May 2020 13:16:53 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: "Eric W. Biederman" <ebiederm@...ssion.com>
Cc: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Oleg Nesterov <oleg@...hat.com>, Jann Horn <jannh@...gle.com>,
Kees Cook <keescook@...omium.org>,
Greg Ungerer <gerg@...ux-m68k.org>,
Rob Landley <rob@...dley.net>,
Bernd Edlinger <bernd.edlinger@...mail.de>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Al Viro <viro@...iv.linux.org.uk>,
Alexey Dobriyan <adobriyan@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Casey Schaufler <casey@...aufler-ca.com>,
LSM List <linux-security-module@...r.kernel.org>,
James Morris <jmorris@...ei.org>,
"Serge E. Hallyn" <serge@...lyn.com>,
Andy Lutomirski <luto@...capital.net>
Subject: Re: [PATCH 3/5] exec: Remove recursion from search_binary_handler
On Sat, May 9, 2020 at 12:45 PM Eric W. Biederman <ebiederm@...ssion.com> wrote:
>
> Instead of recursing in search_binary_handler have the methods that
> would recurse return a positive value, and simply loop in exec_binprm.
>
> This is a trivial change as all of the methods that would recurse do
> so as effectively the last thing they do. Making this a trivial code
> change.
Looks good.
I'd suggest doing that loop slightly differently:
> - ret = search_binary_handler(bprm);
> + do {
> + depth++;
> + ret = search_binary_handler(bprm);
> + /* This allows 4 levels of binfmt rewrites before failing hard. */
> + if ((ret > 0) && (depth > 5))
> + ret = -ELOOP;
> + } while (ret > 0);
> if (ret >= 0) {
That's really an odd way to write this.
So honestly, if "ret < 0", then we can just return directly.
So I think would make much more sense to do this loop something like
for (depth = 0; depth < 5; depth++) {
int ret;
ret = search_binary_handler(bprm);
if (ret < 0)
return ret;
/* Continue searching for the next binary handler? */
if (ret > 0)
continue;
/* Success! */
audit_bprm(bprm);
trace_sched_process_exec(current, old_pid, bprm);
ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
proc_exec_connector(current);
return 0;
}
return -ELOOP;
(if I read the logic of exec_binprm() right - I might have missed something).
Linus
Powered by blists - more mailing lists