From: Mathias Krause <minipli@googlemail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, stable@kernel.org,
Al Viro <viro@zeniv.linux.org.uk>,
Rusty Russell <rusty@rustcorp.com.au>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] init: use KERNEL_DS when trying to start init process
Date: Tue, 7 Jun 2011 08:49:53 +0200 [thread overview]
Message-ID: <6C79597B-CBC0-46FB-A700-BD04FFE2C5FF@googlemail.com> (raw)
In-Reply-To: <20110606161254.5f02d855.akpm@linux-foundation.org>
On 07.06.2011, 01:12 Andrew Morton wrote:
> On Mon, 30 May 2011 18:17:08 +0200
> Mathias Krause <minipli@googlemail.com> wrote:
>
>> The bug is, that search_binary_handler() sets the address limit to
>> USER_DS but doesn't reset it on error which will make all further
>> attempts fail with -EFAULT because argv[0] is a pointer to kernel
>> memory, not userland.
>>
>> The bug can easily be reproduced by starting a 32 bit kernel with a 64
>> bit executable as /init and a 32 bit version as /sbin/init within an
>> initramfs. The hardcoded defaults should make /init fail because of the
>> unsupported file format but should make /sbin/init succeed. This doesn't
>> happen because the string "/sbin/init" lives in kernel memory and is no
>> longer allowed because of the modified address limit to USER_DS after
>
> Geeze, you're kicking over some ancient rocks there.
>
> Possibly the bug was added by
>
> commit 473ae30bc7b1dda5c5791c773f95e9424ddfead9
> Author: Al Viro <viro@zeniv.linux.org.uk>
> AuthorDate: Wed Apr 26 14:04:08 2006 -0400
> Commit: Al Viro <viro@zeniv.linux.org.uk>
> CommitDate: Tue Jun 20 05:25:21 2006 -0400
>
> [PATCH] execve argument logging
>
>
> and will be fixed with
>
> --- a/fs/exec.c~a
> +++ a/fs/exec.c
> @@ -1357,14 +1357,14 @@ int search_binary_handler(struct linux_b
> if (retval)
> return retval;
>
> - /* kernel module loader fixup */
> - /* so we don't try to load run modprobe in kernel space. */
> - set_fs(USER_DS);
> -
> retval = audit_bprm(bprm);
> if (retval)
> return retval;
>
> + /* kernel module loader fixup */
> + /* so we don't try to load run modprobe in kernel space. */
> + set_fs(USER_DS);
> +
> retval = -ENOENT;
> for (try=0; try<2; try++) {
> read_lock(&binfmt_lock);
> _
This fixes nothing because search_binary_handler() won't return that early in
my case but will try the binfmt list to find an appropriate handler. That for,
removing the set_fs() *might* be yet another solution to the problem but I
wasn't brave enough to do that change because I could not foresee all related
consequences -- didn't want to exchange a bug fix for a security hole.
Just changing the address limit in run_init_process() was the straight forward
fix with the least possible implications to the rest of the execve path.
> but I'm finding lots of mysterious things in there.
>
> Like, what does this comment:
>
> /* so we don't try to load run modprobe in kernel space. */
> set_fs(USER_DS);
>
> mean?
I found this comment confusing, too. But since the usermode helper is started
as separate kernel thread I thought this might be a security measure to prevent
leaking kernel memory to userland?!
> It's all truly ancient code and I suspect the set_fs() simply isn't
> needed any more - the calling process doesn't parent modprobe. And
> request_module() should take care of the mm_segment, not its callers.
>
> Also, search_binary_handler() appears to *always* return with USER_DS?
> Is that a secret part of its interface? Or should it be
> unconditionally restoring KERNEL_DS?
Wouldn't that introduce a security bug, when a userland triggered execve()
fails to execute and returns to userland? Having that process run with
KERNEL_DS afterwards isn't wanted, is it? Or is the address limit restored
by some other means?
> I tried to work out how that set_fs() got there, in the historical git
> tree but it's part of 14592fa9:
>
> 73 files changed, 963 insertions(+), 798 deletions(-)
>
> which is pretty useless (what's up with that?)
>
>
> So I dunno, I'm stumped. I'm suspecting that the right fix here is to
> just remove that call to set_fs(USER_DS) but I'm having trouble working
> out what all this cruft is trying to do.
Me is having trouble too, that for the simple solution with run_init_process().
Mathias
next prev parent reply other threads:[~2011-06-07 6:49 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-30 16:17 Mathias Krause
2011-06-06 23:12 ` Andrew Morton
2011-06-07 6:49 ` Mathias Krause [this message]
2011-06-08 2:00 ` Linus Torvalds
2011-06-08 8:23 ` Mathias Krause
2011-06-08 10:47 ` Al Viro
2011-06-08 12:14 ` Mathias Krause
2011-06-08 14:03 ` Al Viro
2011-06-08 20:20 ` Chris Metcalf
2011-06-09 8:14 ` Mathias Krause
2011-06-09 10:40 ` Al Viro
2011-06-09 12:06 ` Mathias Krause
2011-06-09 15:56 ` Linus Torvalds
2011-06-09 16:40 ` Mathias Krause
2011-06-09 17:03 ` Linus Torvalds
2011-06-09 18:05 ` Mathias Krause
2011-06-09 22:56 ` [PATCH] init: use KERNEL_DS when trying to start init process Andrew Morton
2011-06-10 8:11 ` Mathias Krause
2011-06-10 15:52 ` Randy Dunlap
2011-06-10 13:08 ` [PATCH] alpha, exec: remove redundant set_fs(USER_DS) Mathias Krause
2011-06-10 13:08 ` [PATCH] arm, " Mathias Krause
2011-06-10 13:48 ` Russell King - ARM Linux
2011-06-10 13:53 ` Mathias Krause
2011-06-27 4:29 ` Mathias Krause
2011-06-10 13:09 ` [PATCH] avr32, " Mathias Krause
2011-06-14 11:28 ` Hans-Christian Egtvedt
2011-06-10 13:09 ` [PATCH] blackfin, " Mathias Krause
2011-06-10 14:17 ` Mike Frysinger
2011-06-10 13:09 ` [PATCH] cris, " Mathias Krause
2011-06-10 13:09 ` [PATCH] frv, " Mathias Krause
2011-06-10 13:09 ` [PATCH] h8300, " Mathias Krause
2011-06-10 13:09 ` [PATCH] ia64, " Mathias Krause
2011-06-10 13:09 ` [PATCH] m32r, " Mathias Krause
2011-06-10 13:09 ` [PATCH] m68k, " Mathias Krause
2011-06-15 14:40 ` Geert Uytterhoeven
2011-06-15 15:49 ` Mathias Krause
2011-06-10 13:09 ` [PATCH] microblaze, " Mathias Krause
2011-07-05 11:45 ` Michal Simek
2011-06-10 13:10 ` [PATCH] mips, exec: remove redundant addr_limit assignment Mathias Krause
2011-06-10 13:10 ` [PATCH] mn10300, exec: remove redundant set_fs(USER_DS) Mathias Krause
2011-06-10 13:10 ` [PATCH] parisc, " Mathias Krause
2011-06-10 13:10 ` [PATCH] ppc, " Mathias Krause
2011-06-10 13:10 ` [PATCH] s390, " Mathias Krause
2011-06-10 13:10 ` [PATCH] sh, " Mathias Krause
2011-06-14 6:33 ` Paul Mundt
2011-06-10 13:10 ` [PATCH] sparc, exec: remove redundant addr_limit assignment Mathias Krause
2011-06-11 23:08 ` David Miller
2011-06-11 23:44 ` Al Viro
2011-06-12 0:58 ` David Miller
2011-06-12 1:01 ` Linus Torvalds
2011-06-12 1:04 ` David Miller
2011-06-13 20:28 ` Mathias Krause
2011-06-17 18:45 ` Mathias Krause
2011-06-10 13:10 ` [PATCH] um, exec: remove redundant set_fs(USER_DS) Mathias Krause
2011-06-10 20:00 ` Richard Weinberger
2011-06-10 13:11 ` [PATCH] unicore32, " Mathias Krause
2011-06-13 9:19 ` Guan Xuetao
2011-06-13 16:02 ` Mathias Krause
2011-06-14 7:03 ` Guan Xuetao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6C79597B-CBC0-46FB-A700-BD04FFE2C5FF@googlemail.com \
--to=minipli@googlemail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®