From patchwork Wed Dec 9 14:47:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11961693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C5F2C2BBCD for ; Wed, 9 Dec 2020 14:49:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C07A23406 for ; Wed, 9 Dec 2020 14:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733109AbgLIOtf (ORCPT ); Wed, 9 Dec 2020 09:49:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:50716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733113AbgLIOtf (ORCPT ); Wed, 9 Dec 2020 09:49:35 -0500 From: trondmy@kernel.org Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-nfs@vger.kernel.org Subject: [PATCH 14/16] NFSv4.2: Deal with potential READ_PLUS data extent buffer overflow Date: Wed, 9 Dec 2020 09:47:59 -0500 Message-Id: <20201209144801.700778-15-trondmy@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201209144801.700778-14-trondmy@kernel.org> References: <20201209144801.700778-1-trondmy@kernel.org> <20201209144801.700778-2-trondmy@kernel.org> <20201209144801.700778-3-trondmy@kernel.org> <20201209144801.700778-4-trondmy@kernel.org> <20201209144801.700778-5-trondmy@kernel.org> <20201209144801.700778-6-trondmy@kernel.org> <20201209144801.700778-7-trondmy@kernel.org> <20201209144801.700778-8-trondmy@kernel.org> <20201209144801.700778-9-trondmy@kernel.org> <20201209144801.700778-10-trondmy@kernel.org> <20201209144801.700778-11-trondmy@kernel.org> <20201209144801.700778-12-trondmy@kernel.org> <20201209144801.700778-13-trondmy@kernel.org> <20201209144801.700778-14-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If the server returns more data than we have buffer space for, then we need to truncate and exit early. Signed-off-by: Trond Myklebust --- fs/nfs/nfs42xdr.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/nfs/nfs42xdr.c b/fs/nfs/nfs42xdr.c index 9ef5261a1a70..8386ca45a43f 100644 --- a/fs/nfs/nfs42xdr.c +++ b/fs/nfs/nfs42xdr.c @@ -1026,6 +1026,7 @@ static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *re } static int decode_read_plus_data(struct xdr_stream *xdr, + struct nfs_pgio_args *args, struct nfs_pgio_res *res) { uint32_t count, recvd; @@ -1041,8 +1042,12 @@ static int decode_read_plus_data(struct xdr_stream *xdr, recvd = xdr_align_data(xdr, res->count, xdr_align_size(count)); if (recvd > count) recvd = count; + if (res->count + recvd > args->count) { + if (args->count > res->count) + res->count += args->count - res->count; + return 1; + } res->count += recvd; - if (count > recvd) return 1; return 0; @@ -1119,7 +1124,7 @@ static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res) type = be32_to_cpup(p++); if (type == NFS4_CONTENT_DATA) - status = decode_read_plus_data(xdr, res); + status = decode_read_plus_data(xdr, args, res); else if (type == NFS4_CONTENT_HOLE) status = decode_read_plus_hole(xdr, args, res, &eof); else