linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Qiaowei Ren <qiaowei.ren@intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@intel.com>,
	x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 08/10] x86, mpx: add prctl commands PR_MPX_REGISTER, PR_MPX_UNREGISTER
Date: Fri, 12 Sep 2014 01:28:14 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.10.1409120020060.4178@nanos> (raw)
In-Reply-To: <1410425210-24789-9-git-send-email-qiaowei.ren@intel.com>

On Thu, 11 Sep 2014, Qiaowei Ren wrote:

> This patch adds the PR_MPX_REGISTER and PR_MPX_UNREGISTER prctl()
> commands. These commands can be used to register and unregister MPX
> related resource on the x86 platform.

I cant see anything which is registered/unregistered.
 
> The base of the bounds directory is set into mm_struct during
> PR_MPX_REGISTER command execution. This member can be used to
> check whether one application is mpx enabled.

This changelog is completely useless.

What's the actual point of this prctl?

> +/*
> + * This should only be called when cpuid has been checked
> + * and we are sure that MPX is available.

Groan. Why can't you put that cpuid check into that function right
away instead of adding a worthless comment?

It's obviously more important to have a comment about somthing which
is obvious than explaining what the function is actually doing, right?

> + */
> +static __user void *task_get_bounds_dir(struct task_struct *tsk)
> +{
> +	struct xsave_struct *xsave_buf;
> +
> +	fpu_xsave(&tsk->thread.fpu);
> +	xsave_buf = &(tsk->thread.fpu.state->xsave);
> +	if (!(xsave_buf->bndcsr.cfg_reg_u & MPX_BNDCFG_ENABLE_FLAG))
> +		return NULL;

Now this might be understandable with a proper comment. Right now it's
a magic check for something uncomprehensible.

> +	return (void __user *)(unsigned long)(xsave_buf->bndcsr.cfg_reg_u &
> +			MPX_BNDCFG_ADDR_MASK);
> +}
> +
> +int mpx_register(struct task_struct *tsk)
> +{
> +	struct mm_struct *mm = tsk->mm;
> +
> +	if (!cpu_has_mpx)
> +		return -EINVAL;
> +
> +	/*
> +	 * runtime in the userspace will be responsible for allocation of
> +	 * the bounds directory. Then, it will save the base of the bounds
> +	 * directory into XSAVE/XRSTOR Save Area and enable MPX through
> +	 * XRSTOR instruction.
> +	 *
> +	 * fpu_xsave() is expected to be very expensive. In order to do
> +	 * performance optimization, here we get the base of the bounds
> +	 * directory and then save it into mm_struct to be used in future.
> +	 */

Ah. Now we get some information what this might do. But that does not
make any sense at all.

So all it does is:

    tsk->mm.bd_addr = xsave_buf->bndcsr.cfg_reg_u & MPX_BNDCFG_ADDR_MASK;

or:

    tsk->mm.bd_addr = NULL;

So we use that information to check, whether we need to tear down a
VM_MPX flagged region with mpx_unmap(), right?

> +         /*
> +          * Check whether this vma comes from MPX-enabled application.
> +          * If so, release this vma related bound tables.
> +          */
> +         if (mm->bd_addr && !(vma->vm_flags & VM_MPX))
> +                 mpx_unmap(mm, start, end);

You really must be kidding. The application maps that table and never
calls that prctl so do_unmap() will happily ignore it?

The design to support this feature makes no sense at all to me. We
have a special mmap interface, some magic kernel side mapping
functionality and then on top of it a prctl telling the kernel to
ignore/respect it.

All I have seen so far is the hint to read some intel feature
documentation, but no coherent explanation how this patch set makes
use of that very feature. The last patch in the series does not count
as coherent explanation. It merily documents parts of the
implementation details which are required to make use of it but
completely lacks of a coherent description how all of this is supposed
to work.

Despite the fact that this is V8, I can't suppress the feeling that
this is just cobbled together to make it work somehow and we'll deal
with the fallout later. I wouldn't be surprised if some of the fallout
is going to be security related. I have a pretty good idea how to
exploit it even without understanding the non-malicious intent of the
whole thing.

So: NAK to the whole series for now until someone comes up with a
coherent explanation.

Thanks,

	tglx

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2014-09-11 23:28 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-11  8:46 [PATCH v8 00/10] Intel MPX support Qiaowei Ren
2014-09-11  8:46 ` [PATCH v8 01/10] x86, mpx: introduce VM_MPX to indicate that a VMA is MPX specific Qiaowei Ren
2014-09-11  8:46 ` [PATCH v8 02/10] x86, mpx: add MPX specific mmap interface Qiaowei Ren
2014-09-11  8:46 ` [PATCH v8 03/10] x86, mpx: add macro cpu_has_mpx Qiaowei Ren
2014-09-11  8:46 ` [PATCH v8 04/10] x86, mpx: hook #BR exception handler to allocate bound tables Qiaowei Ren
2014-09-12 22:58   ` Dave Hansen
2014-09-13  7:24     ` Ren, Qiaowei
2014-09-24 14:40   ` Dave Hansen
2014-09-11  8:46 ` [PATCH v8 05/10] x86, mpx: extend siginfo structure to include bound violation information Qiaowei Ren
2014-09-11  8:46 ` [PATCH v8 06/10] mips: sync struct siginfo with general version Qiaowei Ren
2014-09-11 22:13   ` Thomas Gleixner
2014-09-12  2:54     ` Ren, Qiaowei
2014-09-12  8:17       ` Thomas Gleixner
2014-09-13  7:13         ` Ren, Qiaowei
2014-09-11  8:46 ` [PATCH v8 07/10] x86, mpx: decode MPX instruction to get bound violation information Qiaowei Ren
2014-09-11 22:18   ` Thomas Gleixner
2014-09-11 22:32     ` Dave Hansen
2014-09-11 22:35       ` H. Peter Anvin
2014-09-11 23:37         ` Thomas Gleixner
2014-09-12  4:44           ` H. Peter Anvin
2014-09-12 13:10             ` Thomas Gleixner
2014-09-12 13:39               ` H. Peter Anvin
2014-09-12 17:48                 ` Thomas Gleixner
2014-09-12 17:52         ` Thomas Gleixner
2014-09-12 19:07           ` H. Peter Anvin
2014-09-11  8:46 ` [PATCH v8 08/10] x86, mpx: add prctl commands PR_MPX_REGISTER, PR_MPX_UNREGISTER Qiaowei Ren
2014-09-11 15:03   ` Dave Hansen
2014-09-12  3:10     ` Ren, Qiaowei
2014-09-11 23:28   ` Thomas Gleixner [this message]
2014-09-12  0:10     ` Dave Hansen
2014-09-12  8:11       ` Thomas Gleixner
2014-09-12  9:24         ` Thomas Gleixner
2014-09-12 14:36           ` Dave Hansen
2014-09-12 17:34             ` Thomas Gleixner
2014-09-12 18:42               ` Thomas Gleixner
2014-09-12 20:35                 ` Dave Hansen
2014-09-12 20:18               ` Dave Hansen
2014-09-13  9:01                 ` Thomas Gleixner
2014-09-12 15:22         ` Dave Hansen
2014-09-12 17:42           ` Thomas Gleixner
2014-09-12 20:33             ` Dave Hansen
2014-09-15  0:00   ` One Thousand Gnomes
2014-09-16  3:20     ` Ren, Qiaowei
2014-09-16  4:17       ` Dave Hansen
2014-09-16  7:50   ` Kevin Easton
2014-09-18  0:40     ` Ren, Qiaowei
2014-09-18  3:23       ` Kevin Easton
2014-09-18  2:37         ` Ren, Qiaowei
2014-09-18  4:43         ` Dave Hansen
2014-09-18  7:17           ` Kevin Easton
2014-09-18  6:20             ` Dave Hansen
2014-09-11  8:46 ` [PATCH v8 09/10] x86, mpx: cleanup unused bound tables Qiaowei Ren
2014-09-11 14:59   ` Dave Hansen
2014-09-12  3:02     ` Ren, Qiaowei
2014-09-12  4:59       ` Dave Hansen
2014-09-15 20:53   ` Dave Hansen
2014-09-16  8:06     ` Ren, Qiaowei
2014-09-11  8:46 ` [PATCH v8 10/10] x86, mpx: add documentation on Intel MPX Qiaowei Ren
2014-09-12  0:51 ` [PATCH v8 00/10] Intel MPX support Dave Hansen
2014-09-12 19:21   ` Thomas Gleixner
2014-09-12 21:23     ` Dave Hansen
2014-09-13  9:25       ` Thomas Gleixner
2014-09-12 21:31     ` Dave Hansen
2014-09-12 22:08     ` Dave Hansen
2014-09-13  9:39       ` Thomas Gleixner

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=alpine.DEB.2.10.1409120020060.4178@nanos \
    --to=tglx@linutronix.de \
    --cc=dave.hansen@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@redhat.com \
    --cc=qiaowei.ren@intel.com \
    --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