public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: personality(ADDR_LIMIT_3GB) results in EFAULT
Date: Thu, 27 May 2010 21:17:05 +0400	[thread overview]
Message-ID: <4BFEA911.40600@msgid.tls.msk.ru> (raw)

Hello.

I noticed an.. interesting issue here.

Running a 32bit executable on a 64bit kernel,
and doing

  personality(ADDR_LIMIT_3GB);

That call succedes, but any further execve()
and friends results in EFAULT, unless whole
argv[] and envp[] are copied to a malloc'ed
space.  alloca sometimes helps and sometimes
not.

This simple program demonstrates the issue:


===== cut =====
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main(int ac, char **av, char **ev) {
  int i;

  personality(ADDR_LIMIT_3GB);

  ++av; --ac;

  for (i = 0; i < ac; ++i)
    av[i] = strdup(av[i]);

  for(i = 0; ev[i]; ++i)
   ev[i] = strdup(ev[i]);

  execve(av[0], av, ev);
  printf("unable to execute %s: %m\n", av[0]);
  return 1;
}
===== cut =====

Run as ./a.out /bin/echo
(or any other 32bit program).

Without the two for() loops it fails with EFAULT
error.  Changing strdup into strdupa results in
it working in the above simplest case, but
failing in more complex situation as a part of
larger program.

For now, in order to set this personality, I use
a 64bit helper program that executes the 32bit
binary (for which that personality is important).
Which look a bit ugly, esp. since it is in a chain
of other, all 32bit, programs.

Is it easy enough to fix? :)

The issue here, original issue, is a need to run
some legacy application (oracle database v.8 in
in this particular example), so it's not very
interesting to fix.  But doing ugly workarounds
aren't good either :)

Thanks!

/mjt

             reply	other threads:[~2010-05-27 17:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-27 17:17 Michael Tokarev [this message]
2010-05-27 18:38 ` personality(ADDR_LIMIT_3GB) results in EFAULT Andi Kleen
2010-06-13 18:20   ` Michael Tokarev

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=4BFEA911.40600@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=linux-kernel@vger.kernel.org \
    /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