All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: x86@kernel.org, Ingo Molnar <mingo@elte.hu>,
	richard -rw- weinberger <richard.weinberger@gmail.com>,
	Adrian Bunk <bunk@stusta.de>,
	"H. Peter Anvin" <hpa@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86-64: Set siginfo and context on vsyscall emulation faults
Date: Sat, 22 Oct 2011 02:07:51 -0700	[thread overview]
Message-ID: <CALCETrXAiHs9PyziHBm-gZRiyahYafbxxUSxJUcFh=a-0th0EQ@mail.gmail.com> (raw)
In-Reply-To: <CA+55aFxqG0S+ZS0RHgyFLzgg-c_zu+095OhFresCGAuv8MfQ6A@mail.gmail.com>

On Fri, Oct 21, 2011 at 9:46 PM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> On Sat, Oct 22, 2011 at 12:01 AM, Andy Lutomirski <luto@amacapital.net> wrote:
>>
>> +static bool write_ok_or_segv(unsigned long ptr, size_t size)
>> +{
>> +       if (ptr == 0)
>> +               return true;
>
> Why is ptr==0 special? That makes no sense.
>

Pure laziness.  Null pointers to the vsyscalls are valid and mean that
userspace doesn't care about the result.  I could have put the check
in the caller just as easily.

> Also, this whole function makes the notion of setting the "sigsegv on
> fault" flag much less interesting. It would be much better if
> access_ok() (including the cases embedded in get_user/put_user/etc)
> just did it right automatically for everything, rather than
> special-casing it for just this.
>

Agreed.  If I add an option to let userspace opt in to the
signal-sending behavior, I'd want to convince myself that all callers
of access_ok should be affected.

> I wonder if we could just make access_ok() use a trap instead of just
> the regular compares (and then in the trap handler do the same logic
> as in the page fault handler)? Sadly, the 'bounds' instruction doesn't
> work for this (in 32-bit mode it does a *signed* compare, and in
> 64-bit mode it no longer exists), but something like that might.
>

I suspect that bounds is considerably slower than a comparison anyway.

FWIW, there's a different optimization that could make a lot of this
code much nicer: using asm goto for the failure path in get_user, etc.
 The failure path is already a branch, and if gcc could be convinced
to generate sensible code for:

if (put_user(...)) goto out;
if (put_user(...)) goto out;
if (put_user(...)) goto out;
if (put_user(...)) goto out;

then the uaccess_err mechanism and a whole lot of bitwise ors could go away.

Sadly, gcc (at least 4.5 and 4.6) has weird limitations on the kind of
constraints allowed on asm goto that, IIRC, make get_user impossible
and put_user a little dicey.  (I could have that backwards.)

> That said, I think that your patch looks acceptable as a "let's fix
> vsyscalls without doing the bigger change". But I really don't see why
> ptr==0 would be special.
>
> So I think your write_ok_or_segv() function should just be
>
>   static bool write_ok_or_segv(unsigned long ptr, size_t size)
>   {
>      if (access_ok(ptr, size))
>         return true;
>
>       .. send signal ...
>
>      return false;
>   }
>
> instead of that odd thing you have now.

Or a comment to clarify it.  Alternatively I could ignore the issue
because access to 0 is okay in the access_ok sense anyway.

--Andy

  reply	other threads:[~2011-10-22  9:07 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-03  9:08 [3.1 patch] x86: default to vsyscall=native Adrian Bunk
2011-10-03 13:04 ` Andrew Lutomirski
2011-10-03 17:33   ` Adrian Bunk
2011-10-03 18:06     ` Andrew Lutomirski
2011-10-03 18:41       ` Adrian Bunk
2011-10-05 22:13     ` Andrew Lutomirski
2011-10-05 22:22       ` richard -rw- weinberger
2011-10-05 22:30         ` Adrian Bunk
2011-10-05 22:41           ` richard -rw- weinberger
2011-10-05 22:46           ` Andrew Lutomirski
2011-10-05 23:36             ` Andrew Lutomirski
2011-10-06  3:06               ` Andrew Lutomirski
2011-10-06 12:12                 ` richard -rw- weinberger
2011-10-06 15:37                 ` richard -rw- weinberger
2011-10-06 18:16                   ` Andrew Lutomirski
2011-10-06 18:34                     ` Linus Torvalds
2011-10-07  0:48                       ` Andrew Lutomirski
2011-10-10 11:19                         ` richard -rw- weinberger
2011-10-10 11:48                           ` Ingo Molnar
2011-10-10 15:31                             ` Andrew Lutomirski
2011-10-11  6:22                               ` Ingo Molnar
2011-10-11 17:24                                 ` [RFC] fixing the UML failure root cause Andrew Lutomirski
2011-10-13  6:19                                   ` Linus Torvalds
2011-10-13  8:40                                     ` Andrew Lutomirski
2011-10-14  4:46                                       ` Linus Torvalds
2011-10-14  6:30                                         ` Andrew Lutomirski
2011-10-14 20:10                                           ` Linus Torvalds
2011-10-21 21:01                                             ` [PATCH] x86-64: Set siginfo and context on vsyscall emulation faults Andy Lutomirski
2011-10-22  4:46                                               ` Linus Torvalds
2011-10-22  9:07                                                 ` Andy Lutomirski [this message]
2011-11-08  0:33                                                   ` [PATCH 0/2] Fix and re-enable vsyscall=emulate Andy Lutomirski
2011-11-08  0:33                                                     ` [PATCH 1/2] x86-64: Set siginfo and context on vsyscall emulation faults Andy Lutomirski
2011-12-05 13:23                                                       ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2011-11-08  0:33                                                     ` [PATCH 2/2] x86: Default to vsyscall=emulate Andy Lutomirski
2011-12-05 13:24                                                       ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2011-12-02 22:47                                                     ` [PATCH 0/2] Fix and re-enable vsyscall=emulate Andy Lutomirski
2011-12-05 11:18                                                       ` H. Peter Anvin
2011-10-14 19:53                                   ` [RFC] fixing the UML failure root cause richard -rw- weinberger
2011-10-14 20:17                                     ` Andrew Lutomirski
2011-10-14 20:23                                       ` richard -rw- weinberger
2011-10-14 20:31                                         ` Andrew Lutomirski
2011-10-14 20:39                                           ` richard -rw- weinberger
2011-10-14 22:28                                       ` richard -rw- weinberger
2011-10-15 16:57                                         ` Ingo Molnar
2011-10-05 22:24       ` [3.1 patch] x86: default to vsyscall=native Adrian Bunk
2011-10-03 13:19 ` richard -rw- weinberger
2011-10-03 17:46   ` Adrian Bunk

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='CALCETrXAiHs9PyziHBm-gZRiyahYafbxxUSxJUcFh=a-0th0EQ@mail.gmail.com' \
    --to=luto@amacapital.net \
    --cc=bunk@stusta.de \
    --cc=hpa@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=richard.weinberger@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.