ksmbd: avoid reclaiming expired durable opens by the client
Subsystems (2)
Namjae Jeon
maintainerPATCH 1/2 ksmbd: avoid reclaiming expired durable opens by the client
The expired durable opens should not be reclaimed by client. This patch add ->durable_scavenger_timeout to fp and check it in ksmbd_lookup_durable_fd().
--- fs/smb/server/vfs_cache.c | 9 ++++++++- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-)
fs/smb/server/vfs_cache.c +8 -1
@@ -476,7 +476,10 @@ struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id)struct ksmbd_file *fp; fp =__ksmbd_lookup_fd (&global_ft, id); -if (fp && fp->conn) { +if (fp && (fp->conn || + (fp->durable_scavenger_timeout && + (fp->durable_scavenger_timeout < +jiffies_to_msecs (jiffies))))) {ksmbd_put_durable_fd (fp); fp =NULL ; }
@@ -717,6 +720,10 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon, fp->tcon =NULL ; fp->volatile_id =KSMBD_NO_FID ; +if (fp->durable_timeout) + fp->durable_scavenger_timeout = +jiffies_to_msecs (jiffies) + fp->durable_timeout; +return true; }
fs/smb/server/vfs_cache.h +1 -0
@@ -101,6 +101,7 @@ struct ksmbd_file {struct list_head lock_list;int durable_timeout; +int durable_scavenger_timeout;/* if ls is happening on directory, below is valid*/ struct ksmbd_readdir_data readdir_data;
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 2/2 ksmbd: ignore trailing slashes in share paths
From: Nandor Kracser <[email protected]>
Trailing slashes in share paths (like: /home/me/Share/) caused permission issues with shares for clients on iOS and on Android TV for me, but otherwise they work fine with plain old Samba.
--- fs/smb/server/mgmt/share_config.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/server/mgmt/share_config.c +5 -1
@@ -165,8 +165,12 @@ static struct ksmbd_share_config *share_config_request(struct unicode_map *um, share->path =kstrndup (ksmbd_share_config_path (resp), path_len,GFP_KERNEL ); -if (share->path) +if (share->path) { share->path_sz =strlen (share->path); +while (share->path_sz >1 && + share->path[share->path_sz -1 ] =='/' ) + share->path[--share->path_sz] ='\0' ; + } share->create_mask = resp->create_mask; share->directory_mask = resp->directory_mask; share->force_create_mode = resp->force_create_mode;
Signature · 1 line
2.25.1
Tom Talpey
reviewerQuoted 15 lines · Namjae Jeon
The expired durable opens should not be reclaimed by client. This patch add ->durable_scavenger_timeout to fp and check it in
ksmbd_lookup_durable_fd().Signed-off-by Namjae Jeon <[email protected]>--- fs/smb/server/vfs_cache.c | 9 ++++++++- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-)fs/smb/server/vfs_cache.c +0
-0
fs/smb/server/vfs_cache.c struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id) · line 482
Quoted 8 lines
fs/smb/server/vfs_cache.c +4
-1@@ -476,7 +476,10 @@ struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id)struct ksmbd_file *fp; fp =__ksmbd_lookup_fd (&global_ft, id); -if (fp && fp->conn) { +if (fp && (fp->conn || + (fp->durable_scavenger_timeout && + (fp->durable_scavenger_timeout < +jiffies_to_msecs (jiffies))))) {
Do I understand correctly that this case means the fd is valid, and only the durable timeout has been exceeded?
If so, I believe it is overly strict behavior. MS-SMB2 specifically states that the timer is a lower bound:
Quoted 7 lines
3.3.2.2 Durable Open Scavenger Timer This timer controls the amount of time the server keeps a durable handle active after the underlying transport connection to the client is lost.<210> The server MUST keep the durable handle active for at least this amount of time, except in the cases of an oplock break indicated by the object store as specified in section 3.3.4.6, administrative actions, or resource constraints.
What defect does this patch fix?
Tom.
Quoted 26 lines
ksmbd_put_durable_fd(fp); fp = NULL; }fs/smb/server/vfs_cache.c +4
-0@@ -717,6 +720,10 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon, fp->tcon =NULL ; fp->volatile_id =KSMBD_NO_FID ; +if (fp->durable_timeout) + fp->durable_scavenger_timeout = +jiffies_to_msecs (jiffies) + fp->durable_timeout; +return true; }fs/smb/server/vfs_cache.h +1
-0@@ -101,6 +101,7 @@ struct ksmbd_file {struct list_head lock_list;int durable_timeout; +int durable_scavenger_timeout;/* if ls is happening on directory, below is valid*/ struct ksmbd_readdir_data readdir_data;
Namjae Jeon
maintainer2024년 5월 22일 (수) 오전 12:10, Tom Talpey <[email protected]>님이 작성:
Quoted 19 lines · Namjae Jeon
Quoted 17 lines
The expired durable opens should not be reclaimed by client. This patch add ->durable_scavenger_timeout to fp and check it in
ksmbd_lookup_durable_fd().Signed-off-by Namjae Jeon <[email protected]>--- fs/smb/server/vfs_cache.c | 9 ++++++++- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-)fs/smb/server/vfs_cache.c +0
-0@@ -476,7 +476,10 @@ struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id)struct ksmbd_file *fp;
Quoted 9 lines
fs/smb/server/vfs_cache.c struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id) · line 482
Quoted 6 lines
fs/smb/server/vfs_cache.c +4
-1fp =__ksmbd_lookup_fd (&global_ft, id); -if (fp && fp->conn) { +if (fp && (fp->conn || + (fp->durable_scavenger_timeout && + (fp->durable_scavenger_timeout < +jiffies_to_msecs (jiffies))))) {Do I understand correctly that this case means the fd is valid, and only the durable timeout has been exceeded?
Yes.
Quoted 4 lines
If so, I believe it is overly strict behavior. MS-SMB2 specifically states that the timer is a lower bound:
Quoted 8 lines
Quoted 7 lines
3.3.2.2 Durable Open Scavenger Timer This timer controls the amount of time the server keeps a durable handle active after the underlying transport connection to the client is lost.<210> The server MUST keep the durable handle active for at least this amount of time, except in the cases of an oplock break indicated by the object store as specified in section 3.3.4.6, administrative actions, or resource constraints.
What defect does this patch fix?
Durable open scavenger timer has not been added yet.
I will be adding this timer with this next patch. Nonetheless, this patch is needed.
i.e. we need both ones.
Thanks!
Quoted 30 lines
Tom.
Quoted 26 lines
ksmbd_put_durable_fd(fp); fp = NULL; }fs/smb/server/vfs_cache.c +4
-0@@ -717,6 +720,10 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon, fp->tcon =NULL ; fp->volatile_id =KSMBD_NO_FID ; +if (fp->durable_timeout) + fp->durable_scavenger_timeout = +jiffies_to_msecs (jiffies) + fp->durable_timeout; +return true; }fs/smb/server/vfs_cache.h +1
-0@@ -101,6 +101,7 @@ struct ksmbd_file {struct list_head lock_list;int durable_timeout; +int durable_scavenger_timeout;/* if ls is happening on directory, below is valid*/ struct ksmbd_readdir_data readdir_data;
Tom Talpey
reviewerQuoted 41 lines · Namjae Jeon
2024년 5월 22일 (수) 오전 12:10, Tom Talpey <[email protected]>님이 작성:
Quoted 19 lines · Namjae Jeon
Quoted 17 lines
The expired durable opens should not be reclaimed by client. This patch add ->durable_scavenger_timeout to fp and check it in
ksmbd_lookup_durable_fd().Signed-off-by Namjae Jeon <[email protected]>--- fs/smb/server/vfs_cache.c | 9 ++++++++- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-)fs/smb/server/vfs_cache.c +0
-0@@ -476,7 +476,10 @@ struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id)struct ksmbd_file *fp;Quoted 9 lines
fs/smb/server/vfs_cache.c struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id) · line 482
Quoted 6 lines
fs/smb/server/vfs_cache.c +4
-1fp =__ksmbd_lookup_fd (&global_ft, id); -if (fp && fp->conn) { +if (fp && (fp->conn || + (fp->durable_scavenger_timeout && + (fp->durable_scavenger_timeout < +jiffies_to_msecs (jiffies))))) {Do I understand correctly that this case means the fd is valid, and only the durable timeout has been exceeded?
Yes.
Quoted 11 lines
If so, I believe it is overly strict behavior. MS-SMB2 specifically states that the timer is a lower bound:
Quoted 7 lines
3.3.2.2 Durable Open Scavenger Timer This timer controls the amount of time the server keeps a durable handle active after the underlying transport connection to the client is lost.<210> The server MUST keep the durable handle active for at least this amount of time, except in the cases of an oplock break indicated by the object store as specified in section 3.3.4.6, administrative actions, or resource constraints.
Quoted 5 lines
Quoted 1 line
What defect does this patch fix?
Durable open scavenger timer has not been added yet.
I will be adding this timer with this next patch. Nonetheless, this patch is needed.
i.e. we need both ones.
So this code has no effect until then? And presumably, the scavenger will be closing the fd, so it won't have any effect later, either.
The patch should not be applied at this time, and the full change should be reviewed when it's ready.
Tom.
Quoted 32 lines
Thanks!
Quoted 30 lines
Tom.
Quoted 26 lines
ksmbd_put_durable_fd(fp); fp = NULL; }fs/smb/server/vfs_cache.c +4
-0@@ -717,6 +720,10 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon, fp->tcon =NULL ; fp->volatile_id =KSMBD_NO_FID ; +if (fp->durable_timeout) + fp->durable_scavenger_timeout = +jiffies_to_msecs (jiffies) + fp->durable_timeout; +return true; }fs/smb/server/vfs_cache.h +1
-0@@ -101,6 +101,7 @@ struct ksmbd_file {struct list_head lock_list;int durable_timeout; +int durable_scavenger_timeout;/* if ls is happening on directory, below is valid*/ struct ksmbd_readdir_data readdir_data;
Namjae Jeon
maintainer2024년 5월 23일 (목) 오전 4:47, Tom Talpey <[email protected]>님이 작성:
Quoted 43 lines · Namjae Jeon
Quoted 41 lines
2024년 5월 22일 (수) 오전 12:10, Tom Talpey <[email protected]>님이 작성:
Quoted 19 lines · Namjae Jeon
Quoted 17 lines
The expired durable opens should not be reclaimed by client. This patch add ->durable_scavenger_timeout to fp and check it in
ksmbd_lookup_durable_fd().Signed-off-by Namjae Jeon <[email protected]>--- fs/smb/server/vfs_cache.c | 9 ++++++++- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-)fs/smb/server/vfs_cache.c +0
-0@@ -476,7 +476,10 @@ struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id)struct ksmbd_file *fp;Quoted 9 lines
fs/smb/server/vfs_cache.c struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id) · line 482
Quoted 6 lines
fs/smb/server/vfs_cache.c +4
-1fp =__ksmbd_lookup_fd (&global_ft, id); -if (fp && fp->conn) { +if (fp && (fp->conn || + (fp->durable_scavenger_timeout && + (fp->durable_scavenger_timeout < +jiffies_to_msecs (jiffies))))) {Do I understand correctly that this case means the fd is valid, and only the durable timeout has been exceeded?
Yes.
Quoted 11 lines
If so, I believe it is overly strict behavior. MS-SMB2 specifically states that the timer is a lower bound:
Quoted 7 lines
3.3.2.2 Durable Open Scavenger Timer This timer controls the amount of time the server keeps a durable handle active after the underlying transport connection to the client is lost.<210> The server MUST keep the durable handle active for at least this amount of time, except in the cases of an oplock break indicated by the object store as specified in section 3.3.4.6, administrative actions, or resource constraints.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
What defect does this patch fix?
Durable open scavenger timer has not been added yet.
I will be adding this timer with this next patch. Nonetheless, this patch is needed.
i.e. we need both ones.So this code has no effect until then? And presumably, the scavenger will be closing the fd, so it won't have any effect later, either.
Not at all. We can first take steps to prevent the timeout of durable v2 open from being used. There is absolutely no harm in this.
Thanks.
Quoted 38 lines
The patch should not be applied at this time, and the full change should be reviewed when it's ready.
Tom.
Quoted 32 lines
Thanks!
Quoted 30 lines
Tom.
Quoted 26 lines
ksmbd_put_durable_fd(fp); fp = NULL; }fs/smb/server/vfs_cache.c +4
-0@@ -717,6 +720,10 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon, fp->tcon =NULL ; fp->volatile_id =KSMBD_NO_FID ; +if (fp->durable_timeout) + fp->durable_scavenger_timeout = +jiffies_to_msecs (jiffies) + fp->durable_timeout; +return true; }fs/smb/server/vfs_cache.h +1
-0@@ -101,6 +101,7 @@ struct ksmbd_file {struct list_head lock_list;int durable_timeout; +int durable_scavenger_timeout;/* if ls is happening on directory, below is valid*/ struct ksmbd_readdir_data readdir_data;
Tom Talpey
reviewerQuoted 50 lines · Namjae Jeon
2024년 5월 23일 (목) 오전 4:47, Tom Talpey <[email protected]>님이 작성:
Quoted 49 lines · Namjae Jeon
Quoted 46 lines
2024년 5월 22일 (수) 오전 12:10, Tom Talpey <[email protected]>님이 작성:
Quoted 19 lines · Namjae Jeon
Quoted 17 lines
The expired durable opens should not be reclaimed by client. This patch add ->durable_scavenger_timeout to fp and check it in
ksmbd_lookup_durable_fd().Signed-off-by Namjae Jeon <[email protected]>--- fs/smb/server/vfs_cache.c | 9 ++++++++- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-)fs/smb/server/vfs_cache.c +0
-0@@ -476,7 +476,10 @@ struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id)struct ksmbd_file *fp;Quoted 9 lines
fs/smb/server/vfs_cache.c struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id) · line 482
Quoted 6 lines
fs/smb/server/vfs_cache.c +4
-1fp =__ksmbd_lookup_fd (&global_ft, id); -if (fp && fp->conn) { +if (fp && (fp->conn || + (fp->durable_scavenger_timeout && + (fp->durable_scavenger_timeout < +jiffies_to_msecs (jiffies))))) {Do I understand correctly that this case means the fd is valid, and only the durable timeout has been exceeded?
Yes.
Quoted 4 lines
If so, I believe it is overly strict behavior. MS-SMB2 specifically states that the timer is a lower bound:
Quoted 8 lines
Quoted 7 lines
3.3.2.2 Durable Open Scavenger Timer This timer controls the amount of time the server keeps a durable handle active after the underlying transport connection to the client is lost.<210> The server MUST keep the durable handle active for at least this amount of time, except in the cases of an oplock break indicated by the object store as specified in section 3.3.4.6, administrative actions, or resource constraints.
What defect does this patch fix?
Durable open scavenger timer has not been added yet.
I will be adding this timer with this next patch. Nonetheless, this patch is needed.
i.e. we need both ones.
Quoted 4 lines
Quoted 2 lines
So this code has no effect until then? And presumably, the scavenger will be closing the fd, so it won't have any effect later, either.
Not at all. We can first take steps to prevent the timeout of durable v2 open from being used. There is absolutely no harm in this.
I disagree with "no harm".
As I said, the new behavior is more strict than MS-SMB2, and therefore also stricter than Windows behavior.
Additionally, in the absence of a yet-to-be-written scavenger, this means that fd's will remain cached and unclosed by ksmbd. The client, in turn, will reopen the file, which seems like a source of sharing violations, which become unrecallable in fact.
Finally, from a code standpoint, I still don't see why it's being added before the scavenger functionality is even ready to review.
Tom.
Quoted 40 lines
Thanks.
Quoted 38 lines
The patch should not be applied at this time, and the full change should be reviewed when it's ready.
Tom.
Quoted 32 lines
Thanks!
Quoted 30 lines
Tom.
Quoted 26 lines
ksmbd_put_durable_fd(fp); fp = NULL; }fs/smb/server/vfs_cache.c +4
-0@@ -717,6 +720,10 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon, fp->tcon =NULL ; fp->volatile_id =KSMBD_NO_FID ; +if (fp->durable_timeout) + fp->durable_scavenger_timeout = +jiffies_to_msecs (jiffies) + fp->durable_timeout; +return true; }fs/smb/server/vfs_cache.h +1
-0@@ -101,6 +101,7 @@ struct ksmbd_file {struct list_head lock_list;int durable_timeout; +int durable_scavenger_timeout;/* if ls is happening on directory, below is valid*/ struct ksmbd_readdir_data readdir_data;
Namjae Jeon
maintainer2024년 5월 23일 (목) 오후 10:36, Tom Talpey <[email protected]>님이 작성:
Quoted 59 lines · Namjae Jeon
Quoted 50 lines
2024년 5월 23일 (목) 오전 4:47, Tom Talpey <[email protected]>님이 작성:
Quoted 49 lines · Namjae Jeon
Quoted 46 lines
2024년 5월 22일 (수) 오전 12:10, Tom Talpey <[email protected]>님이 작성:
Quoted 19 lines · Namjae Jeon
Quoted 17 lines
The expired durable opens should not be reclaimed by client. This patch add ->durable_scavenger_timeout to fp and check it in
ksmbd_lookup_durable_fd().Signed-off-by Namjae Jeon <[email protected]>--- fs/smb/server/vfs_cache.c | 9 ++++++++- fs/smb/server/vfs_cache.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-)fs/smb/server/vfs_cache.c +0
-0@@ -476,7 +476,10 @@ struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id)struct ksmbd_file *fp;Quoted 9 lines
fs/smb/server/vfs_cache.c struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id) · line 482
Quoted 6 lines
fs/smb/server/vfs_cache.c +4
-1fp =__ksmbd_lookup_fd (&global_ft, id); -if (fp && fp->conn) { +if (fp && (fp->conn || + (fp->durable_scavenger_timeout && + (fp->durable_scavenger_timeout < +jiffies_to_msecs (jiffies))))) {Do I understand correctly that this case means the fd is valid, and only the durable timeout has been exceeded?
Yes.
Quoted 4 lines
If so, I believe it is overly strict behavior. MS-SMB2 specifically states that the timer is a lower bound:
Quoted 8 lines
Quoted 7 lines
3.3.2.2 Durable Open Scavenger Timer This timer controls the amount of time the server keeps a durable handle active after the underlying transport connection to the client is lost.<210> The server MUST keep the durable handle active for at least this amount of time, except in the cases of an oplock break indicated by the object store as specified in section 3.3.4.6, administrative actions, or resource constraints.
What defect does this patch fix?
Durable open scavenger timer has not been added yet.
I will be adding this timer with this next patch. Nonetheless, this patch is needed.
i.e. we need both ones.Quoted 4 lines
Quoted 2 lines
So this code has no effect until then? And presumably, the scavenger will be closing the fd, so it won't have any effect later, either.
Not at all. We can first take steps to prevent the timeout of durable v2 open from being used. There is absolutely no harm in this.
I disagree with "no harm".
Quoted 7 lines
As I said, the new behavior is more strict than MS-SMB2, and therefore also stricter than Windows behavior.
Additionally, in the absence of a yet-to-be-written scavenger, this means that fd's will remain cached and unclosed by ksmbd. The client, in turn, will reopen the file, which seems like a source of sharing violations, which become unrecallable in fact.
Okay, I understood your point. I will apply this patch with durable scavenger timer.
Quoted 3 lines
Finally, from a code standpoint, I still don't see why it's being added before the scavenger functionality is even ready to review.
Okay. Thanks for pointing this out:)
Quoted 43 lines
Tom.
Quoted 40 lines
Thanks.
Quoted 38 lines
The patch should not be applied at this time, and the full change should be reviewed when it's ready.
Tom.
Quoted 32 lines
Thanks!
Quoted 30 lines
Tom.
Quoted 26 lines
ksmbd_put_durable_fd(fp); fp = NULL; }fs/smb/server/vfs_cache.c +4
-0@@ -717,6 +720,10 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon, fp->tcon =NULL ; fp->volatile_id =KSMBD_NO_FID ; +if (fp->durable_timeout) + fp->durable_scavenger_timeout = +jiffies_to_msecs (jiffies) + fp->durable_timeout; +return true; }fs/smb/server/vfs_cache.h +1
-0@@ -101,6 +101,7 @@ struct ksmbd_file {struct list_head lock_list;int durable_timeout; +int durable_scavenger_timeout;/* if ls is happening on directory, below is valid*/ struct ksmbd_readdir_data readdir_data;