Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4059090pxu; Wed, 9 Dec 2020 07:24:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqTCcaa9kT0+7tT4X+BYzVaLD2LA6bECB73CFsCgbEAOn3c12CBeXKT39c7Dp4PKvaN80f X-Received: by 2002:a17:906:c193:: with SMTP id g19mr2436916ejz.393.1607527486148; Wed, 09 Dec 2020 07:24:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607527486; cv=none; d=google.com; s=arc-20160816; b=Ot+D/NmkJkGNik9AcNNTzqBvFeE+r434JdkeEPz3QmwdaWDVycbFv5vnhvcL3L1o6F Lf3PUHfMd8n6KV3zNhVwskwLDFOcHEoQJSGSiMbIWbUabKgcORlU/iweW01yBEYq9fxo fTfYUALL8WogacACLl6AUQQkRoYsZVRz/mNt44tQq1Ehid/j+rTHy7JEXdpR4aTx7Jbf jxdWVMeBvc4GMADjrmcba77Zp8YHcBnWAcwhi0KQQQxKS/Xa16Fdc5pzhJ7K6MsiB+O6 0+mYl+/QZZDfRkQ5qdCvXOLBlaO06pmjAGbmAV7cA1ycdIWPb4Vd1ufDNBiMUvQek+Ru YhIg== 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 :references:in-reply-to:message-id:date:subject:to:from; bh=59HfGvyHheWM1RFrIxefrrU/ZJ3DeXiSwOQOQt4RJRw=; b=gIE+QzdiHQUxmJucQJHHm/YbAcdahwTj1Xg40qKqsvoYpvsmtaTYtcOahYBxyZhzjT HRHqGlzmqn14aW809+OgK1gRnK5D1HXBRlnEs8KwLmNBHwfgwMKQ+TloJjiHd9zORL9L cZ5TWrpre1xtswQ/nhzf4VS9tNWOmnFllL6v+hw4GVIsiCsjVQI28nSfb+bcp0yT12hJ iF5ZN9LaVlNSfHjzOntW750Pc26uPYg72AEOPTTf+qFshsYkne/wuHZwfGHZhktjDIRB PCdIPic39bACYj0+VaRsdmy1leFjSpiFIrfo+3mgeCcVMSJOPCF+beJSdIf0/+rDSbWP 2Xsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c23si1013770edv.521.2020.12.09.07.24.23; Wed, 09 Dec 2020 07:24:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733109AbgLIOtf (ORCPT + 99 others); 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 Content-Transfer-Encoding: 8bit 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 -- 2.29.2