From nobody Wed Dec 17 19:43:40 2025 Received: from baidu.com (mx22.baidu.com [220.181.50.185]) (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 8B9AC2D3A7B; Tue, 7 Oct 2025 08:27:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.181.50.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759825631; cv=none; b=i/EGfxeC/0h129dLyFxexHJoiNjBpkS5DUJSIp5XVwP35geuKmD6IxvzpgYtGMFbiD8Mws3Q0+qyOvaOIN3iKPg9Ai3Eqhq8ZpgQ1kblF+j8cNIl+WnhhH7eln3kO+jc2V3BggLmv2ZNg5mKZVDXcB0Y8C9yJiHlUjZn5T3UTcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759825631; c=relaxed/simple; bh=ea3CNf1RiJZZ25j5Elj7dgmov+X9K/7JdBfMimuSKD8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=n/N57dtlIdNwbAMw8U8IW6cJXCfPAUaXNHmCft83j66IuzB+dYTC1k7ZWbdyBkqPj3w1AQqLP1TCvtPNz78xXmNZ1AX/Vdjs0SkOX77hR7oRDTOxUNq1REQMqdkICYnwgfc5pyMDIrB2lpy+VsU5t39wT7DBoae0f31IA8hNY5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com; spf=pass smtp.mailfrom=baidu.com; arc=none smtp.client-ip=220.181.50.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=baidu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baidu.com From: Fushuai Wang To: , , , , , , CC: , , , Fushuai Wang Subject: [PATCH v5] cifs: Fix copy_to_iter return value check Date: Tue, 7 Oct 2025 16:26:03 +0800 Message-ID: <20251007082603.16174-1-wangfushuai@baidu.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) 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 X-ClientProxiedBy: bjkjy-exc4.internal.baidu.com (172.31.50.48) To bjkjy-exc17.internal.baidu.com (172.31.50.13) X-FEAS-Client-IP: 172.31.50.13 X-FE-Policy-ID: 52:10:53:SYSTEM Content-Type: text/plain; charset="utf-8" The return value of copy_to_iter() function will never be negative, it is the number of bytes copied, or zero if nothing was copied. Update the check to treat 0 as an error, and return -1 in that case. Fixes: d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather = than a page list") Signed-off-by: Fushuai Wang --- v5: no code changes, only improve commit format v4: no code changes, only add version description v3: use size_t type for (copied) and check for (copied =3D=3D 0) as error. v2: use (!length) check for error condition. v1: use (length <=3D 0) check for error condition. fs/smb/client/smb2ops.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 058050f744c0..ac8a5bd6aec4 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -4650,7 +4650,7 @@ handle_read_data(struct TCP_Server_Info *server, stru= ct mid_q_entry *mid, unsigned int pad_len; struct cifs_io_subrequest *rdata =3D mid->callback_data; struct smb2_hdr *shdr =3D (struct smb2_hdr *)buf; - int length; + size_t copied; bool use_rdma_mr =3D false; =20 if (shdr->Command !=3D SMB2_READ) { @@ -4763,10 +4763,10 @@ handle_read_data(struct TCP_Server_Info *server, st= ruct mid_q_entry *mid, } else if (buf_len >=3D data_offset + data_len) { /* read response payload is in buf */ WARN_ONCE(buffer, "read data can be either in buf or in buffer"); - length =3D copy_to_iter(buf + data_offset, data_len, &rdata->subreq.io_i= ter); - if (length < 0) - return length; - rdata->got_bytes =3D data_len; + copied =3D copy_to_iter(buf + data_offset, data_len, &rdata->subreq.io_i= ter); + if (copied =3D=3D 0) + return -1; + rdata->got_bytes =3D copied; } else { /* read response payload cannot be in both buf and pages */ WARN_ONCE(1, "buf can not contain only a part of read data"); --=20 2.36.1