Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2795838rdh; Wed, 27 Sep 2023 12:59:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+9L+CK82vHtzFpEE+UUxoVBCKj8kkO3dC9k3MJmJ5Dy+TKlqm27HN8agNpNsOzK3wfElS X-Received: by 2002:a05:6830:1089:b0:6b9:8357:6150 with SMTP id y9-20020a056830108900b006b983576150mr3198918oto.35.1695844749153; Wed, 27 Sep 2023 12:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695844749; cv=none; d=google.com; s=arc-20160816; b=izmOZ7wRX60xZ9eV8ZMPs+mo9RCWb44Epafjb7MlML5kcni3bn3HVMioTj5UH+PBvq nnIQ8NCTz7zicF+QDfP3p9CxvOqPMz2xagJSClZzGupwigw5pUipycwdqXMQDq2T/pfu KPe1vkL5ROwupgmZW2YyuC8as6jMvYyT8Je8u39EX2DndVL4khLrj119+a1HCTv2c/nJ nprhQZ0SIWTZ5T9PBiW7TlowY/nR9OqmmJSji7T6YmQDHlKI6AmNJEFOStCAtZZkLeCa mblvrfh8gul244Mr3iZ197H6UhdOyVSucaBFXopZKD5Zbgct6ITjm0r6iYmSjewKJ8ou qHiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:subject:cc:to:from:date :message-id:content-transfer-encoding:mime-version; bh=Lj9cWMVgccUCz7oyAnbAuOMBt56YMDwXn1DvMGAxi2s=; fh=wh0ZroTmfQ+YYcSswGZ0OeF6SaTguxGnuQR0sHidEJQ=; b=zMcIUP1WMk7+TSUP8HaepoZYak3SgP5BWTQZdwrojblr4fVPWfj4/UWAYdrfthfXJ7 pApHJYBTrLSPIouSMiS31HRbjcdivvAU8U+9ZGzxS34LfmaSpk1waUQdg4g0y/2jfK+q iMAlemQJ7OS+hK26hKmwjt0JGXeiWqnZaMhCyIYw1SOGRWv/fXzl24e6NT51SU9W5Yd/ PnEGLfcItU8nMULKFXxcJlk6q8MAXFcJqouloVRZYNLAo/Uzjoy1TcjNrJwlv6CnsnSr j6LEa9WzQ8U/08eq6ol6mrgUqYazcDf4vLjaU/eLqIq+tPvrkMTLlRKFoLepNdJCJWzD 11Xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l69-20020a638848000000b0056c297d1644si15712372pgd.510.2023.09.27.12.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 12:59:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 14FE48060CBD; Wed, 27 Sep 2023 11:43:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229502AbjI0Sn0 (ORCPT + 99 others); Wed, 27 Sep 2023 14:43:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjI0SnZ (ORCPT ); Wed, 27 Sep 2023 14:43:25 -0400 Received: from mail.stoffel.org (mail.stoffel.org [172.104.24.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ED7A8F; Wed, 27 Sep 2023 11:43:23 -0700 (PDT) Received: from quad.stoffel.org (097-095-183-072.res.spectrum.com [97.95.183.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.stoffel.org (Postfix) with ESMTPSA id 266B31E13E; Wed, 27 Sep 2023 14:43:23 -0400 (EDT) Received: by quad.stoffel.org (Postfix, from userid 1000) id 92604A89A7; Wed, 27 Sep 2023 14:43:22 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <25876.30666.549398.562913@quad.stoffel.home> Date: Wed, 27 Sep 2023 14:43:22 -0400 From: "John Stoffel" To: Mateusz Guzik Cc: John Stoffel , brauner@kernel.org, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, torvalds@linux-foundation.org Subject: Re: [PATCH] vfs: shave work on failed file open In-Reply-To: References: <20230925205545.4135472-1-mjguzik@gmail.com> <25875.17995.247620.601505@quad.stoffel.home> X-Mailer: VM 8.2.0b under 27.1 (x86_64-pc-linux-gnu) X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_PASS,T_SPF_HELO_PERMERROR 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 27 Sep 2023 11:43:38 -0700 (PDT) >>>>> "Mateusz" == Mateusz Guzik writes: > On 9/26/23, John Stoffel wrote: >> >>> Signed-off-by: Mateusz Guzik >>> --- >>> fs/file_table.c | 39 +++++++++++++++++++++++++++++++++++++++ >>> fs/namei.c | 2 +- >>> include/linux/file.h | 1 + >>> 3 files changed, 41 insertions(+), 1 deletion(-) >> >>> diff --git a/fs/file_table.c b/fs/file_table.c >>> index ee21b3da9d08..320dc1f9aa0e 100644 >>> --- a/fs/file_table.c >>> +++ b/fs/file_table.c >>> @@ -82,6 +82,16 @@ static inline void file_free(struct file *f) >>> call_rcu(&f->f_rcuhead, file_free_rcu); >>> } >> >>> +static inline void file_free_badopen(struct file *f) >>> +{ >>> + BUG_ON(f->f_mode & (FMODE_BACKING | FMODE_OPENED)); >> >> eww... what a BUG_ON() here? This seems *way* overkill to crash the >> system here, and you don't even check if f exists first as well, since >> I assume the caller checks it or already knows it? >> >> Why not just return an error here and keep going? What happens if you do? >> > The only caller already checked these flags, so I think BUGing out is prudent. So how would the flags change if they had been checked before? And if they are wrong, why not just exit without doing anything? Crashing the system just because you can't free some memory seems like a horrible thing to do. Linus has said multiple times that BUG_ON() isn't the answer. You should just do a WARN_ON() instead. Or WARN_ONCE(), don't just kill the entire system like this. John