linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: Ren Qiaowei <qiaowei.ren@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	x86@kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/4] x86, mpx: hook #BR exception handler to allocate bound tables
Date: Mon, 27 Jan 2014 21:21:43 -0800	[thread overview]
Message-ID: <CALCETrW0L79gjXRD5J5RZQTiZT+MYDYHQ0u7hoeKP=XVqDT5HA@mail.gmail.com> (raw)
In-Reply-To: <52E72573.9090108@intel.com>

On Mon, Jan 27, 2014 at 7:35 PM, Ren Qiaowei <qiaowei.ren@intel.com> wrote:
> On 01/28/2014 04:36 AM, Andy Lutomirski wrote:
>>>
>>> +       bd_entry = status & MPX_BNDSTA_ADDR_MASK;
>>> +       if ((bd_entry >= bd_base) && (bd_entry < bd_base + bd_size))
>>> +               allocate_bt(bd_entry);
>>
>>
>> What happens if this fails?  Retrying forever isn't very nice.
>>
> If allocation of the bound table fail, the related entry in the bound
> directory is still invalid. The following access to this entry still produce
> #BR fault.
>

By the "following access" I think you mean the same instruction that
just trapped -- it will trap again because the exception hasn't been
fixed up.  Then mmap will fail again, and you'll retry again, leading
to an infinite loop.

I think that failure to fix up the exception should either let the
normal bounds error through or should raise SIGBUS.

>
>>> +       if (!user_mode(regs)) {
>>> +               if (!fixup_exception(regs)) {
>>> +                       tsk->thread.error_code = error_code;
>>> +                       tsk->thread.trap_nr = X86_TRAP_BR;
>>> +                       die("bounds", regs, error_code);
>>> +               }
>>
>>
>> Why the fixup?  Unless I'm missing something, the kernel has no business
>> getting #BR on access to a user address.
>>
>> Or are you adding code to allow the kernel to use MPX itself?  If so,
>> shouldn't this use an MPX-specific fixup to allow normal C code to use
>> this stuff?
>>
> It checks whether #BR come from user-space. You can see do_trap_no_signal().

Wasn't #BR using do_trap before?  do_trap doesn't call
fixup_exception.  I don't see why it should do it now.  (I also don't
think it should come from kernel space until someone adds kernel-mode
MPX support.)

>
>
>>> +               goto exit;
>>> +       }
>>> +
>>> +       if (!boot_cpu_has(X86_FEATURE_MPX)) {
>>> +               do_trap(X86_TRAP_BR, SIGSEGV, "bounds", regs, error_code,
>>> NULL);
>>> +               goto exit;
>>
>>
>> This, as well as the status == 0 case, should probably document that the
>> exception is from BOUND, not MPX.
>>
> Ok. I will add one comment for this.
>
>
>
>>> +               break;
>>> +
>>> +       case 1: /* Bound violation. */
>>> +       case 0: /* No MPX exception. */
>>> +               do_trap(X86_TRAP_BR, SIGSEGV, "bounds", regs, error_code,
>>> NULL);
>>> +               break;
>>
>>
>> What does "No Intel MPX exception" mean?  Surely that has business
>> sending #BR.
>>
> Oh. It comes from spec, and just mean it is not from MPX. :) I will change
> it to be accurate.
>
>
>>> +
>>> +       default:
>>> +               break;
>>
>>
>> What does status 3 mean?  The docs say "reserved".  Presumably this
>> should log and kill the process.
>
> I guess it should be a good suggestion.
>
> Thanks,
> Qiaowei
>



-- 
Andy Lutomirski
AMA Capital Management, LLC

  reply	other threads:[~2014-01-28  5:22 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-26  9:08 [PATCH v3 0/4] Intel MPX support Qiaowei Ren
2014-01-26  8:19 ` Ingo Molnar
2014-01-26  8:20   ` Ren Qiaowei
2014-01-28  6:42     ` Ingo Molnar
2014-01-28  7:01       ` Ren Qiaowei
2014-01-28 18:26         ` H. Peter Anvin
2014-01-26  9:08 ` [PATCH v3 1/4] x86, mpx: add documentation on Intel MPX Qiaowei Ren
2014-01-26  3:06   ` Randy Dunlap
2014-01-26  3:15     ` Ren Qiaowei
2014-01-27 20:27   ` Andy Lutomirski
2014-01-28  3:40     ` Ren Qiaowei
2014-01-26  9:08 ` [PATCH v3 2/4] x86, mpx: hook #BR exception handler to allocate bound tables Qiaowei Ren
2014-01-27 20:36   ` Andy Lutomirski
2014-01-28  3:35     ` Ren Qiaowei
2014-01-28  5:21       ` Andy Lutomirski [this message]
2014-01-28  5:39         ` Ren Qiaowei
2014-01-28  6:42           ` Andy Lutomirski
2014-01-28  6:46             ` Ren Qiaowei
2014-01-26  9:08 ` [PATCH v3 3/4] x86, mpx: add prctl commands PR_MPX_INIT, PR_MPX_RELEASE Qiaowei Ren
2014-01-26  8:22   ` Ingo Molnar
2014-01-26  8:23     ` Ren Qiaowei
2014-01-26  8:39       ` Ingo Molnar
2014-01-26 11:37         ` Ren, Qiaowei
2014-01-27  1:50         ` H. Peter Anvin
2014-01-27  1:55           ` Ren Qiaowei
2014-01-27  2:10             ` H. Peter Anvin
2014-01-27  2:16               ` Ren Qiaowei
2014-01-27 21:54               ` Andy Lutomirski
2014-01-27 22:01                 ` H. Peter Anvin
2014-01-26  9:08   ` Ingo Molnar
2014-01-26 12:49     ` Ren, Qiaowei
2014-01-26 15:14       ` Ingo Molnar
2014-01-27  2:01         ` Ren Qiaowei
2014-01-27 20:59   ` Andy Lutomirski
2014-01-26  9:08 ` [PATCH v3 4/4] x86, mpx: extend siginfo structure to include bound violation information Qiaowei Ren
2014-01-26  4:22   ` David Rientjes
2014-01-26  4:39     ` Ren Qiaowei
2014-01-26 21:38       ` David Rientjes
2014-01-27  1:34         ` Ren Qiaowei
2014-01-27  1:53           ` H. Peter Anvin
2014-01-27  1:56             ` Ren Qiaowei
2014-01-27 21:58   ` Andy Lutomirski
2014-01-28  2:43     ` Ren Qiaowei

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='CALCETrW0L79gjXRD5J5RZQTiZT+MYDYHQ0u7hoeKP=XVqDT5HA@mail.gmail.com' \
    --to=luto@amacapital.net \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=qiaowei.ren@intel.com \
    --cc=tglx@linutronix.de \
    --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 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).