From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-133.mta1.migadu.com [95.215.58.133]) (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 CF2A1368D71 for ; Sun, 23 Aug 2026 15:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787497903; cv=none; b=qWHsNG+54U8BTK8uVKOAeVv1kpYLORzJK1uj52qmjIRZP3UIbe9lIoaNKVFCpy5PN9e4YM5nC8UbAZWVJ+14YcwjSWK0FDpw+9tOowz/2yvpJMroi+/1jm+lun9/yQp1mT5b0NM9nmwEEZ7w/N4zVIQHte7lKC16aIT07vKp2ls= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787497903; c=relaxed/simple; bh=D9mqq6agSOYQ0eaVwBGh6Xa9bT4lViPNUIKGYdd53ec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GgG7mE3UN1nuJ3s/Q6mxtOS0arn5MnnPxIYWfJNzoioFmYCCqGFZ0fpV/sROQvMm7Em5g6Hixlg7w8Hudu7+zhxQjED5pugY83xaz6xZpfc4W1W2EmDRv1evt+Mpg+OiUxR78SXDRI30gH+hx76RMAyNRYLUxJ8W4FXakCQ1oA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=splEc6sD; arc=none smtp.client-ip=95.215.58.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="splEc6sD" X-Envelope-To: linux-cifs@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=D9mqq6agSOYQ0eaVwBGh6Xa9bT4lViPNUIKGYdd53ec=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787497899; v=1; x=1788102699; b=splEc6sDP1y4VW39NUeeunKHr/9trDfOXVoSzMsaTATM7SD+D8rtu0690u81hZOTboLPXyVl jiAKkg2GrE1cCeSzYMHGESiSv42Pxysmrl5pGkN5pjQIfuvgcfpiIMk8gIp8dZZvR4qiN8DRsB9 o7kjIt2AGGlFXH5SsVDaErGQ= X-Envelope-To: linux-cifs@vger.kernel.org Received: from localhost.localdomain (2408:8352:470:269e:918b:d2e0:eaa5:de79) by smtp.migadu.com with ESMTPS id 405a73f8728b71b3; Sun, 23 Aug 2026 15:11:39 +0000 X-Mizu-Trace-ID: 405a73f8728b71b3 X-Migadu-Flow: FLOW_OUT From: Huiwen He To: linkinjeon@kernel.org, pc@manguebit.org, ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com, senozhatsky@chromium.org, dhowells@redhat.com, chenxiaosong@kylinos.cn Cc: linux-cifs@vger.kernel.org Subject: [PATCH v3 2/7] smb/client: validate new EOF for zero range Date: Sun, 23 Aug 2026 23:10:48 +0800 Message-ID: <20260823151053.935889-3-huiwen.he@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260823151053.935889-1-huiwen.he@linux.dev> References: <20260823151053.935889-1-huiwen.he@linux.dev> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Huiwen He 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 --- 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 bc7dda6d825a..f823f9bc90eb 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3442,6 +3442,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); netfs_read_sizes(inode, &i_size, &remote_i_size, &zero_point); @@ -3472,7 +3479,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); @@ -3489,6 +3495,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.43.0