Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1857000lqm; Fri, 3 May 2024 08:23:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWjbxIiHMjjZotcid0DqChi96LSwqBawIh+LAF3QoyYW4iguuGUvt1uaJpbnE5EVcaaqk17wB04eHd7dOAN+m75I/WxYO6zBeO1P7ZczQ== X-Google-Smtp-Source: AGHT+IGOJ4aph9jQEAjQd8GVmrY4LtmMaSk/5cCUJCxwsZO/I5zoVtmr5CbeHortnB1W6WpIJumB X-Received: by 2002:a05:6a20:8413:b0:1a9:7afc:591c with SMTP id c19-20020a056a20841300b001a97afc591cmr3624752pzd.10.1714749801989; Fri, 03 May 2024 08:23:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714749801; cv=pass; d=google.com; s=arc-20160816; b=icFgkxXCPP+dWDHCSf+BwxIU7sAiOD/VLhAftFN0+XEFJRlVc0WSEdwGgiVtX6yP8s GDNx1wdjk6dzwTiX5sDhE53mVtyatxY9ME1nQ5tXWYCbKbcY4UoC0tty6jdW4a0W89rP kKdvhEGcfgzTEb5vHHP9XH+Jsr+VhduoqAQHK4Xyjl9vzYoSB75GVAzK4tVhx2Fbe4m6 pDcRBHSSaVh6LgSv3IrXXeOh+TS6ibwsVIIklwivg8fYgOnJFpfDutdPzSLySDEnU87i BxAh59D7KyeQx7QqKGf+oLfUKEawuRsIGxykkhigFBdsqfDznVrXPQVNrapC4myL7V5s hwew== 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=qh5Wc3QqXgam82TMaOdVdy+cfP6ZNoEKs7ddCVe4jPY=; fh=hHFuFSOqUqnGwiV2lSuhk3eQh89/d9Ep9e7/8f5X7Tg=; b=aPqDR00jRwR19/uP6D9dIhR530MWhr/425E4ICsPnOa77onDx2gu4yv592xxgP4ptr OAbTMQVudYq9ygdAvGisp4hDhsIheNVBy9p2Lf+ZxCU81Ier+21Dl+qfyuCW+75R6C0B w0PIDy/yqflVT3/suKFA8JggnOpv0fyVvR1M7Ce28ArP6OSujIWuEShtdCnOcnwgkNjN 5M2HgSSHZl6oGCq8MaLKXYdYeyCjCsQfjCIae1EJjf7Oyo/sYvgxT569ep+a+JLWkfK5 H2g0N4rmjPtU1Lss/6w49O2nSvR837w0+l14dowDm7ad9F1cGn7+ydWIT9DlA3BDgj33 Ye4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=N8I4+Cwi; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-167524-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167524-linux.lists.archive=gmail.com@vger.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 v66-20020a632f45000000b005f808d29f8esi3145926pgv.484.2024.05.03.08.23.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 08:23:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167524-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=@infradead.org header.s=desiato.20200630 header.b=N8I4+Cwi; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-167524-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167524-linux.lists.archive=gmail.com@vger.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 53FC3281FE8 for ; Fri, 3 May 2024 10:36:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43F801514E2; Fri, 3 May 2024 10:36:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="N8I4+Cwi" Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 A05CF14BF85; Fri, 3 May 2024 10:36:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714732598; cv=none; b=cHA1nP9IAgF0+Xn+gP67TBpC+rAAvw014bbKFUKVVPAYz3kaqfixgkofOjJQ/fVonTAE1L7t+OEQ6HPUTx7FBj7QVI9IYgE1/0AM5kqU4RitLaRbxj5biGHEqrSimvok7iwfgu+teuvUKKCUAgqI3m184yVLoODSIGPFHBN4Hlk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714732598; c=relaxed/simple; bh=E1HUFQRNQQzIWGVLLr1YxlSskv3v0oqQToBpRizAc/g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Uf5TR56DawSoIjN0FXYOZTcINarNT1QM6mlebQdV/KLRrSNimQD9Oo1eMLW3cStoPiKMO1pNZCwnfO3rtJ4sx8M//pYemIOYI/Nr9qNgfpmyI1WuigMdsbkrpFuSRkt0slImZd/BMqWItkMWEkIRNcFfiDD4zyftxAPCUacGVD4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=N8I4+Cwi; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=qh5Wc3QqXgam82TMaOdVdy+cfP6ZNoEKs7ddCVe4jPY=; b=N8I4+CwiBUkzZYIyGzOqQsvzoP cCulMNJhaL2ygzPgYmNxiIytFGF+IHAZTJlW+4byTl+H1wU91wfyhXytPSpMyruKM0qH5KSX0/zb3 M0q8Xbygslb8bYQIpKyIjcsZNaQg/QlWYyn52lYXcksuWoDoJPjWtlzs918/ctl5xS4pp+70AejpZ OhT/9b+OOu90NRC9JXP0qfZxYlcy+pcNpDPFbgfrnHw1FTRS23pxj0DUFeYKUk3VnYsJropW0Di81 TbrsNflYBNuzXjCwiY53z3m6L9fTjcAMDy3NRSeShDj/z2uaw7qLx2j5fikTkkfH5hfv1oFxw5CPT fv3XU5Zg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2qH0-00000000W9c-2SYt; Fri, 03 May 2024 10:36:14 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 402B93001FD; Fri, 3 May 2024 12:36:14 +0200 (CEST) Date: Fri, 3 May 2024 12:36:14 +0200 From: Peter Zijlstra To: Christian Brauner 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: <20240503103614.GF30852@noisy.programming.kicks-ass.net> References: <20240502223341.1835070-5-keescook@chromium.org> <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> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240503-inventar-braut-c82e15e56a32@brauner> 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?