From patchwork Sat Oct 22 07:21:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7314 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1093440wrr; Sat, 22 Oct 2022 00:57:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4K2ZzasXohaxprUXjh8rCU5B99Q2Q4R36wY9x0eO+bfBv5Adf9Cf6k36vvQsTiBRGB1qrU X-Received: by 2002:a05:6a00:1943:b0:563:8173:b46a with SMTP id s3-20020a056a00194300b005638173b46amr22749769pfk.34.1666425438484; Sat, 22 Oct 2022 00:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425438; cv=none; d=google.com; s=arc-20160816; b=zTMPCSxid7u5Dsz3HQLOYjSEsvTf7EbcGj9fQUX7glPsKemu16jE/OrTEjsy1JM5Wh +rL28nAnSgs7Z6fDJg6tUhKelMMEt7TRgke959Hny0BmsHtNeXfxva/kdwuh8hUI02x0 iKMriLQa4+OdNEmnVUJ8k7JtYfCwz6G5vczm+Aw6qyEvfacvsxPkZS9brm/tofhCXx4g tIfeH+OVbf2klkEeJ1q7Gkgme13VexqUM+Kcd2ELBss29M9kh2YMclStbX/JwsTH8gVR 1mr0uJBFHFa5RqfDxRbKApQF2h+wX2IQdt70NAEe/2ZzNIgZe2Yg0G/TVPZeR6dG1Fph f27g== 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:subject:cc:to :from:dkim-signature; bh=22oRgqIlYo9nQXF/ZTBVDDa7qujvpB2JdPONsPwpRso=; b=T0He5E9IQX7n95HOw18D1UWphhHBnwONlb/lGq2gp8ASR8ez84rGqbC9WhL2ZEX/Ac lVf2FgizLUXemAAFF+8olmvS+Ln6XyAMAYLrV4Gv50BKcc/s808j49XP2qWeeNppFBG3 6aArJ/KDrJJ2LkYMgmA7qJes+DhrEIPva6cCPamzl9kFwa+VbbdgN0um9WOUC5LNKuLo Gi1wk+VyLR/in66JmVPxJ+zQIZQiiqikgHc3sEfBxhQ2GSBCHGJIiMGQso6wHMAqr0M4 EKMX2sgxrZcYNL60aqoeknEQc7Penn0lXgnKxOujxcWdmS6dQHg6sxj48ND8mf2oTyq5 nDCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R0KGsLZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m185-20020a633fc2000000b0043c69a39e26si27854573pga.215.2022.10.22.00.57.06; Sat, 22 Oct 2022 00:57:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R0KGsLZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232147AbiJVH4u (ORCPT + 99 others); Sat, 22 Oct 2022 03:56:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbiJVHwv (ORCPT ); Sat, 22 Oct 2022 03:52:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65CF82C6EB9; Sat, 22 Oct 2022 00:46:50 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1389960BAD; Sat, 22 Oct 2022 07:44:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29A9AC433C1; Sat, 22 Oct 2022 07:44:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424676; bh=UCOXvJhWORPwHaVSbJcOe6oEVxI7zAC7T2lMUEbvagY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R0KGsLZPtQjdxa7QHhx+lBNcSbOWEC4Fek+owrztrjE2t3V2J2qKaJDb9+6gL1L9p U4lFN4rAgPmAaD7w7QjhvBLdrc+TkKaCcvCqxYwaXQLQIKelX8FzY3X8bt8pX3LW8L PBgGA0mPfGZk0YXoGoEUPsR/mybnXbj1BRHxzmlI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Layton , Chuck Lever , Sasha Levin Subject: [PATCH 5.19 195/717] SUNRPC: Fix svcxdr_init_decodes end-of-buffer calculation Date: Sat, 22 Oct 2022 09:21:14 +0200 Message-Id: <20221022072450.024803795@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373720325091303?= X-GMAIL-MSGID: =?utf-8?q?1747373720325091303?= From: Chuck Lever [ Upstream commit 90bfc37b5ab91c1a6165e3e5cfc49bf04571b762 ] 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 Signed-off-by: Sasha Levin --- 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); }