Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1713619lqm; Fri, 3 May 2024 04:36:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzLnVBZTw70iaG0BnvFjnZDDKYiGEMcexlIfUTMjilklQehQZ5m2n1R30Vlz1Ll5Qwpmwv/iV1FWbTBKlxQfTVcFbwgzMyxjRp7vQLgw== X-Google-Smtp-Source: AGHT+IErYsmwnPQXEpjK2O1FoFZYhNcPC3ceV1OnwTqe9+QdeZGZwbjdypXxbQLUJUu/N9fxjsoI X-Received: by 2002:a17:90b:4c85:b0:2b2:7c42:bcd7 with SMTP id my5-20020a17090b4c8500b002b27c42bcd7mr2650346pjb.21.1714736187811; Fri, 03 May 2024 04:36:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714736187; cv=pass; d=google.com; s=arc-20160816; b=XLKan6KMJVf+3UbOKQRYCFjKWxJWW4Ku5jQIZ9+M1Y8fYeYNTyi4LK67JMyy+ax9PX uq0UXgA+uRzdNXs6WPMR3Dj6klJWWDMm6xJ3ygeuvQdGM2iK7Y0ykXcos8RXeLwvdFlP lf0AdmoqgtjXcNRhia6n+NpT4cpKQ6NVhwGxa3leGN4IJgSYciDO74u9Rm/BQEdQRwMe FSQSqFt0U2tU4q8hw67tvNfp8JIgWDmCU9m+MPvZ/AYmw9TiWv9ldYw4w9ueVg2Optid uQ810kDzVm82rPccIRiUGbNRlroV0oZ0BTOSbAUbszebj44UQM/ZNgIS9ldKgRUT9Nvn qq9A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=zkT+ZuqbJ4RQsZa4cqmP36uH+e9cHTnIujwCFF+Q8Ww=; fh=sjPFobnVFUyJe5D+3cZKA8L3wJulSXOW1PoYLQgt2+o=; b=jTbkuwQUmDM2uzF7X7dWYc+Od1ByXJJog+0EgeEa5gPTWOSJI5Ht1CrR5PBGMVZjiX BuDU3yVeYu9J1qjBtgJTQBURbZbsqpLXi38VAP7ovHejdmOUdsU+OXhLxUsaYo51TKsh YIdxUD3EZ9WquejXDp38VOrIuXsMwvw5qtj28y6C/5bnerJp0Mi8ZwIVdMqhWVPfw+UZ BLj/ZOrHZ43Hs/Mi+eXJcbvsH9z9tdgYIhkyUCJrCxBuG6EODwDF7jfXLunJxC7y3JJ6 sFj9gKfM9ePxJGGhLc8OEqQ/eN6IoARLw+QFob3G/RU7yr+XWKHAVtYPPlazq5k86ium z3Gw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kU+Pbgfm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-167592-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167592-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id mp3-20020a17090b190300b002b157e900b8si2811664pjb.116.2024.05.03.04.36.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 04:36:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167592-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kU+Pbgfm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-167592-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167592-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 75307284197 for ; Fri, 3 May 2024 11:36:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69FE61534E2; Fri, 3 May 2024 11:36:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kU+Pbgfm" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 842A0152180; Fri, 3 May 2024 11:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714736165; cv=none; b=JCr6zMqcgsmRZ0pz5j+67A9OZHeqr3ibwh49H1MALaLLQ1YcSZbe84JwGyukg/3nbFmahd7lauzOiKId0Qs1TXedY1iuuSf/hU+AIyWHO+P1DkxL+mttWhPLE1u0wYuW8kTGAr4A+g+YF+xfvsZkz+3FMSIygG5CF1SuF9moYzo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714736165; c=relaxed/simple; bh=fIbetBuQVrEG023U7eI1zy1F+Dx8KclRAJyueT8XV4Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Pcs9VHaEGz8HRsx3M2aMzxXWKtIzWXPp5RT5cSotSajMnZp2kmU1YJcFjjSXd0W/9a22F+GaTZds8fMtFHGtVRks8Una2Z3VXIO2RuiYyKLieHsBCKOgx6mwtOqbqIu8FNQnbMXlThMcLDVqelOoKXG4O7cd4GD20JRHxr9AR1w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kU+Pbgfm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35FEDC116B1; Fri, 3 May 2024 11:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714736165; bh=fIbetBuQVrEG023U7eI1zy1F+Dx8KclRAJyueT8XV4Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kU+PbgfmV2WYTvcKoIKD2SagvRYfVtWIILVja2exLH0MFtfHic0+Py5SLz8ioBh2c bqpbYbxJ/W9l6syTIapYfSN8oXLB4jn8f3Me0mm0uAJK/HVh9Fym6kP9MVBwSMsr3k Jxor+f8RX7pVwuuRJivzQlZh7ay51U+v39/npfLfZ7SyAMSRMB4SIfamdKqeQwinVk K9VNzZ0cPydBqTF+/eTYn5JPlrfdcNvCY5ixi4VD0+WIvYHt43TEYrbf91dw/oLydB tffGxIoNupZL31C61JfQelalR2aYh/QVLvdIroxHiS3/lJQpV1lJ/uyXJPQRKOstnd l8jmPUnOkSLrw== Date: Fri, 3 May 2024 13:35:54 +0200 From: Christian Brauner To: Peter Zijlstra Cc: Kees Cook , Al Viro , Jan Kara , linux-fsdevel@vger.kernel.org, Zack Rusin , Broadcom internal kernel review list , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Andi Shyti , Lucas De Marchi , Matt Atwood , Matthew Auld , Nirmoy Das , Jonathan Cavitt , Will Deacon , Boqun Feng , Mark Rutland , Kent Overstreet , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 5/5] fs: Convert struct file::f_count to refcount_long_t Message-ID: <20240503-kramen-punkten-848aa0cfd3d0@brauner> References: <20240502224250.GM2118490@ZenIV> <202405021548.040579B1C@keescook> <20240502231228.GN2118490@ZenIV> <202405021620.C8115568@keescook> <20240502234152.GP2118490@ZenIV> <202405021708.267B02842@keescook> <20240503001445.GR2118490@ZenIV> <202405021736.574A688@keescook> <20240503-inventar-braut-c82e15e56a32@brauner> <20240503103614.GF30852@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240503103614.GF30852@noisy.programming.kicks-ass.net> On Fri, May 03, 2024 at 12:36:14PM +0200, Peter Zijlstra wrote: > On Fri, May 03, 2024 at 11:37:25AM +0200, Christian Brauner wrote: > > On Thu, May 02, 2024 at 05:41:23PM -0700, Kees Cook wrote: > > > On Fri, May 03, 2024 at 01:14:45AM +0100, Al Viro wrote: > > > > On Thu, May 02, 2024 at 05:10:18PM -0700, Kees Cook wrote: > > > > > > > > > But anyway, there needs to be a general "oops I hit 0"-aware form of > > > > > get_file(), and it seems like it should just be get_file() itself... > > > > > > > > ... which brings back the question of what's the sane damage mitigation > > > > for that. Adding arseloads of never-exercised failure exits is generally > > > > a bad idea - it's asking for bitrot and making the thing harder to review > > > > in future. > > > > > > Linus seems to prefer best-effort error recovery to sprinkling BUG()s > > > around. But if that's really the solution, then how about get_file() > > > switching to to use inc_not_zero and BUG on 0? > > > > Making get_file() return an error is not an option. For all current > > callers that's pointless churn for a condition that's not supposed to > > happen at all. > > > > Additionally, iirc *_inc_not_zero() variants are implemented with > > try_cmpxchg() which scales poorly under contention for a condition > > that's not supposed to happen. > > unsigned long old = atomic_long_fetch_inc_relaxed(&f->f_count); > WARN_ON(!old); > > Or somesuch might be an option? Yeah, I'd be fine with that. WARN_ON() (or WARN_ON_ONCE() even?) and then people can do their panic_on_warn stuff to get the BUG_ON() behavior if they want to.