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/cifs/cifssmb.c fs/smb/client/trace.h fs/smb/client/cifssmb.c [The SMB1 client lives in fs/cifs/ in this tree, so the bound is applied to fs/cifs/cifssmb.c. The smb_EIO2()/smb_eio_trace_lock_data_area helpers do not exist here, so return -EIO as the neighbouring size checks do; no trace.h change is needed.] Signed-off-by: Yifan Qiao <qiaoyifan4@huawei.com> --- fs/cifs/cifssmb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index bc96b1859cd2..562b09468d59 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -2605,6 +2605,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); @@ -2615,10 +2616,16 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, } data_offset = le16_to_cpu(pSMBr->t2.DataOffset); data_count = le16_to_cpu(pSMBr->t2.DataCount); + rsp_len = smbCalcSize(&pSMBr->hdr, tcon->ses->server); 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