linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: chuck.lever@oracle.com
Cc: linux-nfs@vger.kernel.org, dcritch@redhat.com, d.lesca@solinos.it
Subject: [PATCH 2/2] sunrpc: add bounds checking to svc_rqst_replace_page
Date: Fri, 17 Mar 2023 06:56:08 -0400	[thread overview]
Message-ID: <20230317105608.19393-2-jlayton@kernel.org> (raw)
In-Reply-To: <20230317105608.19393-1-jlayton@kernel.org>

There's no good way to handle this gracefully, but if rq_next_page ends
up pointing outside the array, we can at least crash the box before it
scribbles over too much else.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 net/sunrpc/svc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index fea7ce8fba14..864e62945647 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -845,6 +845,16 @@ EXPORT_SYMBOL_GPL(svc_set_num_threads);
  */
 void svc_rqst_replace_page(struct svc_rqst *rqstp, struct page *page)
 {
+	struct page **begin, **end;
+
+	/*
+	 * Bounds check: make sure rq_next_page points into the rq_respages
+	 * part of the array.
+	 */
+	begin = rqstp->rq_pages;
+	end = &rqstp->rq_pages[RPCSVC_MAXPAGES];
+	BUG_ON(rqstp->rq_next_page < begin || rqstp->rq_next_page > end);
+
 	if (*rqstp->rq_next_page) {
 		if (!pagevec_space(&rqstp->rq_pvec))
 			__pagevec_release(&rqstp->rq_pvec);
-- 
2.39.2


  reply	other threads:[~2023-03-17 10:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-17 10:56 [PATCH 1/2] nfsd: don't replace page in rq_pages if it's a continuation of last page Jeff Layton
2023-03-17 10:56 ` Jeff Layton [this message]
2023-03-17 13:44   ` [PATCH 2/2] sunrpc: add bounds checking to svc_rqst_replace_page Chuck Lever III
2023-03-17 13:52     ` Jeff Layton
2023-03-17 13:54       ` Chuck Lever III
2023-03-17 13:06 ` [PATCH 1/2] nfsd: don't replace page in rq_pages if it's a continuation of last page Jeff Layton
2023-03-17 14:16   ` Chuck Lever III
2023-03-17 14:59     ` Jeff Layton
2023-03-17 15:04       ` Chuck Lever III
2023-03-17 17:23         ` Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230317105608.19393-2-jlayton@kernel.org \
    --to=jlayton@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=d.lesca@solinos.it \
    --cc=dcritch@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).