From nobody Fri Nov 22 22:20:05 2024 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD96218C004 for ; Fri, 15 Nov 2024 08:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731659579; cv=none; b=loF178UhIWcviQoXkelllJ8c5lofmvZmfvQqXnyDgLk/DD/qqEhS+qICS+zy4KdYgFNLvOxf/ZXGxAOPmnEnTiMtqxH+ZJZKoo7qu/gOd3lbiIJL3tNFCpB0vBdj3uCSHz9u5N5zzL7LOmpMhIQoYX9TSQeOqevPllVZIimo1xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731659579; c=relaxed/simple; bh=54mni3iTajw4DR3xdzQsdu/Chh5F48gsSo9KvuOjIDE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DTebO57kfGNr1Irtsfr+JuW73yLHvjaFnlR9Q9607aR2gFAvXlsnTblJBx/uyA2443DmO0itU1gm+AQyDRmKyKyXsg4O/03tKBHoq/1Il5chlzYLLt7EbXYLbU7dBUvQ1gfEZPuk1G40/u7t8Db8my7eyTyUO6ZSH9Jw9q3tN9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=IBZudi5C; arc=none smtp.client-ip=209.85.128.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="IBZudi5C" Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-6e9ed5e57a7so4042707b3.1 for ; Fri, 15 Nov 2024 00:32:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1731659577; x=1732264377; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kVk+wA7Hzqqbm+HZtE5Q8quohvyj63w+EnDU9/WQw68=; b=IBZudi5C/S5fTYrNYlC/CG4jdL59Prhrbz/3F0dqoqjrOABZ0y5QQiGgZQs1VOTKuj 5UmMGu7u67sjEe3Xy6Bc3KR6LMphhUDAlva0Wh1APjx9SXT6ZWK+Xqa0E0fmFmUA5bL1 /edbV3sbT2TPb+XbHERqbyMd1l47JUYI20CwQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731659577; x=1732264377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kVk+wA7Hzqqbm+HZtE5Q8quohvyj63w+EnDU9/WQw68=; b=lux6mgyMTp2jnBxWzVBCjtNo8HdDNtC4KkS5vza8Dm7IyvDHn5bVLqUU/1Kw5xBz0C dvlj4fpVjs1s79bfvlsc/vNXmNTcrxGi9J4DoBHujE1WLFVx2gY7e7Xty/jJraar2Xnp F0gczqL3bCBEAcv0Cys+0eV+SSraGOf8Q3eBKAGvTa6K3cp358ApFwHhD8P6Baxv3bPb Idm+c0sjuG+J+vm8DoTpdPf3FIkCQgOBFez++RG0l+Atme3ngGaxiGJxwh6Rkvum4kXs xDBrCcHUJKCjxggfKFJ+t2uvKSRpID/qpFaGXDd53MvTZkxt3zfit9rhIXYJrCUGlYiu BDRA== X-Forwarded-Encrypted: i=1; AJvYcCUKVslZQ4JQXENJB3xIwYvuqL8dV9fJpVxXkuH0WD3Ua/yB03Kz0ily+wkhrLKJTuKPSSdJF1n9AsAguV4=@vger.kernel.org X-Gm-Message-State: AOJu0Yxb3fLv5yx/82OMFIozN68yyCEsnLb0jtccdYHWKbZF6QbJATMz +tOn/0eRIug8xYP+g1V4dkoW03BF7r5ZBh9Xif1h+KrSpdutDIkF4VGxI5WsJw== X-Google-Smtp-Source: AGHT+IGhoGxCNZRH1MLfMJH1sClc2oTWPqp7sgf+UUkz9D2SciqwrZP1OjWUqLdY7aFalNaYgAhmHg== X-Received: by 2002:a05:690c:7005:b0:6ea:84e9:1612 with SMTP id 00721157ae682-6ee55c615d5mr24358737b3.29.1731659576809; Fri, 15 Nov 2024 00:32:56 -0800 (PST) Received: from vb004028-vm1.. ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4635aa37c54sm16584231cf.53.2024.11.15.00.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 00:32:56 -0800 (PST) From: Vamsi Krishna Brahmajosyula To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: yuxuanzhe@outlook.com, linkinjeon@kernel.org, stfrench@microsoft.com, sashal@kernel.org, senozhatsky@chromium.org, tom@talpey.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, ajay.kaher@broadcom.com, alexey.makhalov@broadcom.com, vasavi.sirnapalli@broadcom.com, Vamsi Krishna Brahmajosyula Subject: [PATCH v6.1 1/2] ksmbd: fix slab-out-of-bounds in smb_strndup_from_utf16() Date: Fri, 15 Nov 2024 08:32:39 +0000 Message-Id: <20241115083240.230361-2-vamsi-krishna.brahmajosyula@broadcom.com> X-Mailer: git-send-email 2.39.4 In-Reply-To: <20241115083240.230361-1-vamsi-krishna.brahmajosyula@broadcom.com> References: <20241115083240.230361-1-vamsi-krishna.brahmajosyula@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Namjae Jeon [ Upstream commit a80a486d72e20bd12c335bcd38b6e6f19356b0aa ] If ->NameOffset of smb2_create_req is smaller than Buffer offset of smb2_create_req, slab-out-of-bounds read can happen from smb2_open. This patch set the minimum value of the name offset to the buffer offset to validate name length of smb2_create_req(). Cc: stable@vger.kernel.org Reported-by: Xuanzhe Yu Signed-off-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Sasha Levin Stable-dep-of: c6cd2e8d2d9a ("ksmbd: fix potencial out-of-bounds when buffe= r offset is invalid") Signed-off-by: Vamsi Krishna Brahmajosyula --- fs/smb/server/smb2misc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/smb/server/smb2misc.c b/fs/smb/server/smb2misc.c index 03dded29a980..7c872ffb4b0a 100644 --- a/fs/smb/server/smb2misc.c +++ b/fs/smb/server/smb2misc.c @@ -107,7 +107,10 @@ static int smb2_get_data_area_len(unsigned int *off, u= nsigned int *len, case SMB2_CREATE: { unsigned short int name_off =3D - le16_to_cpu(((struct smb2_create_req *)hdr)->NameOffset); + max_t(unsigned short int, + le16_to_cpu(((struct smb2_create_req *)hdr)->NameOffset), + offsetof(struct smb2_create_req, Buffer)); + unsigned short int name_len =3D le16_to_cpu(((struct smb2_create_req *)hdr)->NameLength); =20 --=20 2.39.4 From nobody Fri Nov 22 22:20:05 2024 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3403C18D65F for ; Fri, 15 Nov 2024 08:33:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731659584; cv=none; b=GnyGdV21vsZlSeA/FkdZLboq4sanI6lIg53xMtENFnEVqSNSWC8FzT0VQPUE9A3FNIm1e0vT8Y422B3TECOQ5gT2Z7ziW0ivHQ/wDmIvHurqhXvMaa8IhhKnmb5cVlbSi1LLp5lHk8YVEV5pnturZJ0YuCUpZmJ7sDfkbF3Hk78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731659584; c=relaxed/simple; bh=2VVsWJrco36QOBvZICeCv8RoEB0WvJ+A8xYHLsPFqVE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u2cvpc8+nE/mYqQi9LcTG/XMQ6LULhhABwSI5punAByxWEs+uGbnFVpcjVIx1Z8KOFqhjT+u+3uKYt3VMpa62mI9UI91t5jMIkC7vTj1L76FWMHh7KiHfBc/FAXEIQ2TXJ56Ewvi8tw7XOBqiiy/MZeYwzm429ihrF32gW+wZt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=eO/OVykJ; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="eO/OVykJ" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-460b16d4534so8572351cf.3 for ; Fri, 15 Nov 2024 00:33:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1731659581; x=1732264381; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d9huFcHpgkOMekePN9oM6pWVjT0WK26mwbaUBeABXVE=; b=eO/OVykJEWQbX43nWxbdhGTb5dgCFVzRSEOzFGfMlwPRVbCuJ3f4/AJEcv/Y4ef4z1 53mGpW5jM4pZTV8FQqCBXbWABhxAqo0TPkpCeOXclqiym4dg7IamjiLIJvJXyrmbKbYf yT5BjT0GxI52Ic3VpM7O3emVD7xZQtSzxUMr4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731659581; x=1732264381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d9huFcHpgkOMekePN9oM6pWVjT0WK26mwbaUBeABXVE=; b=lHBXQF52rBbK1sTAPDoY/degR6bo78ohWVyWPFpeSgYl23y8lqwC8XJMcQ/NIFQtoS 9UPZ50PN8LKDhNe3WrDNOKA7dIfwiedX9Cc0SrF/IvjE08MecOfL6QrLGDS5ccUdewbb PfZDMuKTNWytUSCdXYl0PYUvH8o594QbLQH6rO4ICnbX454iY52mMOp9g6MZCl7TmQcw itmlB/eRDoF++McgejwdNpV6y9Ytcn0d5BI0jkng2e7+Z4OyyMNcI0lD+svTKjXhoMQi /0XZNC1GLGwaucasYPLHV2wfOs8VlSXKEm8qq+ztiwRjPDVLnw2t6D4qnHVooHUSYx4Q l6Ww== X-Forwarded-Encrypted: i=1; AJvYcCUHLhUvOrfNS2Y5/KW5EUCExlZV3EhZi152Q+CIfzlHr+KVdX9EwPaH1I8JQ1GPNEGdePJi1wEWqQNWkPY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+3fFidnXhlGa8qFpknMX6iccSzDfdKFLrfFUfYNemWQO4PLat ODWCJ1HtbhOamWwpqnBXgXJKPV8yMUHHCPTE+EtVVG4eJ2BZnDB3seGsZ9FOWA== X-Google-Smtp-Source: AGHT+IE0ORg2IPxeLB2SEtJk6yiuBs8ng23DcvcNqYuEVaDcG4kAhcSkrVdcc0mE83+uIPPh+d3ZFg== X-Received: by 2002:a05:622a:4815:b0:463:17d2:4b7b with SMTP id d75a77b69052e-46363ec0ab5mr26048091cf.48.1731659581044; Fri, 15 Nov 2024 00:33:01 -0800 (PST) Received: from vb004028-vm1.. ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4635aa37c54sm16584231cf.53.2024.11.15.00.32.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 00:32:59 -0800 (PST) From: Vamsi Krishna Brahmajosyula To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: yuxuanzhe@outlook.com, linkinjeon@kernel.org, stfrench@microsoft.com, sashal@kernel.org, senozhatsky@chromium.org, tom@talpey.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, ajay.kaher@broadcom.com, alexey.makhalov@broadcom.com, vasavi.sirnapalli@broadcom.com, Vamsi Krishna Brahmajosyula Subject: [PATCH v6.1 2/2] ksmbd: fix potencial out-of-bounds when buffer offset is invalid Date: Fri, 15 Nov 2024 08:32:40 +0000 Message-Id: <20241115083240.230361-3-vamsi-krishna.brahmajosyula@broadcom.com> X-Mailer: git-send-email 2.39.4 In-Reply-To: <20241115083240.230361-1-vamsi-krishna.brahmajosyula@broadcom.com> References: <20241115083240.230361-1-vamsi-krishna.brahmajosyula@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Namjae Jeon [ Upstream commit c6cd2e8d2d9aa7ee35b1fa6a668e32a22a9753da ] I found potencial out-of-bounds when buffer offset fields of a few requests is invalid. This patch set the minimum value of buffer offset field to ->Buffer offset to validate buffer length. Cc: stable@vger.kernel.org Signed-off-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Sasha Levin Signed-off-by: Vamsi Krishna Brahmajosyula --- fs/smb/server/smb2misc.c | 23 +++++++++++++------ fs/smb/server/smb2pdu.c | 48 ++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/fs/smb/server/smb2misc.c b/fs/smb/server/smb2misc.c index 7c872ffb4b0a..727cb49926ee 100644 --- a/fs/smb/server/smb2misc.c +++ b/fs/smb/server/smb2misc.c @@ -101,7 +101,9 @@ static int smb2_get_data_area_len(unsigned int *off, un= signed int *len, *len =3D le16_to_cpu(((struct smb2_sess_setup_req *)hdr)->SecurityBuffer= Length); break; case SMB2_TREE_CONNECT: - *off =3D le16_to_cpu(((struct smb2_tree_connect_req *)hdr)->PathOffset); + *off =3D max_t(unsigned short int, + le16_to_cpu(((struct smb2_tree_connect_req *)hdr)->PathOffset), + offsetof(struct smb2_tree_connect_req, Buffer)); *len =3D le16_to_cpu(((struct smb2_tree_connect_req *)hdr)->PathLength); break; case SMB2_CREATE: @@ -110,7 +112,6 @@ static int smb2_get_data_area_len(unsigned int *off, un= signed int *len, max_t(unsigned short int, le16_to_cpu(((struct smb2_create_req *)hdr)->NameOffset), offsetof(struct smb2_create_req, Buffer)); - unsigned short int name_len =3D le16_to_cpu(((struct smb2_create_req *)hdr)->NameLength); =20 @@ -131,11 +132,15 @@ static int smb2_get_data_area_len(unsigned int *off, = unsigned int *len, break; } case SMB2_QUERY_INFO: - *off =3D le16_to_cpu(((struct smb2_query_info_req *)hdr)->InputBufferOff= set); + *off =3D max_t(unsigned int, + le16_to_cpu(((struct smb2_query_info_req *)hdr)->InputBufferOffset= ), + offsetof(struct smb2_query_info_req, Buffer)); *len =3D le32_to_cpu(((struct smb2_query_info_req *)hdr)->InputBufferLen= gth); break; case SMB2_SET_INFO: - *off =3D le16_to_cpu(((struct smb2_set_info_req *)hdr)->BufferOffset); + *off =3D max_t(unsigned int, + le16_to_cpu(((struct smb2_set_info_req *)hdr)->BufferOffset), + offsetof(struct smb2_set_info_req, Buffer)); *len =3D le32_to_cpu(((struct smb2_set_info_req *)hdr)->BufferLength); break; case SMB2_READ: @@ -145,7 +150,7 @@ static int smb2_get_data_area_len(unsigned int *off, un= signed int *len, case SMB2_WRITE: if (((struct smb2_write_req *)hdr)->DataOffset || ((struct smb2_write_req *)hdr)->Length) { - *off =3D max_t(unsigned int, + *off =3D max_t(unsigned short int, le16_to_cpu(((struct smb2_write_req *)hdr)->DataOffset), offsetof(struct smb2_write_req, Buffer)); *len =3D le32_to_cpu(((struct smb2_write_req *)hdr)->Length); @@ -156,7 +161,9 @@ static int smb2_get_data_area_len(unsigned int *off, un= signed int *len, *len =3D le16_to_cpu(((struct smb2_write_req *)hdr)->WriteChannelInfoLen= gth); break; case SMB2_QUERY_DIRECTORY: - *off =3D le16_to_cpu(((struct smb2_query_directory_req *)hdr)->FileNameO= ffset); + *off =3D max_t(unsigned short int, + le16_to_cpu(((struct smb2_query_directory_req *)hdr)->FileNameOffs= et), + offsetof(struct smb2_query_directory_req, Buffer)); *len =3D le16_to_cpu(((struct smb2_query_directory_req *)hdr)->FileNameL= ength); break; case SMB2_LOCK: @@ -171,7 +178,9 @@ static int smb2_get_data_area_len(unsigned int *off, un= signed int *len, break; } case SMB2_IOCTL: - *off =3D le32_to_cpu(((struct smb2_ioctl_req *)hdr)->InputOffset); + *off =3D max_t(unsigned int, + le32_to_cpu(((struct smb2_ioctl_req *)hdr)->InputOffset), + offsetof(struct smb2_ioctl_req, Buffer)); *len =3D le32_to_cpu(((struct smb2_ioctl_req *)hdr)->InputCount); break; default: diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 9b5847bf9b2a..7e068c4187a8 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -1961,7 +1961,7 @@ int smb2_tree_connect(struct ksmbd_work *work) =20 WORK_BUFFERS(work, req, rsp); =20 - treename =3D smb_strndup_from_utf16(req->Buffer, + treename =3D smb_strndup_from_utf16((char *)req + le16_to_cpu(req->PathOf= fset), le16_to_cpu(req->PathLength), true, conn->local_nls); if (IS_ERR(treename)) { @@ -2723,7 +2723,7 @@ int smb2_open(struct ksmbd_work *work) goto err_out2; } =20 - name =3D smb2_get_name(req->Buffer, + name =3D smb2_get_name((char *)req + le16_to_cpu(req->NameOffset), le16_to_cpu(req->NameLength), work->conn->local_nls); if (IS_ERR(name)) { @@ -4096,7 +4096,7 @@ int smb2_query_dir(struct ksmbd_work *work) } =20 srch_flag =3D req->Flags; - srch_ptr =3D smb_strndup_from_utf16(req->Buffer, + srch_ptr =3D smb_strndup_from_utf16((char *)req + le16_to_cpu(req->FileNa= meOffset), le16_to_cpu(req->FileNameLength), 1, conn->local_nls); if (IS_ERR(srch_ptr)) { @@ -4357,7 +4357,8 @@ static int smb2_get_ea(struct ksmbd_work *work, struc= t ksmbd_file *fp, sizeof(struct smb2_ea_info_req)) return -EINVAL; =20 - ea_req =3D (struct smb2_ea_info_req *)req->Buffer; + ea_req =3D (struct smb2_ea_info_req *)((char *)req + + le16_to_cpu(req->InputBufferOffset)); } else { /* need to send all EAs, if no specific EA is requested*/ if (le32_to_cpu(req->Flags) & SL_RETURN_SINGLE_ENTRY) @@ -5971,6 +5972,7 @@ static int smb2_set_info_file(struct ksmbd_work *work= , struct ksmbd_file *fp, struct ksmbd_share_config *share) { unsigned int buf_len =3D le32_to_cpu(req->BufferLength); + char *buffer =3D (char *)req + le16_to_cpu(req->BufferOffset); =20 switch (req->FileInfoClass) { case FILE_BASIC_INFORMATION: @@ -5978,7 +5980,7 @@ static int smb2_set_info_file(struct ksmbd_work *work= , struct ksmbd_file *fp, if (buf_len < sizeof(struct smb2_file_basic_info)) return -EINVAL; =20 - return set_file_basic_info(fp, (struct smb2_file_basic_info *)req->Buffe= r, share); + return set_file_basic_info(fp, (struct smb2_file_basic_info *)buffer, sh= are); } case FILE_ALLOCATION_INFORMATION: { @@ -5986,7 +5988,7 @@ static int smb2_set_info_file(struct ksmbd_work *work= , struct ksmbd_file *fp, return -EINVAL; =20 return set_file_allocation_info(work, fp, - (struct smb2_file_alloc_info *)req->Buffer); + (struct smb2_file_alloc_info *)buffer); } case FILE_END_OF_FILE_INFORMATION: { @@ -5994,7 +5996,7 @@ static int smb2_set_info_file(struct ksmbd_work *work= , struct ksmbd_file *fp, return -EINVAL; =20 return set_end_of_file_info(work, fp, - (struct smb2_file_eof_info *)req->Buffer); + (struct smb2_file_eof_info *)buffer); } case FILE_RENAME_INFORMATION: { @@ -6002,7 +6004,7 @@ static int smb2_set_info_file(struct ksmbd_work *work= , struct ksmbd_file *fp, return -EINVAL; =20 return set_rename_info(work, fp, - (struct smb2_file_rename_info *)req->Buffer, + (struct smb2_file_rename_info *)buffer, buf_len); } case FILE_LINK_INFORMATION: @@ -6011,7 +6013,7 @@ static int smb2_set_info_file(struct ksmbd_work *work= , struct ksmbd_file *fp, return -EINVAL; =20 return smb2_create_link(work, work->tcon->share_conf, - (struct smb2_file_link_info *)req->Buffer, + (struct smb2_file_link_info *)buffer, buf_len, fp->filp, work->conn->local_nls); } @@ -6021,7 +6023,7 @@ static int smb2_set_info_file(struct ksmbd_work *work= , struct ksmbd_file *fp, return -EINVAL; =20 return set_file_disposition_info(fp, - (struct smb2_file_disposition_info *)req->Buffer); + (struct smb2_file_disposition_info *)buffer); } case FILE_FULL_EA_INFORMATION: { @@ -6034,7 +6036,7 @@ static int smb2_set_info_file(struct ksmbd_work *work= , struct ksmbd_file *fp, if (buf_len < sizeof(struct smb2_ea_info)) return -EINVAL; =20 - return smb2_set_ea((struct smb2_ea_info *)req->Buffer, + return smb2_set_ea((struct smb2_ea_info *)buffer, buf_len, &fp->filp->f_path, true); } case FILE_POSITION_INFORMATION: @@ -6042,14 +6044,14 @@ static int smb2_set_info_file(struct ksmbd_work *wo= rk, struct ksmbd_file *fp, if (buf_len < sizeof(struct smb2_file_pos_info)) return -EINVAL; =20 - return set_file_position_info(fp, (struct smb2_file_pos_info *)req->Buff= er); + return set_file_position_info(fp, (struct smb2_file_pos_info *)buffer); } case FILE_MODE_INFORMATION: { if (buf_len < sizeof(struct smb2_file_mode_info)) return -EINVAL; =20 - return set_file_mode_info(fp, (struct smb2_file_mode_info *)req->Buffer); + return set_file_mode_info(fp, (struct smb2_file_mode_info *)buffer); } } =20 @@ -6130,7 +6132,7 @@ int smb2_set_info(struct ksmbd_work *work) } rc =3D smb2_set_info_sec(fp, le32_to_cpu(req->AdditionalInformation), - req->Buffer, + (char *)req + le16_to_cpu(req->BufferOffset), le32_to_cpu(req->BufferLength)); ksmbd_revert_fsids(work); break; @@ -7576,7 +7578,7 @@ static int fsctl_pipe_transceive(struct ksmbd_work *w= ork, u64 id, struct smb2_ioctl_rsp *rsp) { struct ksmbd_rpc_command *rpc_resp; - char *data_buf =3D (char *)&req->Buffer[0]; + char *data_buf =3D (char *)req + le32_to_cpu(req->InputOffset); int nbytes =3D 0; =20 rpc_resp =3D ksmbd_rpc_ioctl(work->sess, id, data_buf, @@ -7689,6 +7691,7 @@ int smb2_ioctl(struct ksmbd_work *work) u64 id =3D KSMBD_NO_FID; struct ksmbd_conn *conn =3D work->conn; int ret =3D 0; + char *buffer; =20 if (work->next_smb2_rcv_hdr_off) { req =3D ksmbd_req_buf_next(work); @@ -7711,6 +7714,8 @@ int smb2_ioctl(struct ksmbd_work *work) goto out; } =20 + buffer =3D (char *)req + le32_to_cpu(req->InputOffset); + cnt_code =3D le32_to_cpu(req->CtlCode); ret =3D smb2_calc_max_out_buf_len(work, 48, le32_to_cpu(req->MaxOutputResponse)); @@ -7768,7 +7773,7 @@ int smb2_ioctl(struct ksmbd_work *work) } =20 ret =3D fsctl_validate_negotiate_info(conn, - (struct validate_negotiate_info_req *)&req->Buffer[0], + (struct validate_negotiate_info_req *)buffer, (struct validate_negotiate_info_rsp *)&rsp->Buffer[0], in_buf_len); if (ret < 0) @@ -7821,7 +7826,7 @@ int smb2_ioctl(struct ksmbd_work *work) rsp->VolatileFileId =3D req->VolatileFileId; rsp->PersistentFileId =3D req->PersistentFileId; fsctl_copychunk(work, - (struct copychunk_ioctl_req *)&req->Buffer[0], + (struct copychunk_ioctl_req *)buffer, le32_to_cpu(req->CtlCode), le32_to_cpu(req->InputCount), req->VolatileFileId, @@ -7834,8 +7839,7 @@ int smb2_ioctl(struct ksmbd_work *work) goto out; } =20 - ret =3D fsctl_set_sparse(work, id, - (struct file_sparse *)&req->Buffer[0]); + ret =3D fsctl_set_sparse(work, id, (struct file_sparse *)buffer); if (ret < 0) goto out; break; @@ -7858,7 +7862,7 @@ int smb2_ioctl(struct ksmbd_work *work) } =20 zero_data =3D - (struct file_zero_data_information *)&req->Buffer[0]; + (struct file_zero_data_information *)buffer; =20 off =3D le64_to_cpu(zero_data->FileOffset); bfz =3D le64_to_cpu(zero_data->BeyondFinalZero); @@ -7889,7 +7893,7 @@ int smb2_ioctl(struct ksmbd_work *work) } =20 ret =3D fsctl_query_allocated_ranges(work, id, - (struct file_allocated_range_buffer *)&req->Buffer[0], + (struct file_allocated_range_buffer *)buffer, (struct file_allocated_range_buffer *)&rsp->Buffer[0], out_buf_len / sizeof(struct file_allocated_range_buffer), &nbytes); @@ -7933,7 +7937,7 @@ int smb2_ioctl(struct ksmbd_work *work) goto out; } =20 - dup_ext =3D (struct duplicate_extents_to_file *)&req->Buffer[0]; + dup_ext =3D (struct duplicate_extents_to_file *)buffer; =20 fp_in =3D ksmbd_lookup_fd_slow(work, dup_ext->VolatileFileHandle, dup_ext->PersistentFileHandle); --=20 2.39.4