Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1087126rwe; Thu, 1 Sep 2022 12:17:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR4zr2t4KnEiIe1thgTJok7rFrTb/iPpw+qB6iID3fVZlF/0428QL9t+WGbllNkJXO+Wb2Np X-Received: by 2002:a17:907:2d86:b0:741:8888:de8 with SMTP id gt6-20020a1709072d8600b0074188880de8mr15156160ejc.547.1662059829129; Thu, 01 Sep 2022 12:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662059829; cv=none; d=google.com; s=arc-20160816; b=OMlW8hGHWNsebflAGzFyDMII1OEODo/S4WbR1Sxx2pyzTzFHHfZsU+unI69fd5WKCf oTecj4DM7IkFbL+CDxD4IsXyVUUscM26GdxJPXt0NOdSd0upuMwMKvSSkjdtI25oJ09D PiDssE2tRJuzOkBU1LJfYrdlrsb/bkkjpt6LaIBlHZbpRsRArms8xA1wSEIaKLpamKxY 3jnrr19Yigkozv5ptaVtycPGyalM3R/iMhGU3NQhPx4XxYU/2tNQzWrTAD2VG2Ha5/yA 8tri4KKaYPJsoXwFFRAOvSxoCBXdmucQZRunJ1zP3czbMC6RYgQKIQGZ+/rRJobCaZeT KXQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject; bh=T9Qv/3S8xQSLOq56mwmViuLo7ykpTshQvAPP8PTq064=; b=tgQp+U5JoPLc9B6//xsUwAk3l7bGVWtID/zzAkom29XSLKZBVoKu3jyR/OJZaO/qQa ISLOuyoQpYDh467DagnF17c4KS8SwUAweCGepJR4+QdkEgFSKY1fUJA7DZ/zeb9M+Wh5 Vre1+ryp368y4ERxo4iQBI5fDUrC9SU7Ony64WCqbXHPvQLY4rjGg7saksS0ipIuDqG+ 9AHGN3XSBXd+PgqFDOhMgL4EAElKyagTLMVEIQY6jKcm7Kg4BKsy57F8Hpntj1uAlDcT uLJQMPOwfX2sFhcxWbubqnGnOGqBq/1nk28XFmdQpqBbojN5Y8PbGnL/Y3STX0rh42ZO EFpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a056402510c00b00443a8854bd1si2659393edd.219.2022.09.01.12.16.44; Thu, 01 Sep 2022 12:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233668AbiIATKB (ORCPT + 99 others); Thu, 1 Sep 2022 15:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233598AbiIATJ7 (ORCPT ); Thu, 1 Sep 2022 15:09:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF888BC8C for ; Thu, 1 Sep 2022 12:09:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7971DB828CE for ; Thu, 1 Sep 2022 19:09:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03E79C433D6; Thu, 1 Sep 2022 19:09:53 +0000 (UTC) Subject: [PATCH v3 1/6] SUNRPC: Fix svcxdr_init_decode's end-of-buffer calculation From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Thu, 01 Sep 2022 15:09:53 -0400 Message-ID: <166205939308.1435.11978929988056383822.stgit@manet.1015granger.net> In-Reply-To: <166204973526.1435.6068003336048840051.stgit@manet.1015granger.net> References: <166204973526.1435.6068003336048840051.stgit@manet.1015granger.net> User-Agent: StGit/1.5.dev2+g9ce680a5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Ensure that stream-based argument decoding can't go past the actual end of the receive buffer. xdr_init_decode's calculation of the value of xdr->end over-estimates the end of the buffer because the Linux kernel RPC server code does not remove the size of the RPC header from rqstp->rq_arg before calling the upper layer's dispatcher. The server-side still uses the svc_getnl() macros to decode the RPC call header. These macros reduce the length of the head iov but do not update the total length of the message in the buffer (buf->len). A proper fix for this would be to replace the use of svc_getnl() and friends in the RPC header decoder, but that would be a large and invasive change that would be difficult to backport. Fixes: 5191955d6fc6 ("SUNRPC: Prepare for xdr_stream-style decoding on the server-side") Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever --- include/linux/sunrpc/svc.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index daecb009c05b..5a830b66f059 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -544,16 +544,27 @@ static inline void svc_reserve_auth(struct svc_rqst *rqstp, int space) } /** - * svcxdr_init_decode - Prepare an xdr_stream for svc Call decoding + * svcxdr_init_decode - Prepare an xdr_stream for Call decoding * @rqstp: controlling server RPC transaction context * + * This function currently assumes the RPC header in rq_arg has + * already been decoded. Upon return, xdr->p points to the + * location of the upper layer header. */ static inline void svcxdr_init_decode(struct svc_rqst *rqstp) { struct xdr_stream *xdr = &rqstp->rq_arg_stream; - struct kvec *argv = rqstp->rq_arg.head; + struct xdr_buf *buf = &rqstp->rq_arg; + struct kvec *argv = buf->head; - xdr_init_decode(xdr, &rqstp->rq_arg, argv->iov_base, NULL); + /* + * svc_getnl() and friends do not keep the xdr_buf's ::len + * field up to date. Refresh that field before initializing + * the argument decoding stream. + */ + buf->len = buf->head->iov_len + buf->page_len + buf->tail->iov_len; + + xdr_init_decode(xdr, buf, argv->iov_base, NULL); xdr_set_scratch_page(xdr, rqstp->rq_scratch_page); }