Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1092606rwb; Thu, 8 Dec 2022 06:42:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf771lCCFLjXYHoNbzXatl2Ub8bxukz9alPxyPTm3+4yyAzLtkZwhTBOjkUIC+yyhewJ5Ag6 X-Received: by 2002:a17:906:e2d4:b0:7c1:532:f420 with SMTP id gr20-20020a170906e2d400b007c10532f420mr10136953ejb.679.1670510576485; Thu, 08 Dec 2022 06:42:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670510576; cv=none; d=google.com; s=arc-20160816; b=omcCy4e8JnCadPryc+kWRCANtrHHwRZkl5cPrvuHJgCOm3ZBA917UYY6tcFwPxt+nP RDQfQumzsdK/z/mNufOwwl9yO7nLaofLbXpYBNHy6vCEHANz0ZKOLoD7ji5fSdaXrXus A36qlPx1Hju7AM5584U1W/8s5a5igy/28u0jGu0i4xi7cgB99EbsFWQsRlelPGshYFli GmHX/grs5bWnxra3T5Vb4u00zCwPeuPp/6+lBN8pYdqj+WPW6jGWN15sm0H5kyKnCNt3 BycNgpUjr20/noWiHT5V/jtaLfluCMPPXW6LoerGPcnSDSoNMem6eETKuW1FvmAEm4F6 G8Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WG+56Z3TVRrxEPIxBZiy2gX7tIWbzFIIdfT6FtjtWvE=; b=iiMW5z5mB2NzYPsxaQP3BHeK/qc7HZPDY+gSHJbEpq4iZNlf8fIaFlVmd6BBqPqE96 7tvoM0nOby3ULAOordB3syhjwVdGbCPDcxUEcLWvHmjbjckQyCOJo/jnaRH5n/IFnlO2 9mDLkB9a62Z6Nb2adzFozc4U8gBlRBVg/qgF6dTC3zlqsWBYB/ojeds7M33G0vzlPHQg zfU3jX7cTDnnEls7UYRT/YOjkr2ENnj9EhQCLXIogL8uKKZTNDbwg8kJOrDDGXybr6Qb G5KJVR4o3w3RE7JDR9Efzc/FfEtHoDJ7+JO8LgFiyqb98OomY9EdQmIO+dLvhd/2dzbm t8zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@szeredi.hu header.s=google header.b=WN2X7Csw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=szeredi.hu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e8-20020a056402088800b0045dc9b4c034si6100243edy.582.2022.12.08.06.42.38; Thu, 08 Dec 2022 06:42:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@szeredi.hu header.s=google header.b=WN2X7Csw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=szeredi.hu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbiLHO1a (ORCPT + 73 others); Thu, 8 Dec 2022 09:27:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbiLHO1F (ORCPT ); Thu, 8 Dec 2022 09:27:05 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC22A9D2DB for ; Thu, 8 Dec 2022 06:26:31 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id bj12so4384985ejb.13 for ; Thu, 08 Dec 2022 06:26:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=WG+56Z3TVRrxEPIxBZiy2gX7tIWbzFIIdfT6FtjtWvE=; b=WN2X7CswpsMtAuwkX7IDc11VxiQWqLC1ZToC4WYuBAB4CDX8WU/zAucKuooMNbPsB5 34Gf9TJHTnOJoYAnlnZJtg2MQ+WWzBEg5v1GW3au1T+iYFjxpQypq7caW7EHvv7u3Vj3 hN1KdAwezCLIF7m6lQy88uPs65cRtdJ/UR+aQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WG+56Z3TVRrxEPIxBZiy2gX7tIWbzFIIdfT6FtjtWvE=; b=J5z7If/KVsjkait9moRJ8CLVeLoXVUwgVTZFIvglDraW+oT9Q62AfHlTboVcmuVPn2 IQhxa7HkWWBIpld4aZ4IuV6ZK7ef4Z0h/XyO42us91BGAfcQXINbcbxwB0Vlo66ho2Aj IAd171y0CEf5M28CMHg9mH2NfWVV596bcmcP4GtsSLGAY3Vw1mxPLfM+GIzmUlY1Unin 878xU3FWmzQeO6EJk3b3x8Bar7RVwzbIa/fu0V8JqBCIyB1v2bUqkWYL7KvRod1E8Avp zY7qPLbcrK6TscDnpxSTkebGjHUiGri4ZT1e0RkqjUqF3AvXIE9Ra8hSHTDF0E/XcoRo 8MLA== X-Gm-Message-State: ANoB5pkxO0d6hlmNyVJywz3PtpgLxWUlUCNahun8kV4efMkDuQFD6+gh 514uNAU4985OP9patNb/7RG+68M87MQCXoXWSzgMWQ== X-Received: by 2002:a17:906:3ad6:b0:7ae:40b7:7fbe with SMTP id z22-20020a1709063ad600b007ae40b77fbemr76760198ejd.371.1670509590418; Thu, 08 Dec 2022 06:26:30 -0800 (PST) MIME-Version: 1.0 References: <20221114160209.1229849-1-tycho@tycho.pizza> In-Reply-To: From: Miklos Szeredi Date: Thu, 8 Dec 2022 15:26:19 +0100 Message-ID: Subject: Re: [PATCH v3] fuse: In fuse_flush only wait if someone wants the return code To: Tycho Andersen Cc: Eric Biederman , linux-kernel@vger.kernel.org, fuse-devel@lists.sourceforge.net, "Serge E . Hallyn" Content-Type: multipart/mixed; boundary="000000000000bb56bc05ef51d27b" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 --000000000000bb56bc05ef51d27b Content-Type: text/plain; charset="UTF-8" On Mon, 28 Nov 2022 at 16:01, Tycho Andersen wrote: > > Hi Milkos, > > On Mon, Nov 14, 2022 at 09:02:09AM -0700, Tycho Andersen wrote: > > v3: use schedule_work() to avoid other sleeps in inode_write_now() and > > fuse_sync_writes(). Fix a UAF of the stack-based inarg. > > Thoughts on this version? Skipping attr invalidation on success is wrong. And there's still too much duplication, IMO. How about the attached (untested) patch? Thanks, Miklos --000000000000bb56bc05ef51d27b Content-Type: text/x-patch; charset="US-ASCII"; name="fuse-flush-async-if-exiting.patch" Content-Disposition: attachment; filename="fuse-flush-async-if-exiting.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lbf676tf0 LS0tCiBmcy9mdXNlL2ZpbGUuYyB8ICAgODkgKysrKysrKysrKysrKysrKysrKysrKysrKysrKysr KysrKysrKysrKy0tLS0tLS0tLS0tLS0tLS0tCiAxIGZpbGUgY2hhbmdlZCwgNjMgaW5zZXJ0aW9u cygrKSwgMjYgZGV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