Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3718258pxv; Mon, 26 Jul 2021 10:09:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXBx8GPNriqszmKGvaa54uyNcS+MByvlmYkZx3MirnJml0y85cu1aDol+fKfVzqJ2zUYFU X-Received: by 2002:a17:906:a450:: with SMTP id cb16mr17719202ejb.296.1627319349810; Mon, 26 Jul 2021 10:09:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627319349; cv=none; d=google.com; s=arc-20160816; b=ZgkEjqUNq5JKsLIXNVEnK4e39c33s2VorQIet0AkmR5+9T6MFRzR9ws1hQ4tdTMGhB PN+1i10hb3hR9yTZpX/z297632TcNW/EpLKHpgNM8H6w/Sqo7bWgrIFmdRiKrrP/KdBv i8N5X3mee1hxfF4qUHK7EeXQlhOXfXTwdqHGvnRSEMM0SJb9DigSLkIPQaQO3qnp2SpO dWul7RrATVznBpC8B+4GfB9DAjeEHRPhX2OlxtupAhNnaRQLPZIzenG34BWFahvrsJYT sRvVkI2KGHV+rUKAC2A/Tt1mrwy1FKUW68Y5icntJWpSDfP7/xOjShRSYBOoUl93AL/s tygw== 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=Wi0JIxMcUKseE72F+/DcRjxXkqPjTKN2Bu6AtgXI+To=; b=vjpJqA7YXzwvv+Zf1QO3M4yp9xS44KYzVnRGUKKf0CRBztzz7bvgIsUjDnQoe4nhXw VlLEkiwHY/8eCTzHW7FM+HU8e79htkDAwwCiKWM5jb3BHZ4C9EXbJrx1XS+ErTKxfRY7 XGUsEkzsNkvEF+C7r9Rgx4WqHVQZ1hsGVn3l4ZHpWPMZdCByIWkqX57Yza+nbVijK9rK sPjFkWZLx+x/KwcIC1yRMhQ2fCgvdGDpSi/3bTsoRXuYFj+HqQTLpQlpKACpngBLI7qP GYwafm0P5CPeKv4u8CLPv4qU+u7pZ85MXOGQi6dsvJaMoqYOy1bZl1M4KZU10AhtT1h4 BuEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="bG9IPSe/"; 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 w11si499314ejc.453.2021.07.26.10.08.42; Mon, 26 Jul 2021 10:09:09 -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="bG9IPSe/"; 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 S238436AbhGZPm7 (ORCPT + 99 others); Mon, 26 Jul 2021 11:42:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:38916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237597AbhGZPXv (ORCPT ); Mon, 26 Jul 2021 11:23:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9E7AA60EB2; Mon, 26 Jul 2021 16:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315460; bh=gmEns8PhLF+o1uVXF0uNw72FyU1wHirlb4IqqBmMj3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bG9IPSe/s7YCteTk7lPPxVKKXGuN85snFkllh8SrkZ0p4RdR4YaQG/JpV8JRa5cgg x4EshJdvstRJ0jCSp8aDAsYQXp7cVBxa+iMZUsEfk0Yh3fatAqs+ZxFSyYsjmv5h3J oI1CYP35odPsmfVAMtrA/pWzQsFDOTBL9WLw9yLM= 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.10 104/167] cifs: fix fallocate when trying to allocate a hole. Date: Mon, 26 Jul 2021 17:38:57 +0200 Message-Id: <20210726153842.888529961@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153839.371771838@linuxfoundation.org> References: <20210726153839.371771838@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 442bf422aa01..b0b06eb86edf 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3516,11 +3516,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) { @@ -3643,6 +3638,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