linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Zach Levis <zach@zachsthings.com>
Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	dan.carpenter@oracle.com, keescook@chromium.org,
	cody@linux.vnet.ibm.com, zml@linux.vnet.ibm.com
Subject: Re: [PATCH v4 2/3] fs/binfmts: Better handling of binfmt loops
Date: Wed, 14 Aug 2013 19:50:14 +0200	[thread overview]
Message-ID: <20130814175014.GA1080@redhat.com> (raw)
In-Reply-To: <1376497898-18619-3-git-send-email-zach@zachsthings.com>

On 08/14, Zach Levis wrote:
>
> Example: a qemu is configured to run 64-bit ELFs on an otherwise 32-bit
> system. The system's owner switches to running with 64-bit executables,
> but forgets to disable the binfmt_misc option that redirects 64bit ELFs
> to qemu. Since the qemu executable is a 64-bit ELF now, binfmt_misc
> keeps on matching it with the qemu rule, preventing the execution of any
> 64-bit binary.

Honestly, I dislike this version even more, sorry. The patch becomes
much more complex, and and it is still not clear to me why do we want
these complications.

> My (rough, but functional) test scripts for this issue are available at:
>     https://gist.github.com/zml2008/6075418

Well, suppose that someone tries to read this changelog in 2014 to
understand the code. Are you sure this link will be still alive?

It would be better to have everything in the changelog, if possible.

> +static void put_binfmts(struct linux_binprm *bprm, struct linux_binfmt *cur_fmt)
> +{
> +	if (bprm->previous_binfmts[1])
> +		put_binfmt(bprm->previous_binfmts[1]);
> +	if (bprm->previous_binfmts[0])
> +		put_binfmt(bprm->previous_binfmts[0]);
> +	if (cur_fmt)
> +		put_binfmt(cur_fmt);
> +}

I didn't actually read this patch, but at first glance this doesn't look
right. Just suppose that ->load_binary() succeeds at depth = N, this will
be called N times.

In fact I am not sure update_prev_binfmts() is right too, but probably
I do not understand the logic. Just suppose that each ->load_binary()
simply returns ENOEXEC at some depth. Do we really want to replace
previous_binfmts[1] every time?

> @@ -1393,18 +1494,44 @@ int search_binary_handler(struct linux_binprm *bprm)
>  	list_for_each_entry(fmt, &formats, lh) {
>  		if (!try_module_get(fmt->module))
>  			continue;
> +
> +		if (!update_prev_binfmts(bprm, fmt))
> +			continue;
> +
>  		read_unlock(&binfmt_lock);
> +
>  		bprm->recursion_depth++;
>  		retval = fmt->load_binary(bprm);
>  		bprm->recursion_depth--;
> -		if (retval >= 0 || retval != -ENOEXEC ||
> -		    bprm->mm == NULL || bprm->file == NULL) {
> -			put_binfmt(fmt);
> +		if (retval == -ELOOP
> +			&& bprm->recursion_depth == 0) { /* cur, previous */
> +			pr_err("Too much recursion with binfmts (0:%s, -1:%s) in file %s, skipping (base %s).\n",
> +				binfmt_name(bprm->previous_binfmts[0]),
> +				binfmt_name(bprm->previous_binfmts[1]),
> +				bprm->filename,
> +				fmt->name);
> +
> +			free_arg_pages(bprm);
> +			if (bprm->interp != bprm->filename)
> +				kfree(bprm->interp);
> +			bprm_close_file(bprm);
> +			retval = init_bprm(bprm, bprm->filename,
> +					   bprm->argv_orig, bprm->envp_orig);
> +			if (retval < 0) {
> +				put_binfmts(bprm, fmt);
> +				return retval;
> +			}

I still think that if we want this, it would be better to move this hack
into load_misc_binary(). Only linux_binprm itself can know it is desirable
(or even safe) to recover/restart in general.

And btw, if we want this, then why we only do this if recursion_depth == 0?
Just condider '#!/path-to-the-binary-which-wants-this-patch".

And again, the patch (afaics) translates -ELOOP into -ENOEXEC on failure,
not good.

Oleg.

  reply	other threads:[~2013-08-14 17:50 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25 15:40 [PATCH 1/3] fs/binfmts: Add a name field to the binfmt struct Zach Levis
2013-07-25 15:40 ` [PATCH 2/3] fs/binfmts: Better handling of binfmt loops Zach Levis
2013-07-30 21:04   ` Andrew Morton
2013-07-30 23:16     ` Zach Levis
2013-07-30 23:26       ` Andrew Morton
2013-07-31 16:17         ` Zach Levis
2013-07-25 15:40 ` [PATCH 3/3] fs/binfmts: Whitespace fixes with scripts/cleanfile Zach Levis
2013-08-02 22:12 ` [PATCH v2 0/3] fs/binfmts: Improve handling of loops Zach Levis
2013-08-02 22:12 ` [PATCH v2 1/3] fs/binfmts: Add a name field to the binfmt struct Zach Levis
2013-08-02 22:12 ` [PATCH v2 2/3] fs/binfmts: Better handling of binfmt loops Zach Levis
2013-08-02 22:49   ` Zach Levis
2013-08-02 22:12 ` [PATCH v2 3/3] fs/binfmts: Whitespace fixes with scripts/cleanfile Zach Levis
2013-08-02 23:21 ` [PATCH v3 0/3] fs/binfmts: Improve handling of loops Zach Levis
2013-08-06 21:11   ` Kees Cook
2013-08-07 23:30     ` Zach Levis
2013-08-02 23:21 ` [PATCH v3 1/3] fs/binfmts: Add a name field to the binfmt struct Zach Levis
2013-08-03 16:41   ` Oleg Nesterov
2013-08-02 23:21 ` [PATCH v3 2/3] fs/binfmts: Better handling of binfmt loops Zach Levis
2013-08-03 16:42   ` Oleg Nesterov
2013-08-02 23:21 ` [PATCH v3 3/3] fs/binfmts: Whitespace fixes with scripts/cleanfile Zach Levis
2013-08-03 16:51   ` Oleg Nesterov
2013-08-14 16:31 ` [PATCH v4 0/3] fs/binfmts: Improve handling of loops Zach Levis
2013-08-14 16:31 ` [PATCH v4 1/3] fs/binfmts: Add a name field to the binfmt struct Zach Levis
2013-08-14 16:31 ` [PATCH v4 2/3] fs/binfmts: Better handling of binfmt loops Zach Levis
2013-08-14 17:50   ` Oleg Nesterov [this message]
2013-08-15 16:26     ` Zach L
2013-08-16 12:23       ` Oleg Nesterov
2013-08-14 18:16   ` Oleg Nesterov
2013-08-14 16:31 ` [PATCH v4 3/3] fs/binfmts: Whitespace fixes with scripts/cleanfile Zach Levis
2013-08-15 16:20 ` [PATCH v5 0/3] fs/binfmts: Improve handling of loops Zach Levis
2013-08-15 16:20 ` [PATCH v5 1/3] fs/binfmts: Add a name field to the binfmt struct Zach Levis
2013-08-15 17:06   ` Kees Cook
2013-08-15 16:20 ` [PATCH v5 2/3] fs/binfmts: Better handling of binfmt loops Zach Levis
2013-08-16 13:15   ` Oleg Nesterov
2013-08-15 16:20 ` [PATCH v5 3/3] fs/binfmts: Whitespace fixes with scripts/cleanfile Zach Levis

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=20130814175014.GA1080@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=cody@linux.vnet.ibm.com \
    --cc=dan.carpenter@oracle.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zach@zachsthings.com \
    --cc=zml@linux.vnet.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).