FAILED: patch "[PATCH] svcrdma: Reject Write/Reply chunks with segcount 0" failed to apply to 5.15-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 9808eb7656666acc7291bae9ab6b987bd16e47e0
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090344-perfume-python-398c@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 9808eb7656666acc7291bae9ab6b987bd16e47e0 Mon Sep 17 00:00:00 2001
From: Chris Mason <[email protected]>
Date: Tue, 26 May 2026 09:35:59 -0400
Subject: [PATCH] svcrdma: Reject Write/Reply chunks with segcount 0
A peer can send a Write or Reply chunk whose segcount field is zero. xdr_check_write_chunk() only rejects segcount > rc_maxpages, so zero passes the range check, and xdr_inline_decode(stream, 0) returns the current (non-NULL) cursor without advancing. The function returns true and pcl_alloc_write() then links a struct svc_rdma_chunk with ch_segcount == 0 onto rc_write_pcl or rc_reply_pcl.
An earlier patch in this series made pcl_for_each_segment() safe for ch_segcount == 0, so this no longer drives the memory walk it used to. Rejecting the malformed frame at the decode boundary is still worthwhile as defense in depth: it keeps degenerate zero-segment chunks off the parsed chunk lists entirely, so any future consumer that walks ch_segments directly cannot observe one, and it makes the zero-floor easy to backport to trees where the macro change is more intrusive. RFC 8166 has no meaning for a Write/Reply chunk that describes no remote buffer, so no legitimate client is affected.
xdr_check_reply_chunk() funnels Reply chunks through xdr_check_write_chunk() and inherits the same rejection.
pcl_alloc_write() also links each chunk onto the parsed chunk list before filling its segment array. If a future change weakens the segcount-0 rejection, an incomplete chunk is visible to consumers during the fill loop. Reorder so that list_add_tail() follows the segment fill loop, ensuring only fully-populated chunks appear on the list.
net/sunrpc/xprtrdma/svc_rdma_pcl.c +1 -1
@@ -213,7 +213,6 @@ bool pcl_alloc_write(struct svc_rdma_recv_ctxt *rctxt, chunk =pcl_alloc_chunk (segcount,0 );if (!chunk)return false; -list_add_tail (&chunk->ch_list, &pcl->cl_chunks);for (j =0 ; j < segcount; j++) { segment = &chunk->ch_segments[j];
@@ -225,6 +224,7 @@ bool pcl_alloc_write(struct svc_rdma_recv_ctxt *rctxt, chunk->ch_length += segment->rs_length; chunk->ch_segcount++; } +list_add_tail (&chunk->ch_list, &pcl->cl_chunks); }return true; }
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +6 -3
@@ -510,10 +510,13 @@ static bool xdr_check_write_chunk(struct svc_rdma_recv_ctxt *rctxt)return false;/* Before trusting the segcount value enough to use it in -* a computation, perform a simple range check. This is an -* arbitrary but sensible limit (ie, not architectural). +* a computation, perform a simple range check. A zero +* segcount describes no remote buffer and is rejected so +* downstream consumers never see a degenerate ch_segcount==0 +* chunk. The upper bound is an arbitrary but sensible limit +* (ie, not architectural). */ -if (unlikely (segcount > rctxt->rc_maxpages)) +if (segcount ==0 ||unlikely (segcount > rctxt->rc_maxpages))return false; p = xdr_inline_decode(&rctxt->rc_stream,
Sasha Levin
maintainerPATCH 1/3 svcrdma: Add back svc_rdma_recv_ctxt::rc_pages
From: Chuck Lever <[email protected]>
[ Upstream commit 4d9d69db898d05bd063548eee65d16a020676fec ]
Having an nfsd thread waiting for an RDMA Read completion is problematic if the Read responder (the client) stops responding. We need to go back to handling RDMA Reads by allowing the nfsd thread to return to the svc scheduler, then waking a second thread finish the RPC message once the Read completion fires.
To start with, restore the rc_pages field so that RDMA Read pages can be managed across calls to svc_rdma_recvfrom().
Stable-dep-of: 9808eb765666 ("svcrdma: Reject Write/Reply chunks with segcount 0")
--- include/linux/sunrpc/svc_rdma.h | 4 +++- net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 5 +++++ net/sunrpc/xprtrdma/svc_rdma_rw.c | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-)
include/linux/sunrpc/svc_rdma.h +3 -1
@@ -137,7 +137,6 @@ struct svc_rdma_recv_ctxt {struct xdr_stream rc_stream;bool rc_temp;u32 rc_byte_len; -unsigned int rc_page_count;u32 rc_inv_rkey;__be32 rc_msgtype;
@@ -147,6 +146,9 @@ struct svc_rdma_recv_ctxt {struct svc_rdma_chunk *rc_cur_result_payload;struct svc_rdma_pcl rc_write_pcl;struct svc_rdma_pcl rc_reply_pcl; + +unsigned int rc_page_count; +struct page *rc_pages[RPCSVC_MAXPAGES ]; };struct svc_rdma_send_ctxt {
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +5 -0
@@ -227,6 +227,11 @@ struct svc_rdma_recv_ctxt *svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma)void svc_rdma_recv_ctxt_put (struct svcxprt_rdma *rdma,struct svc_rdma_recv_ctxt *ctxt) { +/* @rc_page_count is normally zero here, but error flows +* can leave pages in @rc_pages. +*/ +release_pages (ctxt->rc_pages, ctxt->rc_page_count); +pcl_free (&ctxt->rc_call_pcl);pcl_free (&ctxt->rc_read_pcl);pcl_free (&ctxt->rc_write_pcl);
net/sunrpc/xprtrdma/svc_rdma_rw.c +3 -1
@@ -1137,7 +1137,9 @@ int svc_rdma_process_read_list(struct svcxprt_rdma *rdma, rqstp->rq_respages = &rqstp->rq_pages[head->rc_page_count]; rqstp->rq_next_page = rqstp->rq_respages +1 ; -/* Ensure svc_rdma_recv_ctxt_put() does not try to release pages */ +/* Ensure svc_rdma_recv_ctxt_put() does not release pages +* left in @rc_pages while I/O proceeds. +*/ head->rc_page_count =0 ; out_err:
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 svcrdma: Adjust the number of entries in svc_rdma_recv_ctxt::rc_pages
From: Chuck Lever <[email protected]>
[ Upstream commit 81381d1a90dea186ce4585d9bd3cdc40b50e9c48 ]
Allow allocation of more entries in the rc_pages[] array when the maximum size of an RPC message is increased.
For the 5.15 backport, keep the existing kmalloc allocation policy and size the flexible rc_pages array with RPCSVC_MAXPAGES. This tree retains fixed-size RPC request page arrays and does not have svc_serv_maxpages(), so using the existing limit preserves both allocation capacity and the accepted segment-count upper bound without adding a helper function. Omit __counted_by, which is not available in this tree.
Retain rc_maxpages and use it in xdr_check_write_chunk() so that target 9808eb765666 ("svcrdma: Reject Write/Reply chunks with segcount 0") applies without changes. Initialize rc_maxpages before the context is published.
Include linux/pagemap.h explicitly for release_pages(). The preceding rc_pages backport added this call without its declaration, causing an implicit-function-declaration build error on this stable tree.
Stable-dep-of: 9808eb765666 ("svcrdma: Reject Write/Reply chunks with segcount 0")
--- include/linux/sunrpc/svc_rdma.h | 3 ++- net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)
include/linux/sunrpc/svc_rdma.h +2 -1
@@ -148,7 +148,8 @@ struct svc_rdma_recv_ctxt {struct svc_rdma_pcl rc_reply_pcl;unsigned int rc_page_count; -struct page *rc_pages[RPCSVC_MAXPAGES ]; +unsigned long rc_maxpages; +struct page *rc_pages[]; };struct svc_rdma_send_ctxt {
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +6 -2
@@ -92,6 +92,7 @@* are transferred from the svc_rdma_recv_ctxt to the second svc_rqst. */ +#include <linux/pagemap.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <asm/unaligned.h>
@@ -126,12 +127,15 @@ static struct svc_rdma_recv_ctxt * svc_rdma_recv_ctxt_alloc(struct svcxprt_rdma *rdma) {struct svc_rdma_recv_ctxt *ctxt; +unsigned long pages;dma_addr_t addr;void *buffer; - ctxt =kmalloc (sizeof (*ctxt),GFP_KERNEL ); + pages =RPCSVC_MAXPAGES ; + ctxt =kmalloc (struct_size (ctxt, rc_pages, pages),GFP_KERNEL );if (!ctxt) goto fail0; + ctxt->rc_maxpages = pages; buffer =kmalloc (rdma->sc_max_req_size,GFP_KERNEL );if (!buffer) goto fail1;
@@ -486,7 +490,7 @@ static bool xdr_check_write_chunk(struct svc_rdma_recv_ctxt *rctxt)* a computation, perform a simple range check. This is an * arbitrary but sensible limit (ie, not architectural). */ -if (unlikely (segcount >RPCSVC_MAXPAGES )) +if (unlikely (segcount > rctxt->rc_maxpages))return false; p = xdr_inline_decode(&rctxt->rc_stream,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 svcrdma: Reject Write/Reply chunks with segcount 0
In reply to Sasha LevinFrom: Chris Mason <[email protected]>
[ Upstream commit 9808eb7656666acc7291bae9ab6b987bd16e47e0 ]
A peer can send a Write or Reply chunk whose segcount field is zero. xdr_check_write_chunk() only rejects segcount > rc_maxpages, so zero passes the range check, and xdr_inline_decode(stream, 0) returns the current (non-NULL) cursor without advancing. The function returns true and pcl_alloc_write() then links a struct svc_rdma_chunk with ch_segcount == 0 onto rc_write_pcl or rc_reply_pcl.
An earlier patch in this series made pcl_for_each_segment() safe for ch_segcount == 0, so this no longer drives the memory walk it used to. Rejecting the malformed frame at the decode boundary is still worthwhile as defense in depth: it keeps degenerate zero-segment chunks off the parsed chunk lists entirely, so any future consumer that walks ch_segments directly cannot observe one, and it makes the zero-floor easy to backport to trees where the macro change is more intrusive. RFC 8166 has no meaning for a Write/Reply chunk that describes no remote buffer, so no legitimate client is affected.
xdr_check_reply_chunk() funnels Reply chunks through xdr_check_write_chunk() and inherits the same rejection.
pcl_alloc_write() also links each chunk onto the parsed chunk list before filling its segment array. If a future change weakens the segcount-0 rejection, an incomplete chunk is visible to consumers during the fill loop. Reorder so that list_add_tail() follows the segment fill loop, ensuring only fully-populated chunks appear on the list.
--- net/sunrpc/xprtrdma/svc_rdma_pcl.c | 2 +- net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_pcl.c +1 -1
@@ -213,7 +213,6 @@ bool pcl_alloc_write(struct svc_rdma_recv_ctxt *rctxt, chunk =pcl_alloc_chunk (segcount,0 );if (!chunk)return false; -list_add_tail (&chunk->ch_list, &pcl->cl_chunks);for (j =0 ; j < segcount; j++) { segment = &chunk->ch_segments[j];
@@ -225,6 +224,7 @@ bool pcl_alloc_write(struct svc_rdma_recv_ctxt *rctxt, chunk->ch_length += segment->rs_length; chunk->ch_segcount++; } +list_add_tail (&chunk->ch_list, &pcl->cl_chunks); }return true; }
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +6 -3
@@ -487,10 +487,13 @@ static bool xdr_check_write_chunk(struct svc_rdma_recv_ctxt *rctxt)return false;/* Before trusting the segcount value enough to use it in -* a computation, perform a simple range check. This is an -* arbitrary but sensible limit (ie, not architectural). +* a computation, perform a simple range check. A zero +* segcount describes no remote buffer and is rejected so +* downstream consumers never see a degenerate ch_segcount==0 +* chunk. The upper bound is an arbitrary but sensible limit +* (ie, not architectural). */ -if (unlikely (segcount > rctxt->rc_maxpages)) +if (segcount ==0 ||unlikely (segcount > rctxt->rc_maxpages))return false; p = xdr_inline_decode(&rctxt->rc_stream,
Signature · 1 line
2.53.0