Skip to contentSkip to conversation

cifs: don't leak -EAGAIN for stat() during reconnect

PATCH Applied Ronnie Sahlberg 3 participants 4 messages Feb 18, 2020 – Feb 24, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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*().

---
 fs/cifs/inode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/cifs/inode.c +5 -1
index b5e6635c578e..1212ace05258 100644
@@ -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;
 out:
 	kfree(full_path);
 	free_xid(xid);
+
 	return rc;
 }
 
Signature · 1 line
2.13.6
Applied
#1 lore raw

merged into cifs-2.6.git for-next

Quoted 52 lines · Ronnie Sahlberg

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

---
 fs/cifs/inode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/cifs/inode.c +5 -2
index b5e6635c578e..1212ace05258 100644
@@ -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;
 out:
        kfree(full_path);
        free_xid(xid);
+
        return rc;
 }
 
--

2.13.6

Signature · 3 lines
Thanks,

Steve
#2 lore raw

вт, 18 февр. 2020 г. в 15:27, Steve French <[email protected]>:

Quoted 37 lines

merged into cifs-2.6.git for-next

Quoted 33 lines · Ronnie Sahlberg

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

---
 fs/cifs/inode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/cifs/inode.c +1 -0
index b5e6635c578e..1212ace05258 100644
@@ -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);
 
Quoted 9 lines

fs/cifs/inode.c int cifs_revalidate_dentry_attr(struct dentry *dentry) · line 2105

Quoted 9 lines
fs/cifs/inode.c +3 -1
+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

Quoted 16 lines
Quoted 10 lines
fs/cifs/inode.c +1 -1
 out:
        kfree(full_path);
        free_xid(xid);
+
        return rc;
 }
 
--

2.13.6

--
Thanks,

Steve

Reviewed-by Pavel Shilovsky Reviewed-by Aurelien Aptel
#3 lore raw

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

Let me know if any objections

Quoted 76 lines · Pavel Shilovsky

вт, 18 февр. 2020 г. в 15:27, Steve French <[email protected]>:

Quoted 37 lines

merged into cifs-2.6.git for-next

Quoted 33 lines · Ronnie Sahlberg

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

---
 fs/cifs/inode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/cifs/inode.c +1 -0
index b5e6635c578e..1212ace05258 100644
@@ -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);
 
Quoted 9 lines

fs/cifs/inode.c int cifs_revalidate_dentry_attr(struct dentry *dentry) · line 2105

Quoted 9 lines
fs/cifs/inode.c +3 -1
+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

Quoted 16 lines
Quoted 10 lines
fs/cifs/inode.c +1 -1
 out:
        kfree(full_path);
        free_xid(xid);
+
        return rc;
 }
 
--

2.13.6

--
Thanks,

Steve

Signature · 3 lines
Thanks,

Steve

From 9255f1c5788c0d97d0ef31b0fabb6457787ce680 Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <[email protected]>
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*().

---
 fs/cifs/inode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/cifs/inode.c +5 -1
index b5e6635c578e..1212ace05258 100644
@@ -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;
 }
 
Signature · 1 line
2.20.1