mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Matthieu CASTET <matthieu.castet@parrot.com>
Cc: linux-kernel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH] binfmt_elf: fix return value in case of interpreter load failure
Date: Thu, 11 Apr 2013 15:04:01 -0700	[thread overview]
Message-ID: <20130411150401.8bf008e05f5dd2239277e2c1@linux-foundation.org> (raw)
In-Reply-To: <1365688389-29908-1-git-send-email-matthieu.castet@parrot.com>

On Thu, 11 Apr 2013 15:53:09 +0200 Matthieu CASTET <matthieu.castet@parrot.com> wrote:

> The current code return the address instead of using PTR_ERR.

I don't understand what you mean here - please describe this error in
much more detail.  Help people to identify the section of code which
is being discussed.

> Also the check is done after adding e_entry. This can cause weird behaviour
> because -errno + loc->interp_elf_ex.e_entry can produce a valid address.

Which check?

> Add a check to test load error before adding entry address. Also in this
> case send SIGKILL instead of SIGSEGV to match what is done when loading binary.
> 
> ...
>
> --- a/fs/binfmt_elf.c
> +++ b/fs/binfmt_elf.c
> @@ -900,18 +900,21 @@ static int load_elf_binary(struct linux_binprm *bprm)
>  					    interpreter,
>  					    &interp_map_addr,
>  					    load_bias);
> -		if (!IS_ERR((void *)elf_entry)) {
> -			/*
> -			 * load_elf_interp() returns relocation
> -			 * adjustment
> -			 */
> -			interp_load_addr = elf_entry;
> -			elf_entry += loc->interp_elf_ex.e_entry;
> +		if (BAD_ADDR(elf_entry)) {
> +			force_sig(SIGKILL, current);
> +			retval = IS_ERR((void *)elf_entry) ?
> +					PTR_ERR((void *)elf_entry) : -EINVAL;

Thats's a bit verbose - "PTR_ERR((void *)elf_entry)" is equivalent to
"elf_entry".  I suppose we can do it this way to document the intent or
something.

It would be helpful if load_elf_interp() had some documentation
describing its return value btw.


> +			goto out_free_dentry;
>  		}
> +		/*
> +		 * load_elf_interp() returns relocation
> +		 * adjustment

This can now be converted to a single-line comment.

> +		 */
> +		interp_load_addr = elf_entry;
> +		elf_entry += loc->interp_elf_ex.e_entry;
>  		if (BAD_ADDR(elf_entry)) {
>  			force_sig(SIGSEGV, current);
> -			retval = IS_ERR((void *)elf_entry) ?
> -					(int)elf_entry : -EINVAL;
> +			retval = -EINVAL;
>  			goto out_free_dentry;
>  		}
>  		reloc_func_desc = interp_load_addr;


  reply	other threads:[~2013-04-11 22:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 13:53 Matthieu CASTET
2013-04-11 22:04 ` Andrew Morton [this message]
2013-04-12 14:49   ` Matthieu CASTET
2013-04-15 21:53     ` Andrew Morton
2013-04-16 14:25       ` Oleg Nesterov

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=20130411150401.8bf008e05f5dd2239277e2c1@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthieu.castet@parrot.com \
    --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

Powered by JetHome