Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp901016pxb; Tue, 1 Feb 2022 12:46:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8zao2ACfu8H1X2FBuuxaCiFI8wbTRRez4SG69XtgBj+pI36Vf0LAvV7Q+VotmXKYey2AW X-Received: by 2002:a17:902:7c84:: with SMTP id y4mr13583275pll.149.1643748419371; Tue, 01 Feb 2022 12:46:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643748419; cv=none; d=google.com; s=arc-20160816; b=KnjFuGyP4e3DNU5nz54IWTcPkRwwVlEBhxoL2ZzO3Rd+6Wc+R3Z1dKYSr0BID6WPW8 6IlW9pUx7sgB9NgM+cQcWqPpfKOUYQpJNDz/z4qxO73u+gbdvOaJyjETD+hfMRhMmyRn w0HV04Uq4RJizuqKt94jknNUWbjn6a2jX62M2L+JjLTHjiEDedljiwDfEkfkZ7yMO/r9 Ti6xrlAcE1V8TXIIWABEvFy5CTDr+t4uVDMZjKZ2PrZh2W/5VqRs0s/DIU47TzO0nkr7 3eskDT3tpeQHpUvz8EMDjMJkPcDq2xCk1dDGwsZQXeI+bweNzh9EAm3ilkwahhf1DBlL oUGg== 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=BpckiP8D/TvXsNj1zyoL3QM2wBxk9YROlX31raRU+cA=; b=oFjkF9A/3r1UL4BI+hFRVvT+3ymK/CsKT6AcYCIjw18jgpZuUSDRsK4EoRpCl7Pp0K +ziBzsqdypUTj0UMPqg7mTLA+r1XqhB4ApNeWpiXT7ASj5BnFLc/T4mBkcWB74gg5y+r Dk/4okV8P64MPPMKyUqnLcU3/P4aYipKA86HNRJNfELix77mFULKaZCjNqpjwsbVPdSB 2EBatj7yLLGXxeGAsU04NrEjruyaK3ubRwV5H/Nur/c8wE+4oqwDnz+6aQ+nH4hCd2S1 F+5W/8iJy9OrgGDQ8TTbD92zYR3yq4nu/ufx5fHaEhRIbe/T7puNEuLk7+cd9erFQ/BH 99YA== 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 b4si16900266plz.351.2022.02.01.12.46.46; Tue, 01 Feb 2022 12:46:59 -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 S1355368AbiAaSZR (ORCPT + 99 others); Mon, 31 Jan 2022 13:25:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356211AbiAaSZC (ORCPT ); Mon, 31 Jan 2022 13:25:02 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CF79C061741; Mon, 31 Jan 2022 10:25:02 -0800 (PST) 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 5AE0DB82BEA; Mon, 31 Jan 2022 18:25:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A3A2C340E8; Mon, 31 Jan 2022 18:24:59 +0000 (UTC) Subject: [PATCH v2 3/5] NFSD: Clamp WRITE offsets From: Chuck Lever To: linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Mon, 31 Jan 2022 13:24:59 -0500 Message-ID: <164365349911.3304.17078054234185583698.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 Ensure that a client cannot specify a WRITE range that falls in a byte range outside what the kernel's internal types (such as loff_t, which is signed) can represent. The kiocb iterators, invoked in nfsd_vfs_write(), should properly limit write operations to within the underlying file system's s_maxbytes. Signed-off-by: Chuck Lever --- fs/nfsd/nfs3proc.c | 6 ++++++ fs/nfsd/nfs4proc.c | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c index 02edc7074d06..4e939ebba5d5 100644 --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -203,6 +203,11 @@ nfsd3_proc_write(struct svc_rqst *rqstp) (unsigned long long) argp->offset, argp->stable? " stable" : ""); + resp->status = nfserr_fbig; + if (argp->offset >= OFFSET_MAX || + argp->offset + argp->len >= OFFSET_MAX) + goto out; + fh_copy(&resp->fh, &argp->fh); resp->committed = argp->stable; nvecs = svc_fill_write_vector(rqstp, &argp->payload); @@ -211,6 +216,7 @@ nfsd3_proc_write(struct svc_rqst *rqstp) rqstp->rq_vec, nvecs, &cnt, resp->committed, resp->verf); resp->count = cnt; +out: return rpc_success; } diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index ed1ee25647be..807f41380e77 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1018,8 +1018,9 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, unsigned long cnt; int nvecs; - if (write->wr_offset >= OFFSET_MAX) - return nfserr_inval; + if (write->wr_offset >= OFFSET_MAX || + write->wr_offset + write->wr_buflen >= OFFSET_MAX) + return nfserr_fbig; cnt = write->wr_buflen; trace_nfsd_write_start(rqstp, &cstate->current_fh,