From mboxrd@z Thu Jan 1 00:00:00 1970 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 233923368A5; Tue, 21 Jul 2026 20:54:23 +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=1784667264; cv=none; b=elS8+r94O63hNlANdHoLP5sM/OGj3OeARx/VopvJYNDBi/qU7XWn8ROVKFCDp7PWpubXasZzBeoBajAb9LSZtZHeH7GaReFmdbz8TJdC+XMkr3eZuYgfvM9I5Gvzk+7BdjU5wk6O1y5hD1tzpkRnVBJ1Q5IphcxPaiP0el03e04= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784667264; c=relaxed/simple; bh=V5zziDHrzqgWN4WMt8vtd0Nkpt72O4YCHELPrWJxzoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TJRKIN8CPI+gGQziLgtUjzjZgBKJlKvvp2XS+zIvQ9j9sZHf5087JkJeVvlltfKVRBLO2W4qxAvG87Q4V89jtzblyOGBuVM3x7ix52/5m/rTuHhnhaKrp0O+q3GPGye16oUdosOGmXt2oBsPgW4mCC02eHonavOBCdfnXebytZ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=KHcPmkNl; 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="KHcPmkNl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A1F61F000E9; Tue, 21 Jul 2026 20:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784667263; bh=9GbPlF5vm7hRFGgW9pSLVF5T10RtJP0J0fNEyDN1CrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KHcPmkNllY7OhpKwrCFMKWM9GN4ggEKgmT12Jd/QzlXSF3ZAw32mWHPbVFNkWwbJK SYaC4a7PSHznYDL7SkbZErBKHjEQOfmbyVizaUROSySVFfsoC5hy/p93RV+W5b4TXK bi3rfxqkC3LzYDF1WDirQ3PYpldnHsG5jS02tKt0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Jeff Layton , Chuck Lever Subject: [PATCH 6.6 0968/1266] SUNRPC: Bound-check xdr_buf_to_bvec() stores before writing Date: Tue, 21 Jul 2026 17:23:25 +0200 Message-ID: <20260721152503.492917897@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chuck Lever commit 42f5b80dda6b86e424054baf1475df686c403d5c upstream. xdr_buf_to_bvec() writes a bio_vec into the caller's array before testing whether that slot is in range, and the head branch performs the store with no check at all. When the caller's budget is exactly used up, the next store lands one element past the end of the array. The overflow label returns count - 1, which masks the surplus store but cannot undo it. rq_bvec, the array passed by nfsd_vfs_write(), is allocated to exactly rq_maxpages entries with no slack. The OOB store can land in adjacent slab memory; the bv_len and bv_offset fields written there are derived from client-supplied RPC payload sizes. Move the in-range check ahead of the store in the head, page-loop, and tail branches. With the check at the top of each sequence, count is incremented only after a successful store, so the overflow label can return count directly. Reported-by: Chris Mason Fixes: 2eb2b9358181 ("SUNRPC: Convert svc_tcp_sendmsg to use bio_vecs directly") Cc: stable@vger.kernel.org Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- net/sunrpc/xdr.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c @@ -180,6 +180,8 @@ unsigned int xdr_buf_to_bvec(struct bio_ unsigned int count = 0; if (head->iov_len) { + if (unlikely(count >= bvec_size)) + goto bvec_overflow; bvec_set_virt(bvec++, head->iov_base, head->iov_len); ++count; } @@ -193,25 +195,27 @@ unsigned int xdr_buf_to_bvec(struct bio_ while (remaining > 0) { len = min_t(unsigned int, remaining, PAGE_SIZE - offset); + if (unlikely(count >= bvec_size)) + goto bvec_overflow; bvec_set_page(bvec++, *pages++, len, offset); remaining -= len; offset = 0; - if (unlikely(++count > bvec_size)) - goto bvec_overflow; + ++count; } } if (tail->iov_len) { - bvec_set_virt(bvec, tail->iov_base, tail->iov_len); - if (unlikely(++count > bvec_size)) + if (unlikely(count >= bvec_size)) goto bvec_overflow; + bvec_set_virt(bvec, tail->iov_base, tail->iov_len); + ++count; } return count; bvec_overflow: pr_warn_once("%s: bio_vec array overflow\n", __func__); - return count - 1; + return count; } /**