Skip to content

Commit

Permalink
smb/server: fix potential null-ptr-deref of lease_ctx_info in smb2_op…
Browse files Browse the repository at this point in the history
…en()

null-ptr-deref will occur when (req_op_level == SMB2_OPLOCK_LEVEL_LEASE)
and parse_lease_state() return NULL.

Fix this by check if 'lease_ctx_info' is NULL.

Additionally, remove the redundant parentheses in
parse_durable_handle_context().

Signed-off-by: ChenXiaoSong <[email protected]>
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
ChenXiaoSong authored and namjaejeon committed Oct 13, 2024
1 parent 710a209 commit 684bcb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion oplock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ void create_lease_buf(u8 *rbuf, struct lease *lease)
* @open_req: buffer containing smb2 file open(create) request
* @is_dir: whether leasing file is directory
*
* Return: oplock state, -ENOENT if create lease context not found
* Return: allocated lease context object on success, otherwise NULL
*/
struct lease_ctx_info *parse_lease_state(void *open_req)
{
Expand Down
10 changes: 5 additions & 5 deletions smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2865,8 +2865,8 @@ static int parse_durable_handle_context(struct ksmbd_work *work,
}
}

if (((lc && (lc->req_state & SMB2_LEASE_HANDLE_CACHING_LE)) ||
req_op_level == SMB2_OPLOCK_LEVEL_BATCH)) {
if ((lc && (lc->req_state & SMB2_LEASE_HANDLE_CACHING_LE)) ||
req_op_level == SMB2_OPLOCK_LEVEL_BATCH) {
dh_info->CreateGuid =
durable_v2_blob->CreateGuid;
dh_info->persistent =
Expand All @@ -2886,8 +2886,8 @@ static int parse_durable_handle_context(struct ksmbd_work *work,
goto out;
}

if (((lc && (lc->req_state & SMB2_LEASE_HANDLE_CACHING_LE)) ||
req_op_level == SMB2_OPLOCK_LEVEL_BATCH)) {
if ((lc && (lc->req_state & SMB2_LEASE_HANDLE_CACHING_LE)) ||
req_op_level == SMB2_OPLOCK_LEVEL_BATCH) {
ksmbd_debug(SMB, "Request for durable open\n");
dh_info->type = dh_idx;
}
Expand Down Expand Up @@ -3600,7 +3600,7 @@ int smb2_open(struct ksmbd_work *work)
goto err_out1;
}
} else {
if (req_op_level == SMB2_OPLOCK_LEVEL_LEASE) {
if (req_op_level == SMB2_OPLOCK_LEVEL_LEASE && lc) {
if (S_ISDIR(file_inode(filp)->i_mode)) {
lc->req_state &= ~SMB2_LEASE_WRITE_CACHING_LE;
lc->is_dir = true;
Expand Down

0 comments on commit 684bcb8

Please sign in to comment.