Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1465044lqm; Thu, 2 May 2024 16:21:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUSCkiofmUujYYRInytfSWr02Q2L7FC10ITjAgoLBsN/08cfvJnR3cA6he2HDNIGY7thT2WYJ1EfSsvJX8HUporoeUJlD29GLuthtZTwg== X-Google-Smtp-Source: AGHT+IG/LFrcCLxHEorGHwhn/ZtY07/ZGFfBDJwynww5f2CbdlfziepbzMJdaRS9UlFxQo9emLCK X-Received: by 2002:a05:6870:d10d:b0:222:99cb:2215 with SMTP id e13-20020a056870d10d00b0022299cb2215mr1693873oac.28.1714692086413; Thu, 02 May 2024 16:21:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714692086; cv=pass; d=google.com; s=arc-20160816; b=CmjbdqGSun+iCMPldVBguzDGFOISEC91D/bffKkbZ+SMe8NfWRBHKpX3YeK6AHVjWj i+hzdxT4uuaMdxlNQIL0+meP3Bth4S1a8A2gL6RJLqWoCrGMteudntghtSiFPOo1PBZJ 6MFRyYkrhPQy/FMOj1NmJXWXZ9fW7DouuWuGL58RZIcLxjfnO8D2yIOpGnnEXRyDEQL5 +HWVdNE/oVIDRCVDnqQGQBLzcymadoksZcC35L2OhdYtHIlqST0wF9hvN6jo/J23EsDN tApcdJdcoL4oeg7WTBgkg4voMadHx2nIEbl3jpGOQWnSyyD0QnMP9Qa4FIRidmckWSRR 2QiQ== 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=Yb4bKEByKdlz4UZjReMUHUSYQEXXrh5q/y+c7lUVAhc=; fh=HlSfV+beKQUGi341B6qvfJLn2BUk+0Mw2kXzhyvT5Lg=; b=cQEhDJOebDIe4diSyhp7p32lrTmgMFRnhdj7k4pjv8IzPl48d3cCqHhS8Z3bCuI2y0 dulcBZTIcnUu1efwL0DD31EagXHda/hDdK1jqTjhqoY9Q7zVCFRf340dSo8cnLtJp+xE ohrP1z1KnDL4f9PozWDNzwTvH6dhLF4FwDBCALt3am0u8mpAMSdA4UUVVQm4sT9Zmo6J LWdMHx5wsLtCbiqslJDCL8CLmv/+wKHo4ZVMxjp+mQXXFsS7FES2r6MZb0iTAIOwFJ70 qVDvjRQu7w+GznKNFkV7PNZR2XtEfzTmy9rpNxOTbbP0dQbnmdRdhI8t0j7UZFXhT1Pu fi/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QxFx9dvV; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-167052-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167052-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g11-20020a05620a13cb00b007907b9da2f8si2043733qkl.250.2024.05.02.16.21.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 16:21:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167052-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QxFx9dvV; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-167052-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167052-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 24E1B1C23051 for ; Thu, 2 May 2024 23:21:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52F9A38F91; Thu, 2 May 2024 23:21:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QxFx9dvV" Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CCA01CF8B for ; Thu, 2 May 2024 23:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714692076; cv=none; b=EALwPIZJ675gq/HzzBzAwbgIoJ8QX5STlkHUzyEMFWvgFLdNtOBgEr74kvIVAgiHxegrX+VBdFILyhwccFZtSo7kBD1Hn3PjGSngcVshJ1FZDIYmyem9aLHvZ0pMuDS0ZAhwR3E702/e1p0TUwXdraPOIwhKSRvzZs6CjrKiPkg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714692076; c=relaxed/simple; bh=6YgtMXWABRT2OTs6qwyyj+LFyuPuM8VYCR4YovsE1KQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ma1V12gnuFY0JANwCpgdukc0dQ7QXYlK8g9+lEitdoiua8t7WyqD3Y78hmgh6xM2vld/8ucfsJF8ePeWUm29I5WJADtaFS932cmmNEIVWLDXTxuCxQRzhn2jf3tlVRkRYF4aWmYUezHdfyTByC5Oq1OkvTGbghG1u+PcJXFS8NA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=QxFx9dvV; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6f447976de7so617615b3a.1 for ; Thu, 02 May 2024 16:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714692074; x=1715296874; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Yb4bKEByKdlz4UZjReMUHUSYQEXXrh5q/y+c7lUVAhc=; b=QxFx9dvVfc9RrjAW8fvVc0SxoJ8B1jmxz1Jli7jWPt6QWk10CZkIbdjp83W4W4OgCn psyp5bx5xsIjZfQVpUK7/kgnbeLjvjv7K3ps/FU6NuJ7lKRQl9kOozsHAAlEWo6pbIKa 1zfeaH3HrwwpFW4Yq532/alFlJ9CMYoElKWMQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714692074; x=1715296874; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Yb4bKEByKdlz4UZjReMUHUSYQEXXrh5q/y+c7lUVAhc=; b=OhrZnLG++BhUWCTaoNfH29LmABt8SSCbiD0RLhITiYwJOlGAEaTUTwqCSPP+nvcaao yshbAwHGjF+Sfaa8H01B/NF5p539D+kqUWOHCy05XG+ng2LY7kRwFF2vsqEBPGnCZfrJ eyU05FnHcuIboibw+HQjzEJAuepldrWLPM7B4se7U+S/eCcXnG8IzuyVu2mPNCxwZ1cZ Z8/MuZ3G5ipJHjClr+FdU//EUFYW1BlSt6Evns+OTjdE68B1LKh020qfLo745ee1jNLC uZ5wP9NXTMSDXADMQWlXOGBHHcnTD4zVoZFFqqX3meibiMfJfyTVQG3lRy+LjosCC4+Q g77g== X-Forwarded-Encrypted: i=1; AJvYcCXwG+tuE9F6oZhxFptKh0IEfNYVKi7Sb3IfOmxxFwMcqzTp84rL65PvPTwy76r76zA/0MygXgV4Ogroap0QDV3ls/KUZXRX20toeEg/ X-Gm-Message-State: AOJu0YygLrV4xMqxtRTAwxIFAFEaX5/HRnZsYL6U12twFFz1ux0tL6vz N3Z9kiv8PGi/yAe5pizpwLvP43aFJnwFTzlNrry2FO3hOuLZ/JhDBcopa9orPw== X-Received: by 2002:a05:6a20:7f96:b0:1a9:b2ee:5f72 with SMTP id d22-20020a056a207f9600b001a9b2ee5f72mr1455527pzj.36.1714692074451; Thu, 02 May 2024 16:21:14 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id ls30-20020a056a00741e00b006f4123491d2sm1821750pfb.108.2024.05.02.16.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 16:21:13 -0700 (PDT) Date: Thu, 2 May 2024 16:21:13 -0700 From: Kees Cook To: Al Viro 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: <202405021620.C8115568@keescook> References: <20240502222252.work.690-kees@kernel.org> <20240502223341.1835070-5-keescook@chromium.org> <20240502224250.GM2118490@ZenIV> <202405021548.040579B1C@keescook> <20240502231228.GN2118490@ZenIV> 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: <20240502231228.GN2118490@ZenIV> 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? -- Kees Cook