From: Andrew Morton <akpm@osdl.org>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: mingo@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] Futex non-page-pinning fix
Date: Tue, 26 Aug 2003 23:20:39 -0700 [thread overview]
Message-ID: <20030826232039.626f5a4c.akpm@osdl.org> (raw)
In-Reply-To: <20030827051853.181C92C0C1@lists.samba.org>
Rusty Russell <rusty@rustcorp.com.au> wrote:
>
> In message <20030825210606.5912bac4.akpm@osdl.org> you write:
> > But end_swap_bio_read() is called from interrupt context. Hence the
> > spinlock you have in there needs to become IRQ safe.
>
> OK, I've fixed that, with conservative assumptions (so it doesn't
> assume context). Or is _bh sufficient?
spin_lock_irq/irqsave is correct.
> > Two issues:
> >
> > a) what to do about futexes in file-backed pages? At present the
> > attacker can pin arbitrary amount of memory by backing it with a file.
>
> At present == 2.6.0-test4? In 2.6.0-test4, the attacker can pin one
> page per process (OK), or on per FD using FUTEX_FD (not OK). This
> patch changes it so that pages are *never* pinned, whatever is backing
> them.
oh, OK.
> > Your solution won't scale to solving this, because we need to perform
> > a futex lookup on every add_to_page_cache(). (Well, it will scale
> > fairly well because add_to_page_cache() is ratelimited by the IO speed.
> > But it will still suck quite a bit for some people).
>
> I assumed that for non-anonymous pages the mapping + index was always
> a unique identifier, even as they were swapped out. We need a
> persistent unique identifier for a page, OR a callback to
> unhash/rehash it when the identifier changes. Hence mapping + index
> where mapping != NULL, and the struct page and callbacks for swap
> pages. Using the callbacks for wherever else page->mapping changes is
> simple (but may be slow).
swap_writepage() and end_swap_bio_read() are not really companion
functions. The page is in use and may be mapped into user pagetables
during swap_writepage(). It won't actually be freed up for a very long
time, if at all.
I guess this means that there could be a large number of futexes which are
considered "swapped out" which are in fact not swapped out at all.
I'm starting to dimly understand what this code does. You get 2/10 for
patch explanation ;)
I think a better place to rehash the futex would be at the point where the
page is added to and removed from swapcache.
When the page is in swapcache it has stable ->mapping and ->index and can
be treated in the same way as file-backed MAP_SHARED memory.
If this works then the places to be looking are:
__delete_from_swap_cache(): page moves from swapcache to anon
add_to_swap(): page moves from anon to swapcache.
move_to_swap_cache(): file-backed to swapcache
move_from_swap_cache(): swapcache to file-backed.
The locking you have there in move_to_swap_cache() and
move_from_swap_cache() look wrong. Take move_to_swap_cache(): there is a
window in which the page has mapping==&swapper_space, but it is hashed over
in futex land by the old tmpfs mapping. A futex lookup which is concurrent
with move_to_swap_cache() will fail to find the futex.
I think that to resolve this you need to take futex_lock while swizzling
the mapping and index in move_to_swap_cache():
spin_lock(&swapper_space.page_lock);
spin_lock(&mapping->page_lock);
+ spin_lock(&futex_lock);
err = radix_tree_insert(&swapper_space.page_tree, entry.val, page);
if (!err) {
__remove_from_page_cache(page);
___add_to_page_cache(page, &swapper_space, entry.val);
+ __futex_rehash(page);
}
+ spin_unlock(&futex_lock);
spin_unlock(&mapping->page_lock);
spin_unlock(&swapper_space.page_lock);
Similarly, all places which change the page's hash keys (mapping and index)
need to be locked against the futex lookup code.
None of the above four functions are performance-critical; they already take
a ton of global locks.
Alternative: just use swapper_space.page_lock when you're doing futex
lookups. That will pin down the ->mapping and ->index of anonymous,
swapcache and tmpfs pages.
Please make sure it builds with CONFIG_SWAP=n
Please make sure it builds with CONFIG_FUTEX=n (sorry)
Please augment the lock ranking comment at the top of filemap.c
If a futex resides in a pagecache page which is then truncated, a
futex_wake() should really send the caller a SIGBUS; it looks like the code
will return -EFAULT, which is good enough. Any waiters on that futex will
not be wakeable, but they will be killable.
next prev parent reply other threads:[~2003-08-27 6:17 UTC|newest]
Thread overview: 102+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-26 3:12 Rusty Russell
2003-08-26 4:06 ` Andrew Morton
2003-08-26 5:30 ` Ingo Molnar
2003-08-26 5:50 ` Andrew Morton
2003-08-26 5:58 ` Ingo Molnar
2003-08-26 6:14 ` Andrew Morton
2003-08-26 6:36 ` Ingo Molnar
2003-08-26 7:02 ` Andrew Morton
2003-08-26 7:56 ` Arjan van de Ven
2003-08-26 8:08 ` Muli Ben-Yehuda
2003-08-26 8:11 ` Arjan van de Ven
2003-08-26 8:25 ` Andrew Morton
2003-08-26 9:02 ` Muli Ben-Yehuda
2003-08-26 10:38 ` William Lee Irwin III
2003-08-26 10:44 ` Andrew Morton
2003-08-26 10:45 ` William Lee Irwin III
2003-08-26 17:29 ` Andrew Morton
2003-08-26 19:35 ` William Lee Irwin III
2003-08-27 5:17 ` Rusty Russell
2003-08-27 6:20 ` Andrew Morton [this message]
2003-08-28 0:47 ` Rusty Russell
2003-08-28 8:21 ` Andrew Morton
2003-08-29 3:46 ` Rusty Russell
2003-08-29 4:17 ` Andrew Morton
2003-08-30 7:49 ` Rusty Russell
2003-09-01 0:35 ` Jamie Lokier
2003-09-01 4:11 ` Rusty Russell
2003-09-01 20:57 ` Hugh Dickins
2003-09-02 3:12 ` Rusty Russell
2003-09-02 6:51 ` Jamie Lokier
2003-09-02 16:14 ` Hugh Dickins
2003-09-02 19:54 ` Jamie Lokier
2003-09-02 20:15 ` Andrew Morton
2003-09-02 21:20 ` Jamie Lokier
2003-09-03 2:40 ` Rusty Russell
2003-09-03 7:36 ` [PATCH] Alternate futex non-page-pinning and COW fix Jamie Lokier
2003-09-03 11:19 ` Hugh Dickins
2003-09-03 14:38 ` Jamie Lokier
2003-09-03 17:39 ` Jamie Lokier
2003-09-03 17:55 ` Linus Torvalds
2003-09-03 18:06 ` Hugh Dickins
2003-09-03 18:19 ` Linus Torvalds
2003-09-03 18:43 ` Hugh Dickins
2003-09-03 19:05 ` Linus Torvalds
2003-09-03 19:40 ` Hugh Dickins
2003-09-03 20:04 ` Linus Torvalds
2003-09-04 2:43 ` Rusty Russell
2003-09-04 8:28 ` Linus Torvalds
2003-09-04 12:20 ` Hugh Dickins
2003-09-04 15:40 ` Linus Torvalds
2003-09-04 16:55 ` Hugh Dickins
2003-09-04 18:38 ` Jamie Lokier
2003-09-04 18:46 ` Linus Torvalds
2003-09-04 20:04 ` Jamie Lokier
2003-09-04 21:49 ` Linus Torvalds
2003-09-04 22:10 ` Jamie Lokier
2003-09-04 17:16 ` Jamie Lokier
2003-09-04 17:38 ` Linus Torvalds
2003-09-04 18:42 ` Linus Torvalds
2003-09-04 18:42 ` Linus Torvalds
2003-09-05 3:55 ` Rusty Russell
2003-09-05 17:55 ` Jamie Lokier
2003-09-04 17:26 ` Jamie Lokier
2003-09-04 1:30 ` Rusty Russell
2003-09-04 21:00 ` Jamie Lokier
2003-09-05 5:19 ` Rusty Russell
2003-09-05 20:54 ` Jamie Lokier
2003-09-07 6:45 ` Rusty Russell
2003-09-07 13:20 ` Jamie Lokier
2003-09-08 1:49 ` Rusty Russell
2003-09-08 9:44 ` Jamie Lokier
2003-09-03 14:40 ` [PATCH 2] Little fixes to previous futex patch Jamie Lokier
2003-09-04 16:45 ` Hugh Dickins
2003-09-04 17:59 ` Jamie Lokier
2003-09-04 18:35 ` Hugh Dickins
2003-09-04 20:11 ` Jamie Lokier
2003-09-04 21:36 ` Hugh Dickins
2003-09-04 21:58 ` Jamie Lokier
2003-09-07 7:23 ` Ingo Molnar
2003-09-07 12:27 ` Hugh Dickins
2003-09-07 15:03 ` Jamie Lokier
2003-09-08 1:56 ` Rusty Russell
2003-09-07 13:00 ` Jamie Lokier
2003-09-08 3:32 ` Ingo Molnar
2003-09-08 9:33 ` Jamie Lokier
2003-09-08 9:57 ` Ingo Molnar
2003-09-05 4:56 ` Rusty Russell
2003-09-03 15:34 ` [PATCH] Alternate futex non-page-pinning and COW fix Andrew Morton
2003-09-03 17:16 ` Jamie Lokier
2003-09-04 1:35 ` Rusty Russell
2003-09-04 17:35 ` Jamie Lokier
2003-09-03 0:14 ` [PATCH 2/2] Futex non-page-pinning fix Rusty Russell
2003-09-03 1:16 ` Andrew Morton
2003-09-03 1:54 ` Dave Hansen
2003-09-03 2:54 ` Andrew Morton
2003-09-02 3:23 ` Hugh Dickins
2003-09-02 23:58 ` Rusty Russell
2003-08-27 8:37 ` Hugh Dickins
2003-08-27 8:56 ` William Lee Irwin III
2003-08-27 10:38 ` Andrew Morton
2003-08-27 10:57 ` Hugh Dickins
2003-08-28 8:03 ` Rusty Russell
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=20030826232039.626f5a4c.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rusty@rustcorp.com.au \
/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
all inboxes | Powered by JetHome®