From: Ratnaker Gautam <ratnaker.gautam@kuleuven.be> mainline inclusion from mainline-v7.4-rc1 commit 8fc9af68c57156ff64769f30e831553cd03b3000 category: bugfix bugzilla: https://atomgit.com/src-openeuler/kernel/issues/21529 CVE: CVE-2026-99387 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=... -------------------------------- CIFSSMBPosixLock() receives a TRANS2 response whose server-provided DataOffset and DataCount are not required by validate_t2() to describe an interval inside the response. A server can therefore make the client read a cifs_posix_lock beyond the response buffer and return those kernel bytes through F_GETLK. Use smbCalcSize() to obtain the full response length after any multipart TRANS2 reassembly, then reject data areas that extend past it before dereferencing them. Fixes: fc94cdb94462 ("[CIFS] Fix new POSIX Locking for setting lock_type correctly on unlock") Reported-by: Ratnaker Gautam <ratnaker.gautam@kuleuven.be> Cc: stable@vger.kernel.org Signed-off-by: Ratnaker Gautam <ratnaker.gautam@kuleuven.be> Reviewed-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Paulo Alcantara <pc@manguebit.org> Conflicts: fs/smb/client/cifssmb.c [The smb_EIO2()/smb_eio_trace_lock_data_area helpers and smb_eio_traces in trace.h do not exist in this tree, so return -EIO as the neighbouring size checks do and drop the trace.h change.] Signed-off-by: Yifan Qiao <qiaoyifan4@huawei.com> --- fs/smb/client/cifssmb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index dc251338ee7e..27f5f672a992 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -2070,6 +2070,7 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, cifs_dbg(FYI, "Send error in Posix Lock = %d\n", rc); } else if (pLockData) { /* lock structure can be returned on get */ + unsigned int rsp_len; __u16 data_offset; __u16 data_count; rc = validate_t2((struct smb_t2_rsp *)pSMBr); @@ -2078,12 +2079,18 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, rc = -EIO; /* bad smb */ goto plk_err_exit; } + rsp_len = smbCalcSize(&pSMBr->hdr); data_offset = le16_to_cpu(pSMBr->t2.DataOffset); data_count = le16_to_cpu(pSMBr->t2.DataCount); if (data_count < sizeof(struct cifs_posix_lock)) { rc = -EIO; goto plk_err_exit; } + if (data_offset + 4 > rsp_len || + data_count > rsp_len - data_offset - 4) { + rc = -EIO; + goto plk_err_exit; + } parm_data = (struct cifs_posix_lock *) ((char *)&pSMBr->hdr.Protocol + data_offset); if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) -- 2.52.0