linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Florian Weimer <fweimer@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	linux-x86_64@vger.kernel.org, linux-arch@vger.kernel.org
Cc: linux-mm <linux-mm@kvack.org>, Linux API <linux-api@vger.kernel.org>
Subject: Re: MPK: pkey_free and key reuse
Date: Thu, 23 Nov 2017 14:07:03 +0100	[thread overview]
Message-ID: <3c4aab06-af97-ccd2-ed51-a462ec251c65@suse.cz> (raw)
In-Reply-To: <068b89c7-4303-88a7-540a-1491dc8a292d@redhat.com>

On 11/23/2017 01:48 PM, Florian Weimer wrote:
>>>> Using the malloc() analogy, we
>>>> don't expect that free() in one thread actively takes away references to
>>>> the memory held by other threads.
>>>
>>> But malloc/free isn't expected to be a partial antidote to random
>>> pointer scribbling.
>>
>> Nor is protection keys intended to be an antidote for use-after-free.
> 
> I'm comparing this to munmap, which is actually such an antidote 
> (because it involves an IPI to flush all CPUs which could have seen the 
> mapping before).
> 
> I'm surprised that pkey_free doesn't perform a similar broadcast.

Hmm, I'm not sure this comparison is accurate. IPI flushes in unmap are
done because the shared page tables were updated, and TLB's in other
cpu's might be stale. The closest pkey equivalent would be allocating a
new pkey that only my thread can use, and then using it in
pkey_mprotect() to change some memory region. Then other threads will
lose access and I believe IPI's will be issued and existing TLB mappings
in other cpu's removed.

pkey_remove() has AFAICS two potential problems:
- the key is still used in some page tables. Scanning them all and
resetting to 0 would be rather expensive. Maybe we could maintain
per-pkey counters (for pkey != 0) in the mm, which might not be that
expensive, and refuse pkey_free() if the counter is not zero?
- the key is still "used" by other threads in their PKRU. Here I would
think that if kernel doesn't broadcast pkey_alloc() to other threads, it
also shouldn't broadcast the freeing? We also can't track per-pkey
"threads using pkey" counters, as WRPKRU is pure userspace.

--
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>

  reply	other threads:[~2017-11-23 13:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-05 10:35 MPK: pkey_free and key reuse Florian Weimer
2017-11-08 20:41 ` Dave Hansen
2017-11-09 14:48   ` Florian Weimer
2017-11-09 16:59     ` Dave Hansen
2017-11-23 12:48       ` Florian Weimer
2017-11-23 13:07         ` Vlastimil Babka [this message]
2017-11-23 15:25         ` Dave Hansen
2017-11-24 14:55           ` Florian Weimer
     [not found] ` <0f006ef4-a7b5-c0cf-5f58-d0fd1f911a54-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-11-22  8:18   ` MPK: removing a pkey (was: pkey_free and key reuse) Vlastimil Babka
2017-11-22 12:15     ` MPK: removing a pkey Florian Weimer
2017-11-22 12:46       ` Vlastimil Babka
     [not found]         ` <f0495f01-9821-ec36-56b4-333f109eb761-AlSwsSmVLrQ@public.gmane.org>
2017-11-22 12:49           ` Florian Weimer
2017-11-22 16:10       ` Dave Hansen
2017-11-22 16:21         ` Florian Weimer
     [not found]           ` <9ec19ff3-86f6-7cfe-1a07-1ab1c5d9882c-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-11-22 16:32             ` Dave Hansen
2017-11-23  8:11               ` Vlastimil Babka
     [not found]                 ` <de93997a-7802-96cf-62e2-e59416e745ca-AlSwsSmVLrQ@public.gmane.org>
2017-11-23 15:00                   ` Dave Hansen
2017-11-23 21:42                     ` Vlastimil Babka
     [not found]                       ` <2d12777f-615a-8101-2156-cf861ec13aa7-AlSwsSmVLrQ@public.gmane.org>
2017-11-23 23:29                         ` Dave Hansen
2017-11-24  8:35                           ` Florian Weimer
2017-11-24  8:38                             ` Vlastimil Babka
2017-11-23 12:38               ` Florian Weimer
2017-11-23 15:09                 ` Dave Hansen

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=3c4aab06-af97-ccd2-ed51-a462ec251c65@suse.cz \
    --to=vbabka@suse.cz \
    --cc=dave.hansen@linux.intel.com \
    --cc=fweimer@redhat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-x86_64@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;
as well as URLs for NNTP newsgroup(s).