Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4686548iob; Sun, 8 May 2022 22:00:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4JBJmOn4RXhhhBZHzlhAmz8LlaFALpmIbBp+fSOaS2tV2Qzfq5EWaIKFpPjjZdsw1Eavw X-Received: by 2002:a17:902:f708:b0:153:839f:bf2c with SMTP id h8-20020a170902f70800b00153839fbf2cmr14766995plo.113.1652072451161; Sun, 08 May 2022 22:00:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652072451; cv=none; d=google.com; s=arc-20160816; b=BZZhjxLcitofU3tO1r+DDVH48UJFbXZPoWovy/X9BGEv27I/+v9yff+K2yTt3xttnp Ysf1xZbg0Yz1U8ZebhgcFz7PrnmUANxswRF3ZHaHoVE6h0zK1BlByJNYUsf6lTCS+6b6 eDd9Iav6taJ70LGT5NamD878XREPcTF3RCiq4ywgnDhU/TujrZeK4r91WPC3xSF/zjM8 T74jiByhUdXXx+mkaKdVTUZlRUsRr4wyh6w9u09vBp5NeNarDIgMULJ7J20Fgnm4ZAo+ mj6s0D2fPZdLcqURmrnLm2YlAidUcfS3x4JLqLNBf89AX3z8RSZxJls/5ddAhgSXvzfD OlKg== 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=PNHNL3Nqh0XQQg/SgFbjJYa2gLo3aA2x1JqE9uudqUM=; b=C3PbaitmsTfB5053hU2yihcFo6fIog5qXG8mSrIdPhLya04N3jSM/PrNyk/ezwnaSS qcsCc3l+SFI0XAfFOqGMfcyv7JzdzQ+uunkHP2D4Wd+rL0skKDI8YZNFtuq0bUQW+acJ HwMqo2LeGI6c7pZPf9KEJEZeXxBxRxH68fdaw7YnASNAjsbkQ/46vctZpjH+hIWEgCzM L5oVBFnym6cDz/MKFoxenpDxLsGZURykYm5bqm3ODB5FR1PqnPOgkwg4hrN7/46PjNr0 ZkFjFULkS6qg4tyrcIaPSu/5FiHJ1DKwA83w/3qVnk/IZfzzU6rz1az5TOhZ3w0FdA3o bFDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eXY4ksjV; 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 pc4-20020a17090b3b8400b001dc40c6c7besi15423428pjb.53.2022.05.08.22.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 22:00:51 -0700 (PDT) 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=eXY4ksjV; 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 702E4AAB48; Sun, 8 May 2022 21:56:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357409AbiEDR2C (ORCPT + 99 others); Wed, 4 May 2022 13:28:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355756AbiEDRIu (ORCPT ); Wed, 4 May 2022 13:08:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93133515A5; Wed, 4 May 2022 09:54:32 -0700 (PDT) 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 0BBBCB827A5; Wed, 4 May 2022 16:54:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FD6EC385A4; Wed, 4 May 2022 16:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683269; bh=bRQrtA7Sj1ZggibkRz6ZFK9KJkXGdhVaf5iHCb6wSws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eXY4ksjVQkqH97LIz4owDIvDmY777u3yRqnXpOa/t/zCijpG8fiqjKicaj+O5RxST MHvCiwD/yyIkwqdwzmEwKY/UYQ7s0ZLAE5a6+BlIEqlr/Bdtwl7RgfUCB/Uz05hQeB 1Rfw1c5RvodkQjnwqeHdmw1KXxUr9WCawQ7JjHSQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Gruenbacher , Sasha Levin Subject: [PATCH 5.15 119/177] gfs2: Prevent endless loops in gfs2_file_buffered_write Date: Wed, 4 May 2022 18:45:12 +0200 Message-Id: <20220504153103.816946873@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@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.6 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=unavailable 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: Andreas Gruenbacher [ Upstream commit 554c577cee95bdc1d03d9f457e57dc96eb791845 ] Currently, instead of performing a short write, iomap_file_buffered_write will fail when part of its iov iterator cannot be read. In contrast, gfs2_file_buffered_write will loop around if it can read part of the iov iterator, so we can end up in an endless loop. This should be fixed in iomap_file_buffered_write (and also generic_perform_write), but this comes a bit late in the 5.16 development cycle, so work around it in the filesystem by trimming the iov iterator to the known-good size for now. Signed-off-by: Andreas Gruenbacher Signed-off-by: Sasha Levin --- fs/gfs2/file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 247b8d95b5ef..97e2793e22d7 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -1021,6 +1021,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, struct gfs2_sbd *sdp = GFS2_SB(inode); struct gfs2_holder *statfs_gh = NULL; size_t prev_count = 0, window_size = 0; + size_t orig_count = iov_iter_count(from); size_t read = 0; ssize_t ret; @@ -1065,6 +1066,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, if (inode == sdp->sd_rindex) gfs2_glock_dq_uninit(statfs_gh); + from->count = orig_count - read; if (should_fault_in_pages(ret, from, &prev_count, &window_size)) { size_t leftover; @@ -1072,6 +1074,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb, leftover = fault_in_iov_iter_readable(from, window_size); gfs2_holder_disallow_demote(gh); if (leftover != window_size) { + from->count = min(from->count, window_size - leftover); if (!gfs2_holder_queued(gh)) { if (read) goto out_uninit; -- 2.35.1