linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V1] fuse: Set fuse request error upon fuse abort connection
@ 2021-04-16 14:19 Pradeep P V K
  2021-05-10  7:52 ` pragalla
  2021-06-21  7:48 ` Miklos Szeredi
  0 siblings, 2 replies; 4+ messages in thread
From: Pradeep P V K @ 2021-04-16 14:19 UTC (permalink / raw)
  To: miklos; +Cc: stummala, linux-kernel, linux-fsdevel, Pradeep P V K

There is a minor race in setting the fuse out request error
between fuse_abort_conn() and fuse_dev_do_read() as explained
below.

Thread-1			  Thread-2
========			  ========
->fuse_simple_request()           ->shutdown
  ->__fuse_request_send()
    ->queue_request()		->fuse_abort_conn()
->fuse_dev_do_read()                ->acquire(fpq->lock)
  ->wait_for(fpq->lock) 	  ->set err to all req's in fpq->io
				  ->release(fpq->lock)
  ->acquire(fpq->lock)
  ->add req to fpq->io

The above scenario may cause Thread-1 request to add into
fpq->io list after Thread-2 sets -ECONNABORTED err to all
its requests in fpq->io list. This leaves Thread-1 request
with unset err and this further misleads as a completed
request without an err set upon request_end().

Handle this by setting the err appropriately.

Signed-off-by: Pradeep P V K <pragalla@codeaurora.org>
---
 fs/fuse/dev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index a5ceccc..102c56f 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1283,6 +1283,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
 	clear_bit(FR_LOCKED, &req->flags);
 	if (!fpq->connected) {
 		err = fc->aborted ? -ECONNABORTED : -ENODEV;
+		req->out.h.error = err;
 		goto out_end;
 	}
 	if (err) {
-- 
2.7.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V1] fuse: Set fuse request error upon fuse abort connection
  2021-04-16 14:19 [PATCH V1] fuse: Set fuse request error upon fuse abort connection Pradeep P V K
@ 2021-05-10  7:52 ` pragalla
  2021-05-10 14:05   ` Miklos Szeredi
  2021-06-21  7:48 ` Miklos Szeredi
  1 sibling, 1 reply; 4+ messages in thread
From: pragalla @ 2021-05-10  7:52 UTC (permalink / raw)
  To: miklos; +Cc: stummala, linux-kernel, linux-fsdevel

Hi Miklos,

Did you get a chance to look on the below change ?
could you please review and provide your comments if any.

Thanks and Regards,
Pradeep

On 2021-04-16 19:49, Pradeep P V K wrote:
> There is a minor race in setting the fuse out request error
> between fuse_abort_conn() and fuse_dev_do_read() as explained
> below.
> 
> Thread-1			  Thread-2
> ========			  ========
> ->fuse_simple_request()           ->shutdown
>   ->__fuse_request_send()
>     ->queue_request()		->fuse_abort_conn()
> ->fuse_dev_do_read()                ->acquire(fpq->lock)
>   ->wait_for(fpq->lock) 	  ->set err to all req's in fpq->io
> 				  ->release(fpq->lock)
>   ->acquire(fpq->lock)
>   ->add req to fpq->io
> 
> The above scenario may cause Thread-1 request to add into
> fpq->io list after Thread-2 sets -ECONNABORTED err to all
> its requests in fpq->io list. This leaves Thread-1 request
> with unset err and this further misleads as a completed
> request without an err set upon request_end().
> 
> Handle this by setting the err appropriately.
> 
> Signed-off-by: Pradeep P V K <pragalla@codeaurora.org>
> ---
>  fs/fuse/dev.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> index a5ceccc..102c56f 100644
> --- a/fs/fuse/dev.c
> +++ b/fs/fuse/dev.c
> @@ -1283,6 +1283,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev
> *fud, struct file *file,
>  	clear_bit(FR_LOCKED, &req->flags);
>  	if (!fpq->connected) {
>  		err = fc->aborted ? -ECONNABORTED : -ENODEV;
> +		req->out.h.error = err;
>  		goto out_end;
>  	}
>  	if (err) {

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V1] fuse: Set fuse request error upon fuse abort connection
  2021-05-10  7:52 ` pragalla
@ 2021-05-10 14:05   ` Miklos Szeredi
  0 siblings, 0 replies; 4+ messages in thread
From: Miklos Szeredi @ 2021-05-10 14:05 UTC (permalink / raw)
  To: pragalla; +Cc: Sahitya Tummala, linux-kernel, linux-fsdevel

On Mon, May 10, 2021 at 9:52 AM <pragalla@codeaurora.org> wrote:
>
> Hi Miklos,
>
> Did you get a chance to look on the below change ?
> could you please review and provide your comments if any.

Hi Pradeep,

Patch looks good at first glance.  Will review properly.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V1] fuse: Set fuse request error upon fuse abort connection
  2021-04-16 14:19 [PATCH V1] fuse: Set fuse request error upon fuse abort connection Pradeep P V K
  2021-05-10  7:52 ` pragalla
@ 2021-06-21  7:48 ` Miklos Szeredi
  1 sibling, 0 replies; 4+ messages in thread
From: Miklos Szeredi @ 2021-06-21  7:48 UTC (permalink / raw)
  To: Pradeep P V K; +Cc: stummala, linux-kernel, linux-fsdevel

On Fri, Apr 16, 2021 at 07:49:12PM +0530, Pradeep P V K wrote:
> There is a minor race in setting the fuse out request error
> between fuse_abort_conn() and fuse_dev_do_read() as explained
> below.
> 
> Thread-1			  Thread-2
> ========			  ========
> ->fuse_simple_request()           ->shutdown
>   ->__fuse_request_send()
>     ->queue_request()		->fuse_abort_conn()
> ->fuse_dev_do_read()                ->acquire(fpq->lock)
>   ->wait_for(fpq->lock) 	  ->set err to all req's in fpq->io
> 				  ->release(fpq->lock)
>   ->acquire(fpq->lock)
>   ->add req to fpq->io
> 
> The above scenario may cause Thread-1 request to add into
> fpq->io list after Thread-2 sets -ECONNABORTED err to all
> its requests in fpq->io list. This leaves Thread-1 request
> with unset err and this further misleads as a completed
> request without an err set upon request_end().
> 
> Handle this by setting the err appropriately.

The fix looks good, but still allows the request to block during the copy phase
after being aborted, which the FR_LOCKED/FR_ABORT bits are meant to prevent.

Here's an updated fix.  It does not allow the request to be queued on the
fpq->io list after fuse_abort_conn() has aborted requests on that list.

Can you verify that it fixes the race you reported?

Thanks,
Miklos


--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1272,6 +1272,15 @@ static ssize_t fuse_dev_do_read(struct f
 		goto restart;
 	}
 	spin_lock(&fpq->lock);
+	/*
+	 *  Must not put request on fpq->io queue after having been shut down by
+	 *  fuse_abort_conn()
+	 */
+	if (!fpq->connected) {
+		req->out.h.error = err = -ECONNABORTED;
+		goto out_end;
+
+	}
 	list_add(&req->list, &fpq->io);
 	spin_unlock(&fpq->lock);
 	cs->req = req;

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-21  7:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16 14:19 [PATCH V1] fuse: Set fuse request error upon fuse abort connection Pradeep P V K
2021-05-10  7:52 ` pragalla
2021-05-10 14:05   ` Miklos Szeredi
2021-06-21  7:48 ` Miklos Szeredi

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