Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5964138pxb; Mon, 14 Feb 2022 11:50:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1F8Wtw//VDF+cekhvMM1nN6BEWT28VPOPuIrX/uVferxP/v5yhQ3DaDtaDqKUYnzH2Jgf X-Received: by 2002:a17:903:40c6:: with SMTP id t6mr386582pld.117.1644868236288; Mon, 14 Feb 2022 11:50:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644868236; cv=none; d=google.com; s=arc-20160816; b=xL+tzWqq2rr26q2XhqzDP5SbStX46PW47O/nUnpoweizuWZ2DX56KfV3Yu14tockOd 3WeXlUfBvENkxR3A/qSq/HbuwXRXkj/xjZJWRXTXnFeauyUvqFcWubCW551jP0eosvoH 6yNrUoywvr8GGzSjlmF2Bz7YFMncc3wDzjnNIxam5WxcaWobdcgWKiCNtMsi9eD7V+yS LyGr86/o3UlLiPboa6GoiibbpgIIz0IxTojTADWxVQQTii/wIeQxzQuTzPnNXolo2717 3TcubSYhX0DV0fdRMTqJVOkcmBDyVX5BefSAR6Tq/6Pl/jOXrhD4HyrArjPUGU/UOcmk YGIg== 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=BWH2wLRL1Lk9NKILnAcY76WEy9GrvwlbMbWZUEW0VMQ=; b=t61PHdw3Gll1I6eUt1K8H4oJkQKdTBGnF4slz6/jiabXVH4lAh9Eod/wF6RFgw/DKf PpBVAiIsyLVkPFDX9u4+JY0W8SkAZUQNEyHU04HdXCkrKqanimXtF5orrNLuE47G6agH 2SPpnDxnu2eeTwWioxfmP7FX/YSX5o53rgFkIE+2votESG8sGggfqZj3EWEm3ApqEMkT YUYB30yKw9fvHT/XEUrJYK6X/fOwFOCvR3TZRrY5cYiqPFBuNu8FphX4pXAm67UakAZa JEO/6TYzWxGoCYLS1YTvwlnh+i9E4LjGxxYgAi3LZDCv+ADF6jgGt0KWrM5X1AskA6OC xoEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VsH0BpcX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b5si32832312pfm.93.2022.02.14.11.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 11:50:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VsH0BpcX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 62E9B90264; Mon, 14 Feb 2022 11:33:43 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243482AbiBNJhX (ORCPT + 99 others); Mon, 14 Feb 2022 04:37:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244501AbiBNJf6 (ORCPT ); Mon, 14 Feb 2022 04:35:58 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A9DABF78; Mon, 14 Feb 2022 01:33:51 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 8D9BC61023; Mon, 14 Feb 2022 09:33:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66E48C340EF; Mon, 14 Feb 2022 09:33:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831188; bh=uMMeRoT+ybvFtU0MX3yKDdCNfcVrwyog8G8R/v9tMPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VsH0BpcX+xlPLkghRvGcxzn+Z3VAfAxCq1QarlW1jtaObrLprmHzZzYtPPEBVsk8u xu4DZPQjE7jdNSUc5wPc4BLO4xSZTMqrJwyeLkcgicyR1/XTNmm9dTN0qVBMlXZpNV ugpUlR1PnhcIwUtMWNlwkkF33lgN+Yu0pOj6fTwQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chuck Lever Subject: [PATCH 4.19 07/49] NFSD: Clamp WRITE offsets Date: Mon, 14 Feb 2022 10:25:33 +0100 Message-Id: <20220214092448.544263590@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092448.285381753@linuxfoundation.org> References: <20220214092448.285381753@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Chuck Lever commit 6260d9a56ab352b54891ec66ab0eced57d55abc6 upstream. 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. Cc: stable@vger.kernel.org Signed-off-by: Chuck Lever Signed-off-by: Greg Kroah-Hartman --- fs/nfsd/nfs3proc.c | 5 +++++ fs/nfsd/nfs4proc.c | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -200,6 +200,11 @@ nfsd3_proc_write(struct svc_rqst *rqstp) (unsigned long long) argp->offset, argp->stable? " stable" : ""); + resp->status = nfserr_fbig; + if (argp->offset > (u64)OFFSET_MAX || + argp->offset + argp->len > (u64)OFFSET_MAX) + return rpc_success; + fh_copy(&resp->fh, &argp->fh); resp->committed = argp->stable; nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages, --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -997,8 +997,9 @@ nfsd4_write(struct svc_rqst *rqstp, stru unsigned long cnt; int nvecs; - if (write->wr_offset >= OFFSET_MAX) - return nfserr_inval; + if (write->wr_offset > (u64)OFFSET_MAX || + write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX) + return nfserr_fbig; cnt = write->wr_buflen; trace_nfsd_write_start(rqstp, &cstate->current_fh,