linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve French <smfrench@gmail.com>
To: Pavel Shilovsky <piastryyy@gmail.com>
Cc: Ronnie Sahlberg <lsahlber@redhat.com>,
	linux-cifs <linux-cifs@vger.kernel.org>
Subject: Re: [PATCH] cifs: don't leak -EAGAIN for stat() during reconnect
Date: Mon, 24 Feb 2020 14:22:09 -0600	[thread overview]
Message-ID: <CAH2r5ms35H2miJ=tHFXQfAfoD0AE+CxX8xhVMrJWmK9sG_Z6Vw@mail.gmail.com> (raw)
In-Reply-To: <CAKywueSsso_n_KM5qv9kuLVEPyjUaqh3u973EJ_+RLRaGwBFtg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2897 bytes --]

updated Ronnie's patch and remerged to cifs-2.6.git for-next

Let me know if any objections

On Mon, Feb 24, 2020 at 1:36 PM Pavel Shilovsky <piastryyy@gmail.com> wrote:
>
> вт, 18 февр. 2020 г. в 15:27, Steve French <smfrench@gmail.com>:
> >
> > merged into cifs-2.6.git for-next
> >
> > On Tue, Feb 18, 2020 at 2:07 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
> > >
> > > If from cifs_revalidate_dentry_attr() the SMB2/QUERY_INFO call fails with an
> > > error, such as STATUS_SESSION_EXPIRED, causing the session to be reconnected
> > > it is possible we will leak -EAGAIN back to the application even for
> > > system calls such as stat() where this is not a valid error.
> > >
> > > Fix this by re-trying the operation from within cifs_revalidate_dentry_attr()
> > > if cifs_get_inode_info*() returns -EAGAIN.
> > >
> > > This fixes stat() and possibly also other system calls that uses
> > > cifs_revalidate_dentry*().
> > >
> > > Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> > > ---
> > >  fs/cifs/inode.c | 6 +++++-
> > >  1 file changed, 5 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
> > > index b5e6635c578e..1212ace05258 100644
> > > --- a/fs/cifs/inode.c
> > > +++ b/fs/cifs/inode.c
> > > @@ -2073,6 +2073,7 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)
> > >         struct inode *inode = d_inode(dentry);
> > >         struct super_block *sb = dentry->d_sb;
> > >         char *full_path = NULL;
> > > +       int count = 0;
> > >
> > >         if (inode == NULL)
> > >                 return -ENOENT;
> > > @@ -2094,15 +2095,18 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)
> > >                  full_path, inode, inode->i_count.counter,
> > >                  dentry, cifs_get_time(dentry), jiffies);
> > >
> > > +again:
> > >         if (cifs_sb_master_tcon(CIFS_SB(sb))->unix_ext)
> > >                 rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid);
> > >         else
> > >                 rc = cifs_get_inode_info(&inode, full_path, NULL, sb,
> > >                                          xid, NULL);
> > > -
> > > +       if (is_retryable_error(rc) && count++ < 10)
> > > +               goto again;
>
> If there is interrupt error, you will end up doing 10 attempts with
> the same outcome - interrupt error. Such errors should be returned to
> the upper layers to be handled correctly (restart of a system call or
> return of EINTR error to the user space).
>
> Please revert to your original version that handles EAGAIN only.
>
> --
> Best regards,
> Pavel Shilovsky
>
> > >  out:
> > >         kfree(full_path);
> > >         free_xid(xid);
> > > +
> > >         return rc;
> > >  }
> > >
> > > --
> > > 2.13.6
> > >
> >
> >
> > --
> > Thanks,
> >
> > Steve



-- 
Thanks,

Steve

[-- Attachment #2: 0001-cifs-don-t-leak-EAGAIN-for-stat-during-reconnect.patch --]
[-- Type: text/x-patch, Size: 1931 bytes --]

From 9255f1c5788c0d97d0ef31b0fabb6457787ce680 Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <lsahlber@redhat.com>
Date: Wed, 19 Feb 2020 06:01:03 +1000
Subject: [PATCH 01/10] cifs: don't leak -EAGAIN for stat() during reconnect

If from cifs_revalidate_dentry_attr() the SMB2/QUERY_INFO call fails with an
error, such as STATUS_SESSION_EXPIRED, causing the session to be reconnected
it is possible we will leak -EAGAIN back to the application even for
system calls such as stat() where this is not a valid error.

Fix this by re-trying the operation from within cifs_revalidate_dentry_attr()
if cifs_get_inode_info*() returns -EAGAIN.

This fixes stat() and possibly also other system calls that uses
cifs_revalidate_dentry*().

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
CC: Stable <stable@vger.kernel.org>
---
 fs/cifs/inode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index b5e6635c578e..1212ace05258 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -2073,6 +2073,7 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)
 	struct inode *inode = d_inode(dentry);
 	struct super_block *sb = dentry->d_sb;
 	char *full_path = NULL;
+	int count = 0;
 
 	if (inode == NULL)
 		return -ENOENT;
@@ -2094,15 +2095,18 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)
 		 full_path, inode, inode->i_count.counter,
 		 dentry, cifs_get_time(dentry), jiffies);
 
+again:
 	if (cifs_sb_master_tcon(CIFS_SB(sb))->unix_ext)
 		rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid);
 	else
 		rc = cifs_get_inode_info(&inode, full_path, NULL, sb,
 					 xid, NULL);
-
+	if (rc == -EAGAIN && count++ < 10)
+		goto again;
 out:
 	kfree(full_path);
 	free_xid(xid);
+
 	return rc;
 }
 
-- 
2.20.1


  reply	other threads:[~2020-02-24 20:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-18 20:01 [PATCH] cifs: don't leak -EAGAIN for stat() during reconnect Ronnie Sahlberg
2020-02-18 23:26 ` Steve French
2020-02-24 19:36   ` Pavel Shilovsky
2020-02-24 20:22     ` Steve French [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-02-18  4:48 Ronnie Sahlberg
2020-02-18 11:47 ` Aurélien Aptel
2020-02-18 19:58   ` ronnie sahlberg
2020-02-18  4:18 [PATCH 0/1] dont leak -EAGAIN Ronnie Sahlberg
2020-02-18  4:18 ` [PATCH] cifs: don't leak -EAGAIN for stat() during reconnect Ronnie Sahlberg

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='CAH2r5ms35H2miJ=tHFXQfAfoD0AE+CxX8xhVMrJWmK9sG_Z6Vw@mail.gmail.com' \
    --to=smfrench@gmail.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=lsahlber@redhat.com \
    --cc=piastryyy@gmail.com \
    /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).