Skip to content

Commit eb4447b

Browse files
Wang ZhaolongSteve French
authored andcommitted
ksmbd: fix memory leak in parse_lease_state()
The previous patch that added bounds check for create lease context introduced a memory leak. When the bounds check fails, the function returns NULL without freeing the previously allocated lease_ctx_info structure. This patch fixes the issue by adding kfree(lreq) before returning NULL in both boundary check cases. Fixes: bab703e ("ksmbd: add bounds check for create lease context") Signed-off-by: Wang Zhaolong <wangzhaolong1@huawei.com> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 53e3e5b commit eb4447b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/smb/server/oplock.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ struct lease_ctx_info *parse_lease_state(void *open_req)
14961496

14971497
if (le16_to_cpu(cc->DataOffset) + le32_to_cpu(cc->DataLength) <
14981498
sizeof(struct create_lease_v2) - 4)
1499-
return NULL;
1499+
goto err_out;
15001500

15011501
memcpy(lreq->lease_key, lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
15021502
lreq->req_state = lc->lcontext.LeaseState;
@@ -1512,7 +1512,7 @@ struct lease_ctx_info *parse_lease_state(void *open_req)
15121512

15131513
if (le16_to_cpu(cc->DataOffset) + le32_to_cpu(cc->DataLength) <
15141514
sizeof(struct create_lease))
1515-
return NULL;
1515+
goto err_out;
15161516

15171517
memcpy(lreq->lease_key, lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
15181518
lreq->req_state = lc->lcontext.LeaseState;
@@ -1521,6 +1521,9 @@ struct lease_ctx_info *parse_lease_state(void *open_req)
15211521
lreq->version = 1;
15221522
}
15231523
return lreq;
1524+
err_out:
1525+
kfree(lreq);
1526+
return NULL;
15241527
}
15251528

15261529
/**

0 commit comments

Comments
 (0)