Commit 6821320f authored by ChenXiaoSong's avatar ChenXiaoSong Committed by Li Lingfeng
Browse files

smb/server: fix potential null-ptr-deref of lease_ctx_info in smb2_open()

mainline inclusion
from mainline-v6.11-rc5
commit 4e8771a3666c8f216eefd6bd2fd50121c6c437db
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IARWV6
CVE: CVE-2024-46742

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4e8771a3666c8f216eefd6bd2fd50121c6c437db



--------------------------------

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: default avatarChenXiaoSong <chenxiaosong@kylinos.cn>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
Signed-off-by: default avatarLi Lingfeng <lilingfeng3@huawei.com>
parent b4480f1e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1510,7 +1510,7 @@ void create_lease_buf(u8 *rbuf, struct lease *lease)
 * parse_lease_state() - parse lease context containted in file open request
 * @open_req:	buffer containing smb2 file open(create) request
 *
 * 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)
{
+5 −5
Original line number Diff line number Diff line
@@ -2761,8 +2761,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 =
@@ -2782,8 +2782,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;
			}
@@ -3414,7 +3414,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;