Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1530751lqm; Thu, 2 May 2024 19:46:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWyXa0wWdf9nTeWAPF/WhDb2fCVvV9MZqgYhTw8+jFycg4qEqBqeAK1kzQVhTZx6ZYq3SYeiUTbKTy9YRan2LPEApD+tq57mlVNx8EFXw== X-Google-Smtp-Source: AGHT+IFTl/2DabaIfr21t/q0tz/pJJgzHLqALnu8pL0ppKG88X6LgGOVCuzR0H4bhy9Beo2T0ehU X-Received: by 2002:a05:6830:1494:b0:6eb:7bc3:12a5 with SMTP id s20-20020a056830149400b006eb7bc312a5mr1654026otq.32.1714704418257; Thu, 02 May 2024 19:46:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714704418; cv=pass; d=google.com; s=arc-20160816; b=OOwRh86FsK4PlxjGrxjUGNqXy4pnkisws4DBauC4z70rT82EDzWzIaH4zxkvdn029K CZAno5OP1Y7t+8gakgQPCDtL0w6vo2UY44dwH+J74p86UGvYD3tbygi4a5DWLgFnKhjo kCRVSFVpXYoLuvpgbPGB+orQvJ1QmqAsRCst/vqIHrS1O4DZCPkLPSToEiyKf3Aqr1Sy DTcU4oAARtdZ47c3e4xABQibySQZHxeNUWJRP64vX6WMK2g6/LQkS3J/eV8x15LuLYwS KeA4Gyc27E9N8TYSPDtjhwKM3UW7UoljdnYOI52UTVjJi92YM51+AfaXR7gCxfm1oxur nDog== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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=+jAuGAUMlirWHwpsbSRnjzxGiwK0lb5RSO05/kE9BCw=; fh=4ju/sbQ98gwaxGjZBNIZUzZfMrxGD5BSlxjcUF57YM4=; b=b0B5x7xrLdXiKGnuNnlP9d+VfvjYf/Y522IekaE4VbhT2Yt7Xses6+pooYRaGKb3Ln dA1KVsUls7fyeO0Pv2/jy+602oprLGXpcSw7gyXsbx85F2y1xzQsHf3DZIRdp+4CZWb/ ncnPzHp3r+fxIQxrodXXDZPVrg661YwnGiLmoCz6JHBPNuZ8sQnKaZ97++uu0wjg2Ltx pQgfuzJnbj7+g25XN6i24ipXczA+HVNTpMvc8K4mV4Rq0Xiw92HbwmLrOCkWVM5CYN0R oDhuWUf8CfEbqs6kp4uYhbhSXsF9QqJjOETSArLde+LXXHpd5I82WYwTVTvN7/5CGT24 Cx1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=BNq4ALpK; arc=pass (i=1 dkim=pass dkdomain=linux.org.uk dmarc=pass fromdomain=zeniv.linux.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-167076-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167076-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j23-20020a635517000000b005f7ff55c41dsi2084047pgb.665.2024.05.02.19.46.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 19:46:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167076-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=BNq4ALpK; arc=pass (i=1 dkim=pass dkdomain=linux.org.uk dmarc=pass fromdomain=zeniv.linux.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-167076-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167076-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 3189DB2166A for ; Thu, 2 May 2024 23:42:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFEF5159211; Thu, 2 May 2024 23:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="BNq4ALpK" Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 4A4BC64CFC; Thu, 2 May 2024 23:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714693322; cv=none; b=u9pPyWYumtSssQEg4j+Pw3qxpK57En0oJPxjdbJWMEm09n23vgaW8KfosIBGUPB3SUTDpldhwcR8YnUbQc+J47BhXbVbhMnr5kRESO9e5eAWLle/8OAWCB9zyVbvGFviOLh3wrK7zgbTCyc8ntmiZ9Cmi6haRc6KFDM4rhLBioA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714693322; c=relaxed/simple; bh=IMzxej8gM+J5XtCh0Iw8AuKDl9QKct+s+p69UDAyyz0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tFF1NWNcZScN4IY0JYXHXfQ1UvijUYHAgLiJjJgPjD4GUprinTfVxhWiHuUdCys2Sc0aBMAICDWoyM7Q3uj1ZcsdRfkTt8v2yK6ju9jyOJO8qG/S/8MFyoFvPsHTgj9xgG9jxe0Pa+nfQWMYkd1NeeEQYB+8KIcb7HCKMafVRQ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=BNq4ALpK; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=+jAuGAUMlirWHwpsbSRnjzxGiwK0lb5RSO05/kE9BCw=; b=BNq4ALpKLbJH/KcTZGVVsf3CKJ 6oohbExTsN0l0871Q/7TlyO/laXpsBkWo09az4DGUWLvE3ZnhSutgPPbRrSdmjVD64ociH3mDN1/r gcuF5m3Wd1/GtmS9WdQNT76M7n0pZW4/4mjMhFRhlNHD7QLOPUWnD3I2+RAnpUlOKzb3y7KyOS98x K09oUyMoAR7KSwTEuyYKEXwf8HhZd5wgO8ntlHUFD+3XXf7A8HhJSuBcTLMaabEHDix2ylHnIL6m+ FlrlcoZL1dAfDyMQU82WNe22tv6MCZ5QyTfCry9vkmmNLUa09aNWUKuoG7qNYKGPHCEEaBGvCjE3I mJG5dmsQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s2g3k-009s3X-2Z; Thu, 02 May 2024 23:41:52 +0000 Date: Fri, 3 May 2024 00:41:52 +0100 From: Al Viro To: Kees Cook Cc: Christian Brauner , 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 , Peter Zijlstra , 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: <20240502234152.GP2118490@ZenIV> References: <20240502222252.work.690-kees@kernel.org> <20240502223341.1835070-5-keescook@chromium.org> <20240502224250.GM2118490@ZenIV> <202405021548.040579B1C@keescook> <20240502231228.GN2118490@ZenIV> <202405021620.C8115568@keescook> 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: <202405021620.C8115568@keescook> Sender: Al Viro On Thu, May 02, 2024 at 04:21:13PM -0700, Kees Cook wrote: > On Fri, May 03, 2024 at 12:12:28AM +0100, Al Viro wrote: > > On Thu, May 02, 2024 at 03:52:21PM -0700, Kees Cook wrote: > > > > > As for semantics, what do you mean? Detecting dec-below-zero means we > > > catch underflow, and detected inc-from-zero means we catch resurrection > > > attempts. In both cases we avoid double-free, but we have already lost > > > to a potential dangling reference to a freed struct file. But just > > > letting f_count go bad seems dangerous. > > > > Detected inc-from-zero can also mean an RCU lookup detecting a descriptor > > in the middle of getting closed. And it's more subtle than that, actually, > > thanks to SLAB_TYPESAFE_BY_RCU for struct file. > > But isn't that already handled by __get_file_rcu()? i.e. shouldn't it be > impossible for a simple get_file() to ever see a 0 f_count under normal > conditions? For get_file() it is impossible. The comment about semantics had been about the sane ways to recover if such crap gets detected. __get_file_rcu() is a separate story - consider the comment in there: * atomic_long_inc_not_zero() above provided a full memory * barrier when we acquired a reference. * * This is paired with the write barrier from assigning to the * __rcu protected file pointer so that if that pointer still * matches the current file, we know we have successfully * acquired a reference to the right file. and IIRC, refcount_t is weaker wrt barriers.