Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3696413pxv; Mon, 26 Jul 2021 09:37:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5RX6hoaidlSbxgYp2QD6yqr94KF0IdAIP2zRhr3+tzKIJZWjq9B3tMZxU6ESBuLbKp+P0 X-Received: by 2002:a5e:840f:: with SMTP id h15mr15385561ioj.93.1627317422892; Mon, 26 Jul 2021 09:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627317422; cv=none; d=google.com; s=arc-20160816; b=vlu6xS8qIACQpV4U71G3z5Pk2IFIviEprztzqchKE9j/XO3pn5dSPKxy50VEU4uXwK pRYVzRse7JsbOVowfoqLwmH9qU1HC7CZ8VgyTRnVZoOuzzNpb5uPbMumUNMIQBdqoAmm Yi9HXWIirDcJwC7gD/AiaFDdlEXhoR5ZcexFM5gsy225zMGAGV6/A+tIvergz2WCcMvG 1p8DnQH3/D7p2t6JsHQUb7b4A45lxo+WcNx0nGVnaW0FLMT+7b+Rcwn66k3wnkJeR+9q H1O9RDnwaPlbPAifYPLKV8KJd0FczOVfMh3rLZGBY6dAIOHMkStKZ8hvmgW2TCn7WZNr iE2w== 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=jSLGsAMfX6w8oXAQNXM+ewjMgBJdykW9u68Tqr+B8ls=; b=TMm9vPNv8ZkNPnhIygWTw/SuOf7XD3uxDTg3gzp+KbziIDWzE482BoxMcC10ylq4np mREpegBmm5nqOZFjfqjuroUfeyqA/X4gN/PCFH5bAJv4tPHp7toTZom2X+V/1uGGVnbB LhlcegAJxn4YaQOlXtTrxH5wnO4x2wC56I2r9buXsaeJdWGngn35PHGrdtUbfQoH0DhN WOAsWebmFKRtaQSkK8UvAYoqPDA4rfp7T4V8+t0wxCRECaizlLRdy46tCoH/mwcBgCwJ Bos4tsIpc7ldr6GVURR8neQeo8TBcU9EqND+FhxPljaLcLqKWH8z191PLNqyEwRuEwDk 3UDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WlxT6wkd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si347419ioz.70.2021.07.26.09.36.50; Mon, 26 Jul 2021 09:37:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WlxT6wkd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239531AbhGZPxT (ORCPT + 99 others); Mon, 26 Jul 2021 11:53:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:49042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233604AbhGZPcf (ORCPT ); Mon, 26 Jul 2021 11:32:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 951D860F5A; Mon, 26 Jul 2021 16:13:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315983; bh=Z2Flz7LytWBwNdWFlecWBcQ52VDib5t2STC4uyvgY9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WlxT6wkd5WhUgr2As0cStPM/Mux4R6lNYxNDPGfqexYi2xOOLF9TkvKZfUcvDGVkl tmwJekWncO/cRZeKlcXt89AObFumSb/PtsLjr0w6BsG+zNUmcAjW60uOw31du8gvmO 0VbfqU8OfPJbKlyDA7pxOM+VCaZnOktnwbIQOmOc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ronnie Sahlberg , Steve French , Sasha Levin Subject: [PATCH 5.13 141/223] cifs: fix fallocate when trying to allocate a hole. Date: Mon, 26 Jul 2021 17:38:53 +0200 Message-Id: <20210726153850.850564047@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153846.245305071@linuxfoundation.org> References: <20210726153846.245305071@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ronnie Sahlberg [ Upstream commit 488968a8945c119859d91bb6a8dc13bf50002f15 ] Remove the conditional checking for out_data_len and skipping the fallocate if it is 0. This is wrong will actually change any legitimate the fallocate where the entire region is unallocated into a no-op. Additionally, before allocating the range, if FALLOC_FL_KEEP_SIZE is set then we need to clamp the length of the fallocate region as to not extend the size of the file. Fixes: 966a3cb7c7db ("cifs: improve fallocate emulation") Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/smb2ops.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index cc253bbff696..64cad843ce72 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3663,11 +3663,6 @@ static int smb3_simple_fallocate_range(unsigned int xid, (char **)&out_data, &out_data_len); if (rc) goto out; - /* - * It is already all allocated - */ - if (out_data_len == 0) - goto out; buf = kzalloc(1024 * 1024, GFP_KERNEL); if (buf == NULL) { @@ -3790,6 +3785,24 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, goto out; } + if (keep_size == true) { + /* + * We can not preallocate pages beyond the end of the file + * in SMB2 + */ + if (off >= i_size_read(inode)) { + rc = 0; + goto out; + } + /* + * For fallocates that are partially beyond the end of file, + * clamp len so we only fallocate up to the end of file. + */ + if (off + len > i_size_read(inode)) { + len = i_size_read(inode) - off; + } + } + if ((keep_size == true) || (i_size_read(inode) >= off + len)) { /* * At this point, we are trying to fallocate an internal -- 2.30.2