Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AE6C502771; Thu, 17 Sep 2026 17:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789665210; cv=none; b=ZpJKczf7aAOxzoo5PE7eXNTODbDz+GMttlgMx5XlRBTfDz8KOZ7mQd6X3dV9JRN4sqiN0ogpwqBfcnVWsCOEuqkPGnvmXOZxEPoK/yxUQ8H3D35uS3eRLQ240WIeVVDQ64WUF1L2EXO4vlFnd4Na9KuVqM0Ek4bK42VRpLjgJf0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789665210; c=relaxed/simple; bh=QKV6q0xOTzPithj9z3mR7Po2iSQsNcue0uhIOb5yY8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tBt/JlhqvJqm9Y25sf5wlNNp5mRZJMOEc70AKSCXHjHWThEQHg965q3HgaNUyvhv7hVf9Pe22iA4jTkfSxMzN98DHbdIP/UK8+3Nf9dnXPOZXbE8ngict8O5cjKF6N0XERanQH0LoFFHwEu8nZ4mMIrE9GAeFF3/b4G+EaUA+fs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QLISvT3R; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="QLISvT3R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68BEF1F0089D; Thu, 17 Sep 2026 17:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789665207; bh=RAtLjzkHg310i8FR/L5cztlKMsoTdAlgaGo6gQ4c4us=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QLISvT3RBTo1GYCk8NEM7X9Bd0/+kDXuzYbCcqlS8ok5VBJghzSBb6TvIGieMvYqP EfKgU2OWam2Y4mvBfX0gE3QYC/2X7H5eD2OfKui8xw3qId9l+SJgGZcEKg1CkV01mJ Q8ruDelqgjMuXW6IC+AVq9r4hqJn7ZDkyIMzzWQY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Huiwen He , ChenXiaoSong , Namjae Jeon , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.18 0628/1250] smb/client: validate new EOF for zero range Date: Thu, 17 Sep 2026 16:07:03 +0100 Message-ID: <20260917151608.901455324@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151551.901433442@linuxfoundation.org> References: <20260917151551.901433442@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Huiwen He [ Upstream commit 88972e35750792e717af287dc71f42a03b5cbce4 ] When FALLOC_FL_ZERO_RANGE is used without FALLOC_FL_KEEP_SIZE, smb3_zero_range() may extend EOF without checking RLIMIT_FSIZE, allowing the file to grow beyond the caller's file-size limit. Fix this by calling inode_newsize_ok() before sending the zero-range request when the operation would extend EOF. Reproducer, using a file on a CIFS mount: bash -c ' FILE=/mnt/cifs/repro trap "" SIGXFSZ ulimit -f 3072 truncate -s 2M "$FILE" fallocate --zero-range -o 0 -l 4M "$FILE" echo "fallocate rc=$?" stat -c "file size=%s" "$FILE" ' Before this change, the operation succeeds despite the 3 MiB limit: fallocate rc=0 file size=4194304 After this change, fallocate fails and leaves the file at 2 MiB. Fixes: 72c419d9b073 ("cifs: fix smb3_zero_range so it can expand the file-size when required") Signed-off-by: Huiwen He Reviewed-by: ChenXiaoSong Reviewed-by: Namjae Jeon Signed-off-by: Paulo Alcantara Signed-off-by: Sasha Levin --- fs/smb/client/smb2ops.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 542823110c58e..0a9d29b1c437f 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3380,6 +3380,13 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid, ses->Suid, offset, len); + new_size = offset + len; + if (!keep_size && i_size_read(inode) < new_size) { + rc = inode_newsize_ok(inode, new_size); + if (rc) + goto out; + } + filemap_invalidate_lock(inode->i_mapping); i_size = i_size_read(inode); @@ -3411,7 +3418,6 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, /* * do we also need to change the size of the file? */ - new_size = offset + len; if (keep_size == false && (unsigned long long)i_size_read(inode) < new_size) { rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid, cfile->pid, new_size); @@ -3426,6 +3432,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, zero_range_exit: filemap_invalidate_unlock(inode->i_mapping); + out: free_xid(xid); if (rc) trace_smb3_zero_err(xid, cfile->fid.persistent_fid, tcon->tid, -- 2.53.0