Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp900965pxb; Tue, 1 Feb 2022 12:46:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxRp6BMOo8zWHxdlJeYZmf7SQw4cRDs4hwS5ha1I3D0/bsKHYMtP1IQy9YtvdBuaNYzGAx X-Received: by 2002:a17:903:22c2:: with SMTP id y2mr27473075plg.132.1643748415479; Tue, 01 Feb 2022 12:46:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643748415; cv=none; d=google.com; s=arc-20160816; b=rwVcuwqmRQNOkwL9cDrIAVdRPTXzjw7fn2M9y92Z4grUZbcSmbkGhaod1f3Api6qCp LxuS5s7fihATTaFGRjLGfgfrH5q1KI/R3MtgPvezsgNykYLsJK4BdecrnNYePAUC+JIE uZrM2sDSszZODRuq91utfJwve+YtKsrLkGuCpp5TS7mCDr5jHjZUyr/0I2vHIQfUIs2R OFT+GGOQ0C8eTAddNNChFlYSUrPpSPXPSVWDkq8iqp7mxMyT43bhKKdOsq1dB3VAVGsc JYG0irzrXexkhuQSOB28M+SFNd2B35JlqfuDWZFmFG3ha+2K+To72yvmar7OQpvjClxU TsOg== 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=gIiem6JaMVcITcekIxXX6i+aTKfO4gvtPdVnVPwDZwc=; b=DYSdRwj93mLRg6YGa599gvQ1D68HGB6VaTjr4EPFEpqLziFznaj9sY9Sum8+HnrIlv t2Zn/gnUywxaW1GkInTE53BDpzxBFCC4RXDH3J6az8V3kVTe7K63uRI4A+hJSjBVhde4 Z/nWvMdHkCgRSk4f1QGEG2mn5lYKQmgl3rpWjxFVSA8DVHZKv30+abRRNGwp/LGy+4ux B4nHSk1UKhO4yWI7M03UkZdO7ONBnM3Mqlhoq/d7ZqOkKqpNHqErOgB1G+Uzt+wANyqs LZxD4ZcdnMu2JDdnlUFQl8MRvO5fcH2caG65qd+oL/IYzMLD2wzP+NR5NXZWet27yEDr K7GA== 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=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j73si17129232pge.859.2022.02.01.12.46.42; Tue, 01 Feb 2022 12:46:55 -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=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355321AbiAaSY5 (ORCPT + 99 others); Mon, 31 Jan 2022 13:24:57 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:55698 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355408AbiAaSYu (ORCPT ); Mon, 31 Jan 2022 13:24:50 -0500 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 F3953B82BE6; Mon, 31 Jan 2022 18:24:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A730DC340E8; Mon, 31 Jan 2022 18:24:47 +0000 (UTC) Subject: [PATCH v2 1/5] NFSD: Fix ia_size underflow From: Chuck Lever To: linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Mon, 31 Jan 2022 13:24:46 -0500 Message-ID: <164365348686.3304.5808030961715602906.stgit@bazille.1015granger.net> In-Reply-To: <164365324981.3304.4571955521912946906.stgit@bazille.1015granger.net> References: <164365324981.3304.4571955521912946906.stgit@bazille.1015granger.net> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org iattr::ia_size is a loff_t, which is a signed 64-bit type. NFSv3 and NFSv4 both define file size as an unsigned 64-bit type. Thus there is a range of valid file size values an NFS client can send that is already larger than Linux can handle. Currently decode_fattr4() dumps a full u64 value into ia_size. If that value happens to be larger than S64_MAX, then ia_size underflows. I'm about to fix up the NFSv3 behavior as well, so let's catch the underflow in the common code path: nfsd_setattr(). Signed-off-by: Chuck Lever --- fs/nfsd/vfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 99c2b9dfbb10..0cccceb105e7 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -435,6 +435,10 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap, .ia_size = iap->ia_size, }; + host_err = -EFBIG; + if (iap->ia_size < 0) + goto out_unlock; + host_err = notify_change(&init_user_ns, dentry, &size_attr, NULL); if (host_err) goto out_unlock;