From: Miklos Szeredi <miklos@szeredi.hu>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Linux NFS list <linux-nfs@vger.kernel.org>,
ceph-devel@vger.kernel.org, lustre-devel@lists.lustre.org,
v9fs-developer@lists.sourceforge.net,
Linus Torvalds <torvalds@linux-foundation.org>,
Jan Kara <jack@suse.cz>, Chris Wilson <chris@chris-wilson.co.uk>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Jeff Layton <jlayton@redhat.com>
Subject: Re: [PATCH v3 0/2] iov_iter: allow iov_iter_get_pages_alloc to allocate more pages per call
Date: Mon, 6 Feb 2017 09:37:12 +0100 [thread overview]
Message-ID: <CAJfpegtPELcLY_zGufhhfEYXAmmDsKnxexUyhsQFCQgZfuSY1A@mail.gmail.com> (raw)
In-Reply-To: <20170205220445.GE13195@ZenIV.linux.org.uk>
On Sun, Feb 5, 2017 at 11:04 PM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Sun, Feb 05, 2017 at 10:19:20PM +0100, Miklos Szeredi wrote:
>
>> Then we can't break out of that deadlock: we wait until
>> fuse_dev_do_write() is done until calling request_end() which
>> ultimately results in unlocking page. But fuse_dev_do_write() won't
>> complete until the page is unlocked.
>
> Wait a sec. What happens if
>
> process A: fuse_lookup()
> struct fuse_entry_out outarg on stack
> ...
> fuse_request_send() with req->out.args[0].value = &outarg
> sleep in request_wait_answer() on req->waitq
> server: read the request, write reply
> fuse_dev_do_write()
> copy_out_args()
> fuse_copy_args()
> fuse_copy_one()
> FR_LOCKED is guaranteed to be set
> fuse_copy_do()
> process C on another CPU: umount -f
> fuse_conn_abort()
> end_requests()
> request_end()
> set FR_FINISHED
> wake A up (via req->waitq)
> process A: regain CPU
> bugger off from request_wait_answer(), through __fuse_request_send(),
> fuse_request_send(), fuse_simple_request(), fuse_lookup_name(),
> fuse_lookup() and out of fuse_lookup().
>
> In the meanwhile, server in fuse_copy_do() does memcpy() to what used to
> be outarg, corrupting the stack of process A.
>
> Sure, you need to hit a fairly narrow window, especially if you are to
> cause damage in A, but AFAICS it's not impossible. Consider e.g. the
> situation when you lose CPU on preempt on the way to memcpy(); in that
> case server might come back when A has incremented its stack footprint
> again. Or A might end up taking a hardware interrupt and handling it
> on the normal kernel stack, etc.
>
> Looks like *any* scenario where fuse_conn_abort() manages to run during
> that memcpy() has potential for that kind of trouble; any SMP box appears
> to be vulnerable, along with preempt UP...
>
> Am I missing something that prevents that kind of problem?
Yes: if FR_LOCKED is set, then we leave the request alone in
fuse_abort_conn(). Then, when the copy is finished and
request_unlock() is called, we return -ENOENT to fuse_dev_do_write(),
which in turn calls request_end() to wake up the original caller,
which gets -ECONNABORTED.
So basically FR_LOCKED is protecting the copy, which is guaranteed to
be atomic due to the get_user_pages magic that faults in all pages
beforehand.
Thanks,
Miklos
next prev parent reply other threads:[~2017-02-06 8:37 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-24 21:23 [PATCH] iov_iter: allow iov_iter_get_pages_alloc to allocate more pages per call Jeff Layton
2017-01-25 13:32 ` [PATCH v3 0/2] " Jeff Layton
2017-01-25 13:32 ` [PATCH v3 1/2] " Jeff Layton
2017-01-26 12:35 ` Jeff Layton
2017-01-27 13:24 ` [PATCH v4 0/2] " Jeff Layton
2017-01-27 13:24 ` [PATCH v4 1/2] " Jeff Layton
2017-01-27 13:24 ` [PATCH v4 2/2] ceph: switch DIO code to use iov_iter_get_pages_alloc Jeff Layton
2017-01-30 15:40 ` Jeff Layton
2017-01-25 13:32 ` [PATCH v3 " Jeff Layton
2017-02-02 9:51 ` [PATCH v3 0/2] iov_iter: allow iov_iter_get_pages_alloc to allocate more pages per call Al Viro
2017-02-02 10:56 ` Christoph Hellwig
2017-02-02 11:16 ` Al Viro
2017-02-02 13:00 ` Jeff Layton
2017-02-03 7:29 ` Al Viro
2017-02-03 18:29 ` Linus Torvalds
2017-02-03 19:08 ` Al Viro
2017-02-03 19:28 ` Linus Torvalds
2017-02-13 9:56 ` Steve Capper
2017-02-13 21:40 ` Linus Torvalds
2017-02-03 7:49 ` Christoph Hellwig
2017-02-03 8:54 ` Al Viro
2017-02-03 11:09 ` Christoph Hellwig
2017-02-02 14:48 ` Jan Kara
2017-02-02 18:28 ` Al Viro
2017-02-03 14:47 ` Jan Kara
2017-02-04 3:08 ` Al Viro
2017-02-04 19:26 ` Al Viro
2017-02-04 22:12 ` Miklos Szeredi
2017-02-04 22:11 ` Miklos Szeredi
2017-02-05 1:51 ` Al Viro
2017-02-05 20:15 ` Miklos Szeredi
2017-02-05 21:01 ` Al Viro
2017-02-05 21:19 ` Miklos Szeredi
2017-02-05 22:04 ` Al Viro
2017-02-06 3:05 ` Al Viro
2017-02-06 9:08 ` Miklos Szeredi
2017-02-06 9:57 ` Al Viro
2017-02-06 14:18 ` Miklos Szeredi
2017-02-07 7:19 ` Al Viro
2017-02-07 11:35 ` Miklos Szeredi
2017-02-08 5:54 ` Al Viro
2017-02-08 9:53 ` Miklos Szeredi
2017-02-06 8:37 ` Miklos Szeredi [this message]
2017-02-05 20:56 ` Al Viro
2017-02-16 13:10 ` Jeff Layton
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=CAJfpegtPELcLY_zGufhhfEYXAmmDsKnxexUyhsQFCQgZfuSY1A@mail.gmail.com \
--to=miklos@szeredi.hu \
--cc=ceph-devel@vger.kernel.org \
--cc=chris@chris-wilson.co.uk \
--cc=jack@suse.cz \
--cc=jlayton@redhat.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=lustre-devel@lists.lustre.org \
--cc=torvalds@linux-foundation.org \
--cc=v9fs-developer@lists.sourceforge.net \
--cc=viro@zeniv.linux.org.uk \
/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).