linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Moyer <jmoyer@redhat.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	 Benjamin LaHaise <bcrl@kvack.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	 Kees Cook <keescook@chromium.org>,
	 linux-fsdevel@vger.kernel.org,  linux-aio@kvack.org,
	 linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	 Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH] aio: Convert ioctx_table to XArray
Date: Tue, 11 Dec 2018 12:21:52 -0500	[thread overview]
Message-ID: <x49mupcm11r.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <x49pnuee1gm.fsf@segfault.boston.devel.redhat.com> (Jeff Moyer's message of "Thu, 06 Dec 2018 17:26:33 -0500")

Jeff Moyer <jmoyer@redhat.com> writes:

> Jeff Moyer <jmoyer@redhat.com> writes:
>
>> Matthew Wilcox <willy@infradead.org> writes:
>>
>>> This custom resizing array was vulnerable to a Spectre attack (speculating
>>> off the end of an array to a user-controlled offset).  The XArray is
>>> not vulnerable to Spectre as it always masks its lookups to be within
>>> the bounds of the array.
>>
>> I'm not a big fan of completely re-writing the code to fix this.  Isn't
>> the below patch sufficient?
>
> Too quick on the draw.  Here's a patch that compiles.  ;-)

Hi, Matthew,

I'm going to submit this version formally.  If you're interested in
converting the ioctx_table to xarray, you can do that separately from a
security fix.  I would include a performance analysis with that patch,
though.  The idea of using a radix tree for the ioctx table was
discarded due to performance reasons--see commit db446a08c23d5 ("aio:
convert the ioctx list to table lookup v3").  I suspect using the xarray
will perform similarly.

Cheers,
Jeff

> diff --git a/fs/aio.c b/fs/aio.c
> index 97f983592925..aac9659381d2 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -45,6 +45,7 @@
>  
>  #include <asm/kmap_types.h>
>  #include <linux/uaccess.h>
> +#include <linux/nospec.h>
>  
>  #include "internal.h"
>  
> @@ -1038,6 +1039,7 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id)
>  	if (!table || id >= table->nr)
>  		goto out;
>  
> +	id = array_index_nospec(id, table->nr);
>  	ctx = rcu_dereference(table->table[id]);
>  	if (ctx && ctx->user_id == ctx_id) {
>  		if (percpu_ref_tryget_live(&ctx->users))
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-aio' in
> the body to majordomo@kvack.org.  For more info on Linux AIO,
> see: http://www.kvack.org/aio/
> Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

  reply	other threads:[~2018-12-11 17:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28 18:35 [PATCH] aio: Convert ioctx_table to XArray Matthew Wilcox
2018-12-06 21:08 ` Matthew Wilcox
2018-12-06 22:21 ` Jeff Moyer
2018-12-06 22:26   ` Jeff Moyer
2018-12-11 17:21     ` Jeff Moyer [this message]
2018-12-11 17:51       ` Matthew Wilcox
2018-12-11 18:02         ` Jeff Moyer
2018-12-11 18:05           ` Jens Axboe
2018-12-11 18:09             ` Jeff Moyer
2018-12-11 18:37               ` Jens Axboe
2018-12-11 18:32             ` Jens Axboe
2018-12-11 18:36               ` Jens Axboe
2018-12-11 18:51               ` Matthew Wilcox
2018-12-11 18:52                 ` Jens Axboe
2018-12-11 18:41 ` Jens Axboe
2018-12-11 18:45   ` Matthew Wilcox
2018-12-11 18:46     ` Jens Axboe
2018-12-11 18:53       ` Matthew Wilcox
2018-12-11 18:54         ` Jens Axboe
2018-12-11 18:53       ` Jens Axboe

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=x49mupcm11r.fsf@segfault.boston.devel.redhat.com \
    --to=jmoyer@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bcrl@kvack.org \
    --cc=dan.carpenter@oracle.com \
    --cc=keescook@chromium.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.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).