cifs: update the same create_guid on replay
Subsystems (2)
PATCH 1/1 cifs: update the same create_guid on replay
From: Shyam Prasad N <[email protected]>
File open requests made to the server contain a CreateGuid, which is used by the server to identify the open request. If the same request needs to be replayed, it needs to be sent with the same CreateGuid in the durable handle v2 context.
Without doing so, we could end up leaking handles on the server when:
1. multichannel is used AND
2. connection goes down, but not for all channels
This is because the replayed open request would have a new CreateGuid and the server will treat this as a new request and open a new handle.
This change fixes this by reusing the existing create_guid stored in the cached fid struct.
REF: MS-SMB2 4.9 Replay Create Request on an Alternate Channel
--- fs/smb/client/cached_dir.c | 1 + fs/smb/client/cifsglob.h | 1 + fs/smb/client/smb2inode.c | 1 + fs/smb/client/smb2ops.c | 4 ++++ fs/smb/client/smb2pdu.c | 10 ++++++++-- 5 files changed, 15 insertions(+), 2 deletions(-)
fs/smb/client/cached_dir.c +1 -0
@@ -242,6 +242,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, .desired_access = FILE_READ_DATA | FILE_READ_ATTRIBUTES, .disposition = FILE_OPEN, .fid = pfid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
fs/smb/client/cifsglob.h +1 -0
@@ -1373,6 +1373,7 @@ struct cifs_open_parms {struct cifs_fid *fid;umode_t mode; bool reconnect:1; + bool replay:1; /* indicates that this open is for a replay */struct kvec *ea_cctx; };
fs/smb/client/smb2inode.c +1 -0
@@ -203,6 +203,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, oplock =SMB2_OPLOCK_LEVEL_NONE ; num_rqst =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries); vars =kzalloc (sizeof (*vars),GFP_ATOMIC );if (vars ==NULL )
fs/smb/client/smb2ops.c +4 -0
@@ -1205,6 +1205,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
@@ -1570,6 +1571,7 @@ smb2_ioctl_query_info(const unsigned int xid, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, create_options), .fid = &fid, + .replay = !!(retries), };if (qi.flags &PASSTHRU_FSCTL ) {
@@ -2296,6 +2298,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
@@ -2682,6 +2685,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
fs/smb/client/smb2pdu.c +8 -2
@@ -2406,8 +2406,13 @@ create_durable_v2_buf(struct cifs_open_parms *oparms)*/ buf->dcontext.Timeout =cpu_to_le32 (oparms->tcon->handle_timeout); buf->dcontext.Flags =cpu_to_le32 (SMB2_DHANDLE_FLAG_PERSISTENT ); -generate_random_uuid (buf->dcontext.CreateGuid); -memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + +/* for replay, we should not overwrite the existing create guid */ +if (!oparms->replay) { +generate_random_uuid (buf->dcontext.CreateGuid); +memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + }else +memcpy (buf->dcontext.CreateGuid, pfid->create_guid,16 );/* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */ buf->Name[0 ] ='D' ;
@@ -3156,6 +3161,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,/* reinitialize for possible replay */ flags =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries);cifs_dbg (FYI ,"create/open\n" );if (!ses || !server)
Signature · 1 line
2.34.1
It needed a small rebase to work around one of Paulo's patches which it depended on (which is for 6.9-rc) but was wondering if you want this patch in before 6.9 because its change to smb2_compound_op below has a dependency on another patch - can that change be safely removed?
replay_again:
/* reinitialize for possible replay */
flags = 0;
oplock = SMB2_OPLOCK_LEVEL_NONE;
num_rqst = 0;
server = cifs_pick_channel(ses);
oparms->replay = !!(retries);Quoted 136 lines · On Fri, Feb 9, 2024 at 5:25 AM <[email protected]> wrote:
From: Shyam Prasad N <[email protected]>
File open requests made to the server contain a CreateGuid, which is used by the server to identify the open request. If the same request needs to be replayed, it needs to be sent with the same CreateGuid in the durable handle v2 context.
Without doing so, we could end up leaking handles on the server when:
1. multichannel is used AND
2. connection goes down, but not for all channelsThis is because the replayed open request would have a new CreateGuid and the server will treat this as a new request and open a new handle.
This change fixes this by reusing the existing
create_guidstored in the cached fid struct.REF: MS-SMB2 4.9 Replay Create Request on an Alternate Channel
Fixes 4f1fffa23769 ("cifs: commands that are retried should have replay flag set")Signed-off-by Shyam Prasad N <[email protected]>--- fs/smb/client/cached_dir.c | 1 + fs/smb/client/cifsglob.h | 1 + fs/smb/client/smb2inode.c | 1 + fs/smb/client/smb2ops.c | 4 ++++ fs/smb/client/smb2pdu.c | 10 ++++++++-- 5 files changed, 15 insertions(+), 2 deletions(-)fs/smb/client/cached_dir.c +1
-0@@ -242,6 +242,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, .desired_access = FILE_READ_DATA | FILE_READ_ATTRIBUTES, .disposition = FILE_OPEN, .fid = pfid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,fs/smb/client/cifsglob.h +1
-0@@ -1373,6 +1373,7 @@ struct cifs_open_parms {struct cifs_fid *fid;umode_t mode; bool reconnect:1; + bool replay:1; /* indicates that this open is for a replay */struct kvec *ea_cctx; };fs/smb/client/smb2inode.c +1
-0@@ -203,6 +203,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, oplock =SMB2_OPLOCK_LEVEL_NONE ; num_rqst =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries); vars =kzalloc (sizeof (*vars),GFP_ATOMIC );if (vars ==NULL )fs/smb/client/smb2ops.c +4
-0@@ -1205,6 +1205,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,@@ -1570,6 +1571,7 @@ smb2_ioctl_query_info(const unsigned int xid, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, create_options), .fid = &fid, + .replay = !!(retries), };if (qi.flags &PASSTHRU_FSCTL ) {@@ -2296,6 +2298,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,@@ -2682,6 +2685,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,fs/smb/client/smb2pdu.c +8
-3@@ -2406,8 +2406,13 @@ create_durable_v2_buf(struct cifs_open_parms *oparms)*/ buf->dcontext.Timeout =cpu_to_le32 (oparms->tcon->handle_timeout); buf->dcontext.Flags =cpu_to_le32 (SMB2_DHANDLE_FLAG_PERSISTENT ); -generate_random_uuid (buf->dcontext.CreateGuid); -memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + +/* for replay, we should not overwrite the existing create guid */ +if (!oparms->replay) { +generate_random_uuid (buf->dcontext.CreateGuid); +memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + }else +memcpy (buf->dcontext.CreateGuid, pfid->create_guid,16 );/* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */ buf->Name[0 ] ='D' ;@@ -3156,6 +3161,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,/* reinitialize for possible replay */ flags =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries);cifs_dbg (FYI ,"create/open\n" );if (!ses || !server) --2.34.1
Signature · 3 lines
Thanks, Steve
From 65774929fcabe8492a2b3886574ab1495a13f7e6 Mon Sep 17 00:00:00 2001
From: Shyam Prasad N <[email protected]>
Date: Fri, 9 Feb 2024 11:25:42 +0000
Subject: [PATCH] cifs: update the same create_guid on replay
File open requests made to the server contain a CreateGuid, which is used by the server to identify the open request. If the same request needs to be replayed, it needs to be sent with the same CreateGuid in the durable handle v2 context.
Without doing so, we could end up leaking handles on the server when:
1. multichannel is used AND
2. connection goes down, but not for all channels
This is because the replayed open request would have a new CreateGuid and the server will treat this as a new request and open a new handle.
This change fixes this by reusing the existing create_guid stored in the cached fid struct.
REF: MS-SMB2 4.9 Replay Create Request on an Alternate Channel
--- fs/smb/client/cached_dir.c | 1 + fs/smb/client/cifsglob.h | 1 + fs/smb/client/smb2inode.c | 1 + fs/smb/client/smb2ops.c | 4 ++++ fs/smb/client/smb2pdu.c | 10 ++++++++-- 5 files changed, 15 insertions(+), 2 deletions(-)
fs/smb/client/cached_dir.c +1 -0
@@ -242,6 +242,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, .desired_access = FILE_READ_DATA | FILE_READ_ATTRIBUTES, .disposition = FILE_OPEN, .fid = pfid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
fs/smb/client/cifsglob.h +1 -0
@@ -1378,6 +1378,7 @@ struct cifs_open_parms {struct cifs_fid *fid;umode_t mode; bool reconnect:1; + bool replay:1; /* indicates that this open is for a replay */ };struct cifs_fid {
fs/smb/client/smb2inode.c +1 -0
@@ -128,6 +128,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, oplock =SMB2_OPLOCK_LEVEL_NONE ; num_rqst =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries); vars =kzalloc (sizeof (*vars),GFP_ATOMIC );if (vars ==NULL )
fs/smb/client/smb2ops.c +4 -0
@@ -1204,6 +1204,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
@@ -1569,6 +1570,7 @@ smb2_ioctl_query_info(const unsigned int xid, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, create_options), .fid = &fid, + .replay = !!(retries), };if (qi.flags &PASSTHRU_FSCTL ) {
@@ -2295,6 +2297,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
@@ -2681,6 +2684,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
fs/smb/client/smb2pdu.c +8 -2
@@ -2404,8 +2404,13 @@ create_durable_v2_buf(struct cifs_open_parms *oparms)*/ buf->dcontext.Timeout =cpu_to_le32 (oparms->tcon->handle_timeout); buf->dcontext.Flags =cpu_to_le32 (SMB2_DHANDLE_FLAG_PERSISTENT ); -generate_random_uuid (buf->dcontext.CreateGuid); -memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + +/* for replay, we should not overwrite the existing create guid */ +if (!oparms->replay) { +generate_random_uuid (buf->dcontext.CreateGuid); +memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + }else +memcpy (buf->dcontext.CreateGuid, pfid->create_guid,16 );/* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */ buf->Name[0 ] ='D' ;
@@ -3142,6 +3147,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,/* reinitialize for possible replay */ flags =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries);cifs_dbg (FYI ,"create/open\n" );if (!ses || !server)
Signature · 1 line
2.40.1
Quoted 6 lines · Steve French
It needed a small rebase to work around one of Paulo's patches which it depended on (which is for 6.9-rc) but was wondering if you want this patch in before 6.9 because its change to
smb2_compound_opbelow has a dependency on another patch - can that change be safely removed?
It will be good to have this in 6.8-rc4, if it will be accepted. It's the same small change made in several places.
It avoids a possible handle leak on the server.
Quoted 151 lines
replay_again:/* reinitialize for possible replay */ flags = 0; oplock = SMB2_OPLOCK_LEVEL_NONE; num_rqst = 0; server = cifs_pick_channel(ses); oparms->replay = !!(retries);Quoted 134 lines · On Fri, Feb 9, 2024 at 5:25 AM <[email protected]> wrote:
From: Shyam Prasad N <[email protected]>
File open requests made to the server contain a CreateGuid, which is used by the server to identify the open request. If the same request needs to be replayed, it needs to be sent with the same CreateGuid in the durable handle v2 context.
Without doing so, we could end up leaking handles on the server when:
1. multichannel is used AND
2. connection goes down, but not for all channelsThis is because the replayed open request would have a new CreateGuid and the server will treat this as a new request and open a new handle.
This change fixes this by reusing the existing
create_guidstored in the cached fid struct.REF: MS-SMB2 4.9 Replay Create Request on an Alternate Channel
Fixes 4f1fffa23769 ("cifs: commands that are retried should have replay flag set")Signed-off-by Shyam Prasad N <[email protected]>--- fs/smb/client/cached_dir.c | 1 + fs/smb/client/cifsglob.h | 1 + fs/smb/client/smb2inode.c | 1 + fs/smb/client/smb2ops.c | 4 ++++ fs/smb/client/smb2pdu.c | 10 ++++++++-- 5 files changed, 15 insertions(+), 2 deletions(-)fs/smb/client/cached_dir.c +1
-0@@ -242,6 +242,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, .desired_access = FILE_READ_DATA | FILE_READ_ATTRIBUTES, .disposition = FILE_OPEN, .fid = pfid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,fs/smb/client/cifsglob.h +1
-0@@ -1373,6 +1373,7 @@ struct cifs_open_parms {struct cifs_fid *fid;umode_t mode; bool reconnect:1; + bool replay:1; /* indicates that this open is for a replay */struct kvec *ea_cctx; };fs/smb/client/smb2inode.c +1
-0@@ -203,6 +203,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, oplock =SMB2_OPLOCK_LEVEL_NONE ; num_rqst =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries); vars =kzalloc (sizeof (*vars),GFP_ATOMIC );if (vars ==NULL )fs/smb/client/smb2ops.c +4
-0@@ -1205,6 +1205,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,@@ -1570,6 +1571,7 @@ smb2_ioctl_query_info(const unsigned int xid, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, create_options), .fid = &fid, + .replay = !!(retries), };if (qi.flags &PASSTHRU_FSCTL ) {@@ -2296,6 +2298,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,@@ -2682,6 +2685,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,fs/smb/client/smb2pdu.c +8
-3@@ -2406,8 +2406,13 @@ create_durable_v2_buf(struct cifs_open_parms *oparms)*/ buf->dcontext.Timeout =cpu_to_le32 (oparms->tcon->handle_timeout); buf->dcontext.Flags =cpu_to_le32 (SMB2_DHANDLE_FLAG_PERSISTENT ); -generate_random_uuid (buf->dcontext.CreateGuid); -memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + +/* for replay, we should not overwrite the existing create guid */ +if (!oparms->replay) { +generate_random_uuid (buf->dcontext.CreateGuid); +memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + }else +memcpy (buf->dcontext.CreateGuid, pfid->create_guid,16 );/* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */ buf->Name[0 ] ='D' ;@@ -3156,6 +3161,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,/* reinitialize for possible replay */ flags =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries);cifs_dbg (FYI ,"create/open\n" );if (!ses || !server) --Quoted 2 lines
2.34.1
--
Thanks,Steve
Signature · 2 lines
Regards, Shyam
updated patch attached - rebased to work around Paulo's change and removed the update to smb2inode.c compounding due to dependency on a later patch, and tentatively merged to cifs-2.6.git for-next pending testing
Quoted 169 lines · Shyam Prasad N
Quoted 6 lines · Steve French
It needed a small rebase to work around one of Paulo's patches which it depended on (which is for 6.9-rc) but was wondering if you want this patch in before 6.9 because its change to
smb2_compound_opbelow has a dependency on another patch - can that change be safely removed?It will be good to have this in 6.8-rc4, if it will be accepted. It's the same small change made in several places.
It avoids a possible handle leak on the server.Quoted 150 lines
replay_again:/* reinitialize for possible replay */ flags = 0; oplock = SMB2_OPLOCK_LEVEL_NONE; num_rqst = 0; server = cifs_pick_channel(ses); oparms->replay = !!(retries);Quoted 134 lines · On Fri, Feb 9, 2024 at 5:25 AM <[email protected]> wrote:
From: Shyam Prasad N <[email protected]>
File open requests made to the server contain a CreateGuid, which is used by the server to identify the open request. If the same request needs to be replayed, it needs to be sent with the same CreateGuid in the durable handle v2 context.
Without doing so, we could end up leaking handles on the server when:
1. multichannel is used AND
2. connection goes down, but not for all channelsThis is because the replayed open request would have a new CreateGuid and the server will treat this as a new request and open a new handle.
This change fixes this by reusing the existing
create_guidstored in the cached fid struct.REF: MS-SMB2 4.9 Replay Create Request on an Alternate Channel
Fixes 4f1fffa23769 ("cifs: commands that are retried should have replay flag set")Signed-off-by Shyam Prasad N <[email protected]>--- fs/smb/client/cached_dir.c | 1 + fs/smb/client/cifsglob.h | 1 + fs/smb/client/smb2inode.c | 1 + fs/smb/client/smb2ops.c | 4 ++++ fs/smb/client/smb2pdu.c | 10 ++++++++-- 5 files changed, 15 insertions(+), 2 deletions(-)fs/smb/client/cached_dir.c +1
-0@@ -242,6 +242,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, .desired_access = FILE_READ_DATA | FILE_READ_ATTRIBUTES, .disposition = FILE_OPEN, .fid = pfid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,fs/smb/client/cifsglob.h +1
-0@@ -1373,6 +1373,7 @@ struct cifs_open_parms {struct cifs_fid *fid;umode_t mode; bool reconnect:1; + bool replay:1; /* indicates that this open is for a replay */struct kvec *ea_cctx; };fs/smb/client/smb2inode.c +1
-0@@ -203,6 +203,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, oplock =SMB2_OPLOCK_LEVEL_NONE ; num_rqst =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries); vars =kzalloc (sizeof (*vars),GFP_ATOMIC );if (vars ==NULL )fs/smb/client/smb2ops.c +4
-0@@ -1205,6 +1205,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,@@ -1570,6 +1571,7 @@ smb2_ioctl_query_info(const unsigned int xid, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, create_options), .fid = &fid, + .replay = !!(retries), };if (qi.flags &PASSTHRU_FSCTL ) {@@ -2296,6 +2298,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,@@ -2682,6 +2685,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,fs/smb/client/smb2pdu.c +8
-3@@ -2406,8 +2406,13 @@ create_durable_v2_buf(struct cifs_open_parms *oparms)*/ buf->dcontext.Timeout =cpu_to_le32 (oparms->tcon->handle_timeout); buf->dcontext.Flags =cpu_to_le32 (SMB2_DHANDLE_FLAG_PERSISTENT ); -generate_random_uuid (buf->dcontext.CreateGuid); -memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + +/* for replay, we should not overwrite the existing create guid */ +if (!oparms->replay) { +generate_random_uuid (buf->dcontext.CreateGuid); +memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + }else +memcpy (buf->dcontext.CreateGuid, pfid->create_guid,16 );/* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */ buf->Name[0 ] ='D' ;@@ -3156,6 +3161,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,/* reinitialize for possible replay */ flags =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries);cifs_dbg (FYI ,"create/open\n" );if (!ses || !server) --Quoted 2 lines
2.34.1
--
Thanks,Quoted 1 line
Steve
--
Regards,
Shyam
Signature · 3 lines
Thanks, Steve
From 8b39cfa4b970674a770f6f4c37e2d00c8359daeb Mon Sep 17 00:00:00 2001
From: Shyam Prasad N <[email protected]>
Date: Fri, 9 Feb 2024 11:25:42 +0000
Subject: [PATCH] cifs: update the same create_guid on replay
File open requests made to the server contain a CreateGuid, which is used by the server to identify the open request. If the same request needs to be replayed, it needs to be sent with the same CreateGuid in the durable handle v2 context.
Without doing so, we could end up leaking handles on the server when:
1. multichannel is used AND
2. connection goes down, but not for all channels
This is because the replayed open request would have a new CreateGuid and the server will treat this as a new request and open a new handle.
This change fixes this by reusing the existing create_guid stored in the cached fid struct.
REF: MS-SMB2 4.9 Replay Create Request on an Alternate Channel
--- fs/smb/client/cached_dir.c | 1 + fs/smb/client/cifsglob.h | 1 + fs/smb/client/smb2inode.c | 1 + fs/smb/client/smb2ops.c | 4 ++++ fs/smb/client/smb2pdu.c | 10 ++++++++-- 5 files changed, 15 insertions(+), 2 deletions(-)
fs/smb/client/cached_dir.c +1 -0
@@ -242,6 +242,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, .desired_access = FILE_READ_DATA | FILE_READ_ATTRIBUTES, .disposition = FILE_OPEN, .fid = pfid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
fs/smb/client/cifsglob.h +1 -0
@@ -1378,6 +1378,7 @@ struct cifs_open_parms {struct cifs_fid *fid;umode_t mode; bool reconnect:1; + bool replay:1; /* indicates that this open is for a replay */ };struct cifs_fid {
fs/smb/client/smb2ops.c +4 -0
@@ -1204,6 +1204,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
@@ -1569,6 +1570,7 @@ smb2_ioctl_query_info(const unsigned int xid, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, create_options), .fid = &fid, + .replay = !!(retries), };if (qi.flags &PASSTHRU_FSCTL ) {
@@ -2295,6 +2297,7 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
@@ -2681,6 +2684,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon, .disposition = FILE_OPEN, .create_options = cifs_create_options(cifs_sb, 0), .fid = &fid, + .replay = !!(retries), }; rc = SMB2_open_init(tcon, server,
fs/smb/client/smb2pdu.c +8 -2
@@ -2404,8 +2404,13 @@ create_durable_v2_buf(struct cifs_open_parms *oparms)*/ buf->dcontext.Timeout =cpu_to_le32 (oparms->tcon->handle_timeout); buf->dcontext.Flags =cpu_to_le32 (SMB2_DHANDLE_FLAG_PERSISTENT ); -generate_random_uuid (buf->dcontext.CreateGuid); -memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + +/* for replay, we should not overwrite the existing create guid */ +if (!oparms->replay) { +generate_random_uuid (buf->dcontext.CreateGuid); +memcpy (pfid->create_guid, buf->dcontext.CreateGuid,16 ); + }else +memcpy (buf->dcontext.CreateGuid, pfid->create_guid,16 );/* SMB2_CREATE_DURABLE_HANDLE_REQUEST is "DH2Q" */ buf->Name[0 ] ='D' ;
@@ -3142,6 +3147,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,/* reinitialize for possible replay */ flags =0 ; server =cifs_pick_channel (ses); + oparms->replay = !!(retries);cifs_dbg (FYI ,"create/open\n" );if (!ses || !server)
Signature · 1 line
2.40.1