ksmbd: set epoch in create context v2 lease
Subsystems (2)
Namjae Jeon
maintainerPATCH 1/7 ksmbd: set epoch in create context v2 lease
To support v2 lease(directory lease), ksmbd set epoch in create context v2 lease response.
--- fs/smb/server/oplock.c | 5 ++++- fs/smb/server/oplock.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-)
fs/smb/server/oplock.c +4 -1
@@ -104,7 +104,7 @@ static int alloc_lease(struct oplock_info *opinfo, struct lease_ctx_info *lctx) lease->duration = lctx->duration;memcpy (lease->parent_lease_key, lctx->parent_lease_key,SMB2_LEASE_KEY_SIZE ); lease->version = lctx->version; - lease->epoch =0 ; + lease->epoch =le16_to_cpu (lctx->epoch);INIT_LIST_HEAD (&opinfo->lease_entry); opinfo->o_lease = lease;
@@ -1032,6 +1032,7 @@ static void copy_lease(struct oplock_info *op1, struct oplock_info *op2) SMB2_LEASE_KEY_SIZE); lease2->duration = lease1->duration; lease2->flags = lease1->flags; + lease2->epoch = lease1->epoch++; }static int add_lease_global_list (struct oplock_info *opinfo)
@@ -1364,6 +1365,7 @@ void create_lease_buf(u8 *rbuf, struct lease *lease)memcpy (buf->lcontext.LeaseKey, lease->lease_key,SMB2_LEASE_KEY_SIZE ); buf->lcontext.LeaseFlags = lease->flags; + buf->lcontext.Epoch =cpu_to_le16 (++lease->epoch); buf->lcontext.LeaseState = lease->state;memcpy (buf->lcontext.ParentLeaseKey, lease->parent_lease_key,SMB2_LEASE_KEY_SIZE );
@@ -1423,6 +1425,7 @@ struct lease_ctx_info *parse_lease_state(void *open_req)memcpy (lreq->lease_key, lc->lcontext.LeaseKey,SMB2_LEASE_KEY_SIZE ); lreq->req_state = lc->lcontext.LeaseState; lreq->flags = lc->lcontext.LeaseFlags; + lreq->epoch = lc->lcontext.Epoch; lreq->duration = lc->lcontext.LeaseDuration;memcpy (lreq->parent_lease_key, lc->lcontext.ParentLeaseKey,SMB2_LEASE_KEY_SIZE );
fs/smb/server/oplock.h +1 -0
@@ -34,6 +34,7 @@ struct lease_ctx_info {__le32 flags;__le64 duration;__u8 parent_lease_key[SMB2_LEASE_KEY_SIZE ]; +__le16 epoch;int version; };
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 2/7 ksmbd: set v2 lease capability
Set SMB2_GLOBAL_CAP_DIRECTORY_LEASING to ->capabilities to inform server support directory lease to client.
--- fs/smb/server/oplock.c | 4 ---- fs/smb/server/smb2ops.c | 9 ++++++--- 2 files changed, 6 insertions(+), 7 deletions(-)
fs/smb/server/oplock.c +0 -4
@@ -1105,10 +1105,6 @@ int smb_grant_oplock(struct ksmbd_work *work, int req_op_level, u64 pid,bool prev_op_has_lease;__le32 prev_op_state =0 ; -/* not support directory lease */ -if (S_ISDIR (file_inode (fp->filp)->i_mode)) -return 0 ; - opinfo =alloc_opinfo (work, pid, tid);if (!opinfo)return -ENOMEM ;
fs/smb/server/smb2ops.c +6 -3
@@ -221,7 +221,8 @@ void init_smb3_0_server(struct ksmbd_conn *conn) conn->signing_algorithm =SIGNING_ALG_AES_CMAC_LE ;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_LEASES ) - conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING ; + conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING | +SMB2_GLOBAL_CAP_DIRECTORY_LEASING ;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION && conn->cli_cap &SMB2_GLOBAL_CAP_ENCRYPTION )
@@ -245,7 +246,8 @@ void init_smb3_02_server(struct ksmbd_conn *conn) conn->signing_algorithm =SIGNING_ALG_AES_CMAC_LE ;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_LEASES ) - conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING ; + conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING | +SMB2_GLOBAL_CAP_DIRECTORY_LEASING ; if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION || (!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF) &&
@@ -270,7 +272,8 @@ int init_smb3_11_server(struct ksmbd_conn *conn) conn->signing_algorithm =SIGNING_ALG_AES_CMAC_LE ;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_LEASES ) - conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING ; + conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING | +SMB2_GLOBAL_CAP_DIRECTORY_LEASING ; if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION || (!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF) &&
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 3/7 ksmbd: downgrade RWH lease caching state to RH for directory
In reply to Namjae JeonRWH(Read + Write + Handle) caching state is not supported for directory. ksmbd downgrade it to RH for directory if client send RWH caching lease state.
--- fs/smb/server/oplock.c | 8 ++++++-- fs/smb/server/oplock.h | 2 +- fs/smb/server/smb2pdu.c | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-)
fs/smb/server/oplock.c +6 -2
@@ -1401,7 +1401,7 @@ void create_lease_buf(u8 *rbuf, struct lease *lease)* * Return: oplock state, -ENOENT if create lease context not found */ -struct lease_ctx_info *parse_lease_state (void *open_req) +struct lease_ctx_info *parse_lease_state (void *open_req,bool is_dir) {struct create_context *cc;struct smb2_create_req *req = (struct smb2_create_req *)open_req;
@@ -1419,7 +1419,11 @@ struct lease_ctx_info *parse_lease_state(void *open_req)struct create_lease_v2 *lc = (struct create_lease_v2 *)cc;memcpy (lreq->lease_key, lc->lcontext.LeaseKey,SMB2_LEASE_KEY_SIZE ); - lreq->req_state = lc->lcontext.LeaseState; +if (is_dir) + lreq->req_state = lc->lcontext.LeaseState & + ~SMB2_LEASE_WRITE_CACHING_LE ; +else + lreq->req_state = lc->lcontext.LeaseState; lreq->flags = lc->lcontext.LeaseFlags; lreq->epoch = lc->lcontext.Epoch; lreq->duration = lc->lcontext.LeaseDuration;
fs/smb/server/oplock.h +1 -1
@@ -109,7 +109,7 @@ void opinfo_put(struct oplock_info *opinfo);/* Lease related functions */ void create_lease_buf (u8 *rbuf,struct lease *lease); -struct lease_ctx_info *parse_lease_state (void *open_req); +struct lease_ctx_info *parse_lease_state (void *open_req,bool is_dir);__u8 smb2_map_lease_to_oplock (__le32 lease_state);int lease_read_to_write (struct oplock_info *opinfo);
fs/smb/server/smb2pdu.c +4 -4
@@ -2732,10 +2732,6 @@ int smb2_open(struct ksmbd_work *work) } } - req_op_level = req->RequestedOplockLevel; -if (req_op_level ==SMB2_OPLOCK_LEVEL_LEASE ) - lc =parse_lease_state (req); -if (le32_to_cpu (req->ImpersonationLevel) >le32_to_cpu (IL_DELEGATE )) {pr_err ("Invalid impersonationlevel : 0x%x\n" ,le32_to_cpu (req->ImpersonationLevel));
@@ -3215,6 +3211,10 @@ int smb2_open(struct ksmbd_work *work) need_truncate =1 ; } + req_op_level = req->RequestedOplockLevel; +if (req_op_level ==SMB2_OPLOCK_LEVEL_LEASE ) + lc =parse_lease_state (req,S_ISDIR (file_inode (filp)->i_mode)); + share_ret =ksmbd_smb_check_shared_mode (fp->filp, fp); if (!test_share_config_flag(work->tcon->share_conf, KSMBD_SHARE_FLAG_OPLOCKS) || (req_op_level == SMB2_OPLOCK_LEVEL_LEASE &&
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH 3/7] ksmbd: downgrade RWH lease caching state to RH for directory
kernel test robot noticed the following build warnings:
Hi Namjae,
kernel test robot noticed the following build warnings:
[auto build test WARNING on cifs/for-next]
[also build test WARNING on linus/master v6.7-rc4 next-20231205] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Namjae-Jeon/ksmbd-set-v2-lease-capability/20231204-214847 base: git://git.samba.org/sfrench/cifs-2.6.git for-next patch link: https://lore.kernel.org/r/20231204134509.11413-3-linkinjeon%40kernel.org patch subject: [PATCH 3/7] ksmbd: downgrade RWH lease caching state to RH for directory config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20231205/[email protected]/config) compiler: alpha-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231205/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> fs/smb/server/oplock.c:1405: warning: Function parameter or member 'is_dir' not described in 'parse_lease_state'
vim +1405 fs/smb/server/oplock.c
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1397
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1398 /**
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1399 * parse_lease_state() - parse lease context containted in file open request
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1400 * @open_req: buffer containing smb2 file open(create) request
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1401 *
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1402 * Return: oplock state, -ENOENT if create lease context not found
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1403 */
9c0f64c0641abec fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1404 struct lease_ctx_info *parse_lease_state(void *open_req, bool is_dir)
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 @1405 {
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1406 struct create_context *cc;
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1407 struct smb2_create_req *req = (struct smb2_create_req *)open_req;
fc6c6a3c324c1b3 fs/smb/server/oplock.c Namjae Jeon 2023-05-28 1408 struct lease_ctx_info *lreq;
fc6c6a3c324c1b3 fs/smb/server/oplock.c Namjae Jeon 2023-05-28 1409
fc6c6a3c324c1b3 fs/smb/server/oplock.c Namjae Jeon 2023-05-28 1410 cc = smb2_find_context_vals(req, SMB2_CREATE_REQUEST_LEASE, 4);
fc6c6a3c324c1b3 fs/smb/server/oplock.c Namjae Jeon 2023-05-28 1411 if (IS_ERR_OR_NULL(cc))
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1412 return NULL;
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1413
fc6c6a3c324c1b3 fs/smb/server/oplock.c Namjae Jeon 2023-05-28 1414 lreq = kzalloc(sizeof(struct lease_ctx_info), GFP_KERNEL);
fc6c6a3c324c1b3 fs/smb/server/oplock.c Namjae Jeon 2023-05-28 1415 if (!lreq)
fc6c6a3c324c1b3 fs/smb/server/oplock.c Namjae Jeon 2023-05-28 1416 return NULL;
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1417
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1418 if (sizeof(struct lease_context_v2) == le32_to_cpu(cc->DataLength)) {
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1419 struct create_lease_v2 *lc = (struct create_lease_v2 *)cc;
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1420
2734b692f7b8167 fs/ksmbd/oplock.c Namjae Jeon 2021-09-09 1421 memcpy(lreq->lease_key, lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
9c0f64c0641abec fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1422 if (is_dir)
9c0f64c0641abec fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1423 lreq->req_state = lc->lcontext.LeaseState &
9c0f64c0641abec fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1424 ~SMB2_LEASE_WRITE_CACHING_LE;
9c0f64c0641abec fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1425 else
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1426 lreq->req_state = lc->lcontext.LeaseState;
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1427 lreq->flags = lc->lcontext.LeaseFlags;
3ed2c7b63d1312c fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1428 lreq->epoch = lc->lcontext.Epoch;
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1429 lreq->duration = lc->lcontext.LeaseDuration;
2734b692f7b8167 fs/ksmbd/oplock.c Namjae Jeon 2021-09-09 1430 memcpy(lreq->parent_lease_key, lc->lcontext.ParentLeaseKey,
2734b692f7b8167 fs/ksmbd/oplock.c Namjae Jeon 2021-09-09 1431 SMB2_LEASE_KEY_SIZE);
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1432 lreq->version = 2;
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1433 } else {
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1434 struct create_lease *lc = (struct create_lease *)cc;
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1435
2734b692f7b8167 fs/ksmbd/oplock.c Namjae Jeon 2021-09-09 1436 memcpy(lreq->lease_key, lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1437 lreq->req_state = lc->lcontext.LeaseState;
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1438 lreq->flags = lc->lcontext.LeaseFlags;
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1439 lreq->duration = lc->lcontext.LeaseDuration;
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1440 lreq->version = 1;
ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1441 }
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1442 return lreq;
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1443 }
e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1444 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Namjae Jeon
maintainerRe: [PATCH 3/7] ksmbd: downgrade RWH lease caching state to RH for directory
2023-12-05 20:15 GMT+09:00, kernel test robot <[email protected]>:
Quoted 1 line
Hi Namjae,
Hi kernel test robot.
Thanks for your report. I have fixed it.
Thanks again!
Quoted 124 lines
kernel test robot noticed the following build warnings:
[auto build test WARNING on cifs/for-next]
[also build test WARNING on linus/master v6.7-rc4 next-20231205] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url:
https://github.com/intel-lab-lkp/linux/commits/Namjae-Jeon/ksmbd-set-v2-lease-capability/20231204-214847
base:git://git.samba.org/sfrench/cifs-2.6.gitfor-next
patch link:
https://lore.kernel.org/r/20231204134509.11413-3-linkinjeon%40kernel.org
patch subject: [PATCH 3/7] ksmbd: downgrade RWH lease caching state to RH for directory
config: alpha-allyesconfig
(https://download.01.org/0day-ci/archive/20231205/[email protected]/config)
compiler: alpha-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build):
(https://download.01.org/0day-ci/archive/20231205/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
Quoted 2 lines
Quoted 2 lines
fs/smb/server/oplock.c:1405: warning: Function parameter or member 'is_dir' not described in 'parse_lease_state'vim +1405
fs/smb/server/oplock.ce2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1397 e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1398 /** e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1399 * parse_lease_state() - parse lease context containted in file open request e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1400 * @open_req: buffer containing smb2 file open(create) request e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1401 * e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1402 *Return: oplock state,
-ENOENTif create lease context not founde2f34481b24db2ffs/cifsd/oplock.cNamjae Jeon 2021-03-16 1403 */9c0f64c0641abecfs/smb/server/oplock.cNamjae Jeon 2023-12-04 1404 structlease_ctx_info*parse_lease_state(void*open_req, boolis_dir)e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 @1405 { e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1406 struct
create_context*cc;e2f34481b24db2ffs/cifsd/oplock.cNamjae Jeon 2021-03-16 1407 structsmb2_create_req*req = (structsmb2_create_req*)open_req;fc6c6a3c324c1b3fs/smb/server/oplock.cNamjae Jeon 2023-05-28 1408 structlease_ctx_info*lreq;fc6c6a3c324c1b3fs/smb/server/oplock.cNamjae Jeon 2023-05-28 1409fc6c6a3c324c1b3fs/smb/server/oplock.cNamjae Jeon 2023-05-28 1410 cc =smb2_find_context_vals(req, SMB2_CREATE_REQUEST_LEASE, 4);fc6c6a3c324c1b3fs/smb/server/oplock.cNamjae Jeon 2023-05-28 1411 if
(IS_ERR_OR_NULL(cc))e2f34481b24db2ffs/cifsd/oplock.cNamjae Jeon 2021-03-16 1412return NULL;
e2f34481b24db2ffs/cifsd/oplock.cNamjae Jeon 2021-03-16 1413fc6c6a3c324c1b3fs/smb/server/oplock.cNamjae Jeon 2023-05-28 1414 lreq =kzalloc(sizeof(struct lease_ctx_info), GFP_KERNEL);fc6c6a3c324c1b3fs/smb/server/oplock.cNamjae Jeon 2023-05-28 1415 if
(!lreq)fc6c6a3c324c1b3fs/smb/server/oplock.cNamjae Jeon 2023-05-28 1416return NULL; e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1417 ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1418 if (sizeof(struct lease_context_v2) == le32_to_cpu(cc->DataLength)) { ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1419 struct create_lease_v2 *lc = (struct create_lease_v2 *)cc; ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1420 2734b692f7b8167 fs/ksmbd/oplock.c Namjae Jeon 2021-09-09 1421 memcpy(lreq->lease_key, lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE); 9c0f64c0641abec fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1422 if (is_dir) 9c0f64c0641abec fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1423 lreq->req_state = lc->lcontext.LeaseState & 9c0f64c0641abec fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1424 ~SMB2_LEASE_WRITE_CACHING_LE; 9c0f64c0641abec fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1425 else ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1426 lreq->req_state = lc->lcontext.LeaseState; ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1427 lreq->flags = lc->lcontext.LeaseFlags; 3ed2c7b63d1312c fs/smb/server/oplock.c Namjae Jeon 2023-12-04 1428 lreq->epoch = lc->lcontext.Epoch; ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1429 lreq->duration = lc->lcontext.LeaseDuration; 2734b692f7b8167 fs/ksmbd/oplock.c Namjae Jeon 2021-09-09 1430 memcpy(lreq->parent_lease_key, lc->lcontext.ParentLeaseKey, 2734b692f7b8167 fs/ksmbd/oplock.c Namjae Jeon 2021-09-09 1431 SMB2_LEASE_KEY_SIZE); ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1432 lreq->version = 2; ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1433 } else { e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1434 struct create_lease *lc = (struct create_lease *)cc; ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1435 2734b692f7b8167 fs/ksmbd/oplock.c Namjae Jeon 2021-09-09 1436 memcpy(lreq->lease_key, lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE); e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1437 lreq->req_state = lc->lcontext.LeaseState; e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1438 lreq->flags = lc->lcontext.LeaseFlags; e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1439 lreq->duration = lc->lcontext.LeaseDuration; ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1440 lreq->version = 1; ade62d8b429fe49 fs/cifsd/oplock.c Namjae Jeon 2021-06-07 1441 } e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1442 return lreq; e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1443 } e2f34481b24db2f fs/cifsd/oplock.c Namjae Jeon 2021-03-16 1444--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Namjae Jeon
maintainerPATCH 4/7 ksmbd: send v2 lease break notification for directory
In reply to Namjae JeonIf client send different parent key, different client guid, or there is no parent lease key flags in create context v2 lease, ksmbd send lease break to client.
--- fs/smb/common/smb2pdu.h | 1 + fs/smb/server/oplock.c | 41 ++++++++++++++++++++++++++++++++++----- fs/smb/server/oplock.h | 4 ++++ fs/smb/server/smb2pdu.c | 7 +++++++ fs/smb/server/vfs_cache.c | 13 ++++++++++++- fs/smb/server/vfs_cache.h | 2 ++ 6 files changed, 62 insertions(+), 6 deletions(-)
fs/smb/common/smb2pdu.h +1 -0
@@ -1250,6 +1250,7 @@ struct create_mxac_rsp {#define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04)#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02) +#define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET_LE cpu_to_le32(0x04)#define SMB2_LEASE_KEY_SIZE 16
fs/smb/server/oplock.c +36 -5
77 lines not on this page · raw message
fs/smb/server/oplock.h +4 -0
@@ -36,6 +36,7 @@ struct lease_ctx_info {__u8 parent_lease_key[SMB2_LEASE_KEY_SIZE ];__le16 epoch;int version; +bool is_dir; };struct lease_table {
@@ -54,6 +55,7 @@ struct lease {__u8 parent_lease_key[SMB2_LEASE_KEY_SIZE ];int version;unsigned short epoch; +bool is_dir;struct lease_table *l_lb; };
@@ -125,4 +127,6 @@ struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,int find_same_lease_key (struct ksmbd_session *sess,struct ksmbd_inode *ci,struct lease_ctx_info *lctx);void destroy_lease_table (struct ksmbd_conn *conn); +void smb_send_parent_lease_break_noti (struct ksmbd_file *fp, +struct lease_ctx_info *lctx);#endif /* __KSMBD_OPLOCK_H */
fs/smb/server/smb2pdu.c +7 -0
@@ -3225,6 +3225,13 @@ int smb2_open(struct ksmbd_work *work) } }else {if (req_op_level ==SMB2_OPLOCK_LEVEL_LEASE ) { +/* +* Compare parent lease using parent key. If there is no +* a lease that has same parent key, Send lease break +* notification. +*/ +smb_send_parent_lease_break_noti (fp, lc); + req_op_level =smb2_map_lease_to_oplock (lc->req_state); ksmbd_debug(SMB, "lease req for(%s) req oplock state 0x%x, lease state 0x%x\n",
fs/smb/server/vfs_cache.c +12 -1
@@ -87,6 +87,17 @@ static struct ksmbd_inode *ksmbd_inode_lookup(struct ksmbd_file *fp)return __ksmbd_inode_lookup (fp->filp->f_path.dentry); } +struct ksmbd_inode *ksmbd_inode_lookup_lock (struct dentry *d) +{ +struct ksmbd_inode *ci; + +read_lock (&inode_hash_lock); + ci =__ksmbd_inode_lookup (d); +read_unlock (&inode_hash_lock); + +return ci; +} +int ksmbd_query_inode_status (struct dentry *dentry) {struct ksmbd_inode *ci;
@@ -199,7 +210,7 @@ static void ksmbd_inode_free(struct ksmbd_inode *ci)kfree (ci); } -static void ksmbd_inode_put (struct ksmbd_inode *ci) +void ksmbd_inode_put (struct ksmbd_inode *ci) {if (atomic_dec_and_test (&ci->m_count))ksmbd_inode_free (ci);
fs/smb/server/vfs_cache.h +2 -0
@@ -138,6 +138,8 @@ struct ksmbd_file *ksmbd_lookup_foreign_fd(struct ksmbd_work *work, u64 id);struct ksmbd_file *ksmbd_lookup_fd_slow (struct ksmbd_work *work,u64 id,u64 pid);void ksmbd_fd_put (struct ksmbd_work *work,struct ksmbd_file *fp); +struct ksmbd_inode *ksmbd_inode_lookup_lock (struct dentry *d); +void ksmbd_inode_put (struct ksmbd_inode *ci);struct ksmbd_file *ksmbd_lookup_durable_fd (unsigned long long id);struct ksmbd_file *ksmbd_lookup_fd_cguid (char *cguid);struct ksmbd_file *ksmbd_lookup_fd_inode (struct dentry *dentry);
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 5/7 ksmbd: lazy v2 lease break on smb2_write()
In reply to Namjae JeonDon't immediately send directory lease break notification on smb2_write(). Instead, It postpones it until smb2_close().
--- fs/smb/server/oplock.c | 27 +++++++++++++++++++++++++-- fs/smb/server/oplock.h | 1 + fs/smb/server/vfs.c | 3 +++ fs/smb/server/vfs_cache.h | 1 + 4 files changed, 30 insertions(+), 2 deletions(-)
fs/smb/server/oplock.c +25 -2
@@ -396,8 +396,8 @@ void close_id_del_oplock(struct ksmbd_file *fp) {struct oplock_info *opinfo; -if (S_ISDIR (file_inode (fp->filp)->i_mode)) -return ; +if (fp->reserve_lease_break) +smb_lazy_parent_lease_break_close (fp); opinfo =opinfo_get (fp);if (!opinfo)
@@ -1112,6 +1112,29 @@ void smb_send_parent_lease_break_noti(struct ksmbd_file *fp,ksmbd_inode_put (p_ci); } +void smb_lazy_parent_lease_break_close (struct ksmbd_file *fp) +{ +struct oplock_info *opinfo; +struct ksmbd_inode *p_ci =NULL ; + +if (!fp->f_opinfo->is_lease || fp->f_opinfo->o_lease->version !=2 ) +return ; + + p_ci =ksmbd_inode_lookup_lock (fp->filp->f_path.dentry->d_parent); +if (!p_ci) +return ; + +list_for_each_entry (opinfo, &p_ci->m_op_list, op_entry) { +if (!opinfo->is_lease) +continue ; + +if (opinfo->o_lease->state !=SMB2_OPLOCK_LEVEL_NONE ) +oplock_break (opinfo,SMB2_OPLOCK_LEVEL_NONE ); + } + +ksmbd_inode_put (p_ci); +} +/** * smb_grant_oplock() - handle oplock/lease request on file open * @work: smb work
fs/smb/server/oplock.h +1 -0
@@ -129,4 +129,5 @@ int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,void destroy_lease_table (struct ksmbd_conn *conn);void smb_send_parent_lease_break_noti (struct ksmbd_file *fp,struct lease_ctx_info *lctx); +void smb_lazy_parent_lease_break_close (struct ksmbd_file *fp);#endif /* __KSMBD_OPLOCK_H */
fs/smb/server/vfs.c +3 -0
@@ -517,6 +517,9 @@ int ksmbd_vfs_write(struct ksmbd_work *work, struct ksmbd_file *fp, } } +/* Reserve lease break for parent dir at closing time */ + fp->reserve_lease_break = true; +/* Do we need to break any of a levelII oplock? */ smb_break_all_levII_oplock (work, fp,1 );
fs/smb/server/vfs_cache.h +1 -0
@@ -105,6 +105,7 @@ struct ksmbd_file {struct ksmbd_readdir_data readdir_data;int dot_dotdot[2 ];unsigned int f_state; +bool reserve_lease_break; }; static inline void set_ctx_actor(struct dir_context *ctx,
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH 5/7] ksmbd: lazy v2 lease break on smb2_write()
kernel test robot noticed the following build warnings:
Hi Namjae,
kernel test robot noticed the following build warnings:
[auto build test WARNING on cifs/for-next]
[also build test WARNING on linus/master v6.7-rc4 next-20231206] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Namjae-Jeon/ksmbd-set-v2-lease-capability/20231204-214847 base: git://git.samba.org/sfrench/cifs-2.6.git for-next patch link: https://lore.kernel.org/r/20231204134509.11413-5-linkinjeon%40kernel.org patch subject: [PATCH 5/7] ksmbd: lazy v2 lease break on smb2_write() config: parisc-randconfig-r122-20231206 (https://download.01.org/0day-ci/archive/20231206/[email protected]/config) compiler: hppa-linux-gcc (GCC) 13.2.0 reproduce: (https://download.01.org/0day-ci/archive/20231206/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
fs/smb/server/oplock.c: note: in included file (through include/linux/dcache.h, include/linux/unicode.h, fs/smb/server/unicode.h, ...):
include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true
include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true
include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true
>> fs/smb/server/oplock.c:1120:16: sparse: sparse: dereference of noderef expression
fs/smb/server/oplock.c:1120:42: sparse: sparse: dereference of noderef expression include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true
vim +1120 fs/smb/server/oplock.c
1114
1115 void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp)
1116 {
1117 struct oplock_info *opinfo;
1118 struct ksmbd_inode *p_ci = NULL;
1119
> 1120 if (!fp->f_opinfo->is_lease || fp->f_opinfo->o_lease->version != 2)
1121 return;
1122
1123 p_ci = ksmbd_inode_lookup_lock(fp->filp->f_path.dentry->d_parent);
1124 if (!p_ci)
1125 return;
1126
1127 list_for_each_entry(opinfo, &p_ci->m_op_list, op_entry) {
1128 if (!opinfo->is_lease)
1129 continue;
1130
1131 if (opinfo->o_lease->state != SMB2_OPLOCK_LEVEL_NONE)
1132 oplock_break(opinfo, SMB2_OPLOCK_LEVEL_NONE);
1133 }
1134
1135 ksmbd_inode_put(p_ci);
1136 }
1137
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Namjae Jeon
maintainerRe: [PATCH 5/7] ksmbd: lazy v2 lease break on smb2_write()
2023-12-06 21:41 GMT+09:00, kernel test robot <[email protected]>:
Quoted 1 line
Hi Namjae,
Hi kernel test robot,
Thanks for your report, I have already fixed it and applied it to #ksmbd-for-next-next.
Quoted 78 lines
kernel test robot noticed the following build warnings:
[auto build test WARNING on cifs/for-next]
[also build test WARNING on linus/master v6.7-rc4 next-20231206] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url:
https://github.com/intel-lab-lkp/linux/commits/Namjae-Jeon/ksmbd-set-v2-lease-capability/20231204-214847
base:git://git.samba.org/sfrench/cifs-2.6.gitfor-next
patch link:
https://lore.kernel.org/r/20231204134509.11413-5-linkinjeon%40kernel.org
patch subject: [PATCH 5/7] ksmbd: lazy v2 lease break onsmb2_write()
config: parisc-randconfig-r122-20231206
(https://download.01.org/0day-ci/archive/20231206/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 13.2.0
reproduce:
(https://download.01.org/0day-ci/archive/20231206/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/sparse warnings: (new ones prefixed by >>)
fs/smb/server/oplock.c: note: in included file (throughinclude/linux/dcache.h,include/linux/unicode.h,fs/smb/server/unicode.h, ...):
include/linux/list.h:83:21: sparse: sparse: self-comparison always
evaluates to true
include/linux/list.h:83:21: sparse: sparse: self-comparison always
evaluates to true
include/linux/list.h:83:21: sparse: sparse: self-comparison always
evaluates to trueQuoted 2 lines
Quoted 2 lines
fs/smb/server/oplock.c:1120:16: sparse: sparse: dereference of noderef expression
fs/smb/server/oplock.c:1120:42: sparse: sparse: dereference of noderef
expression
include/linux/list.h:83:21: sparse: sparse: self-comparison always
evaluates to true
include/linux/list.h:83:21: sparse: sparse: self-comparison always
evaluates to truevim +1120
fs/smb/server/oplock.c1114
1115 voidsmb_lazy_parent_lease_break_close(struct ksmbd_file *fp)
1116 {
1117 structoplock_info*opinfo;
1118 structksmbd_inode*p_ci= NULL;
1119Quoted 1 line
1120 if (!fp->f_opinfo->is_lease ||
fp->f_opinfo->o_lease->version!= 2)1121 return;
1122
1123p_ci=ksmbd_inode_lookup_lock(fp->filp->f_path.dentry->d_parent);
1124 if (!p_ci)
1125 return;
1126
1127list_for_each_entry(opinfo, &p_ci->m_op_list, op_entry){
1128 if (!opinfo->is_lease)
1129 continue;
1130
1131 if (opinfo->o_lease->state!=SMB2_OPLOCK_LEVEL_NONE)
1132oplock_break(opinfo, SMB2_OPLOCK_LEVEL_NONE);
1133 }
1134
1135ksmbd_inode_put(p_ci);
1136 }
1137--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Namjae Jeon
maintainerPATCH 6/7 ksmbd: avoid duplicate opinfo_put() call on error of smb21_lease_break_ack()
In reply to Namjae Jeonopinfo_put() could be called twice on error of smb21_lease_break_ack(). It will cause UAF issue if opinfo is referenced on other places.
--- fs/smb/server/smb2pdu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/smb/server/smb2pdu.c +5 -5
@@ -8219,6 +8219,11 @@ static void smb21_lease_break_ack(struct ksmbd_work *work) le32_to_cpu(req->LeaseState)); } +if (ret <0 ) { + rsp->hdr.Status = err; + goto err_out; + } + lease_state = lease->state; opinfo->op_state =OPLOCK_STATE_NONE ;wake_up_interruptible_all (&opinfo->oplock_q);
@@ -8226,11 +8231,6 @@ static void smb21_lease_break_ack(struct ksmbd_work *work)wake_up_interruptible_all (&opinfo->oplock_brk);opinfo_put (opinfo); -if (ret <0 ) { - rsp->hdr.Status = err; - goto err_out; - } - rsp->StructureSize =cpu_to_le16 (36 ); rsp->Reserved =0 ; rsp->Flags =0 ;
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 7/7 ksmbd: fix wrong allocation size update in smb2_open()
In reply to Namjae JeonWhen client send SMB2_CREATE_ALLOCATION_SIZE create context, ksmbd update old size to ->AllocationSize in smb2 create response. ksmbd_vfs_getattr() should be called after it to get updated stat result.
--- fs/smb/server/smb2pdu.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
fs/smb/server/smb2pdu.c +18 -18
@@ -2516,7 +2516,7 @@ static void smb2_new_xattrs(struct ksmbd_tree_connect *tcon, const struct path * da.flags =XATTR_DOSINFO_ATTRIB |XATTR_DOSINFO_CREATE_TIME |XATTR_DOSINFO_ITIME ; - rc =ksmbd_vfs_set_dos_attrib_xattr (mnt_idmap (path->mnt), path, &da, false); + rc =ksmbd_vfs_set_dos_attrib_xattr (mnt_idmap (path->mnt), path, &da, true);if (rc)ksmbd_debug (SMB ,"failed to store file attribute into xattr\n" ); }
@@ -3185,23 +3185,6 @@ int smb2_open(struct ksmbd_work *work) goto err_out; } - rc =ksmbd_vfs_getattr (&path, &stat); -if (rc) - goto err_out; - -if (stat.result_mask &STATX_BTIME ) - fp->create_time =ksmbd_UnixTimeToNT (stat.btime); -else - fp->create_time =ksmbd_UnixTimeToNT (stat.ctime); -if (req->FileAttributes || fp->f_ci->m_fattr ==0 ) - fp->f_ci->m_fattr = -cpu_to_le32 (smb2_get_dos_mode (&stat,le32_to_cpu (req->FileAttributes))); - -if (!created) -smb2_update_xattrs (tcon, &path, fp); -else -smb2_new_xattrs (tcon, &path, fp); -if (file_present || created)ksmbd_vfs_kern_path_unlock (&parent_path, &path);
@@ -3302,6 +3285,23 @@ int smb2_open(struct ksmbd_work *work) } } + rc =ksmbd_vfs_getattr (&path, &stat); +if (rc) + goto err_out; + +if (stat.result_mask &STATX_BTIME ) + fp->create_time =ksmbd_UnixTimeToNT (stat.btime); +else + fp->create_time =ksmbd_UnixTimeToNT (stat.ctime); +if (req->FileAttributes || fp->f_ci->m_fattr ==0 ) + fp->f_ci->m_fattr = +cpu_to_le32 (smb2_get_dos_mode (&stat,le32_to_cpu (req->FileAttributes))); + +if (!created) +smb2_update_xattrs (tcon, &path, fp); +else +smb2_new_xattrs (tcon, &path, fp); +memcpy (fp->client_guid, conn->ClientGUID,SMB2_CLIENT_GUID_SIZE ); rsp->StructureSize =cpu_to_le16 (89 );
Signature · 1 line
2.25.1