Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1482959lqm; Thu, 2 May 2024 17:10:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWkw94SHmJXMxdMzkMi9ZxADy2y1Gb6w3K11QAjWJCSw+lPZ17QPMBP3vejOjgGI/C0pdJ41sFhnvsOVhZSqQzvUaOAb51NKY+eCLGRNQ== X-Google-Smtp-Source: AGHT+IHeOvTKxMbB9g18oM1gFqeygRKB8t5zAMMisSzVjmaCpfAQ4R3CFFEF9zjSuh/AzLJlooe5 X-Received: by 2002:a50:9e62:0:b0:572:a71e:b8fa with SMTP id z89-20020a509e62000000b00572a71eb8famr604020ede.16.1714695032524; Thu, 02 May 2024 17:10:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714695032; cv=pass; d=google.com; s=arc-20160816; b=A+Ai66FKlSrMGOW45gBk0Dakll+k4f+ye4+ZsoeKbFeAg7VXevPvZZU9CJqIvbQWbc +a7vT3fIrJ7zsWAyO10qFEkn0BYAnIL+S2w/x3Bm6+zQgOSyeH4AzfTkUUQxcvp/pX2r BDl45zQAQIJCYiC+4AfLOw8iZr7LMAe0uiLKOEe7EzRww+Paw8DUDqLCGkL34SV9OUG6 AcKw2II30mWFKWHlXyKm0mi6eH4ylcnHKngS8ti4p4qjM/0rURISxi6KdUvF52gUvazY j35HK1Z52C6PPv68bjJ/A/UtQVoLHMpvGOwC3SZqAVIeQ286bdORLRvRAfF9rYx8jD+W lDIg== 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=yvQ96PVcBTjB1DlDAHvZFWsvHSveciEwekt2iZelkZw=; fh=H4sd10cl9nCCXBukdH5ilEEGSMjort1cdt7xb9dHedo=; b=ZWWTCSftfw+aP4vpJ/kgDhB/Kv5J1QzjrDQ4k/sG/Tqgaq1cZWQzCO9UZb+FVvMmct J2IPhQ/Jc11+KTvaKKZkJnXhjgcSMV8P2LWPjQPkIwYNAYEd0gWMT1aQvwJvOkWEZUGT /LBlj9hkjtEl96Dyn5YuzQMY3yiu+Nl1wW7ubZnQuqQUJkSHIzhfDj0chvfPKh3G8C1U TWcMX2JRP8WRUTHekEaU6HFMvbY7e39vaZyD5725QzUhtPBGGP2RrSoKQHNXYv7pNpZb 95O8ke04oQieAY2a600lcq/AUcoJQbMH08f1qicK927TmnuCz6zjxNYiLR31fAwgYyuw lEGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="k9/Fbnli"; 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-167088-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167088-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d23-20020a056402079700b00572727642fasi955272edy.338.2024.05.02.17.10.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 17:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167088-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="k9/Fbnli"; 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-167088-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167088-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1CF101F23F8B for ; Fri, 3 May 2024 00:10:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D531163D0; Fri, 3 May 2024 00:10:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="k9/Fbnli" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 A1C624C8D for ; Fri, 3 May 2024 00:10:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714695020; cv=none; b=fhKxtMjTXx6tjeL3wx/y6SYRRu0cB97gTD3kWoid5HQgv3+69DUVOTusHqPuJnXl4eIWM79rDvwRxOx7S6zQgM7/yu2l1Dn1s4TcvBKKOCuAocIHUOinmYhoA8TkLxJp2iu2mgeH8MzvorbvuY3kHBQ6puOrBhvgOU8uOzBJXrA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714695020; c=relaxed/simple; bh=396tSPnsu1o8PLgTUwTVh4aL60msCw5+EXNie4fn0Q0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RTSemLBxQWa4y30HnM7wuowsEAhyDMjPx5mfma6+U+q4K4dTOzJwGo5/ifYdRmzNsQuMes85LijD4tPNnklwLooIpDnhN96RUl0NODzYOX+1RR2IOa+xPFoSHtq801TJbQgLtBi+z7dyQdYgKf7qWWYBsAgjvZfHMAEYpZ8qaec= 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=k9/Fbnli; arc=none smtp.client-ip=209.85.214.178 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-pl1-f178.google.com with SMTP id d9443c01a7336-1e3c3aa8938so57489335ad.1 for ; Thu, 02 May 2024 17:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714695019; x=1715299819; 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=yvQ96PVcBTjB1DlDAHvZFWsvHSveciEwekt2iZelkZw=; b=k9/FbnliWqrl/WrS762l/Mz3AtsWA2PIQfbgk31ICqcz9tfs3FpMk2ChIY2eKxPY9k T2/JzPfprBcFtYxcGy25P1V/pNDDMB5Z2EPjuink3ij/KOoQ2vvwH7zc0BOYRFSh+B14 P1nNq9YJL+BECGhnV/wEMM4J+odD0cjAmCRbE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714695019; x=1715299819; 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=yvQ96PVcBTjB1DlDAHvZFWsvHSveciEwekt2iZelkZw=; b=NxVAfYk5lmudaKw9XqI4SbgcLc3/wTPPC0OhQoLwkGk/pWYKUd4dwVpNH9XIjXMxzl yN+QN4ITZWrGQ10KkByvjic1yYHFRmFVCHVCTXMGgLVOLGsYMZDN/FphMsAjejfFqa63 /B4ee/YcQ6D4/B7bNT121st9WKoMy78vT+6Gw2k0rET6frAemwsQY8BXlivRiATTdIJE lgpQ+uRL5TgLNz6U2iM/9UMDuRxtXEQy3bCVeJ5NlCbdsycu1m4xvWa2xjoMMKpKkeYU CnfBiWE+pxh/hE3u+c4YbWcVpA5QYacwwk/chHNfcXME28A9zKE1Gn5Uf25SsM7m+Ma2 /P9Q== X-Forwarded-Encrypted: i=1; AJvYcCW/Ro0SQUQdfaBFquhwSrykKhWvTHChECVpCotZFKKyOAvCWg/7j202cgKh4zWGxXh8+FsD350tlbUfIcV/70qimNdhewI92lo1NUoM X-Gm-Message-State: AOJu0YwgJeUYfBuAqcI5vJ0fTJ08hQlNM1Rfej9PcVHM+Fq14ZnA9IKn CKR+c1N7HVLttOjvXvfWkpKBLbWNHwT1w6gbGSWs2j+LadeZqaS5wpDI+oe0uA== X-Received: by 2002:a17:902:e747:b0:1e3:e380:8724 with SMTP id p7-20020a170902e74700b001e3e3808724mr1684558plf.48.1714695018965; Thu, 02 May 2024 17:10:18 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id a12-20020a170902b58c00b001e4881fbec8sm1942415pls.36.2024.05.02.17.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 17:10:18 -0700 (PDT) Date: Thu, 2 May 2024 17:10:18 -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: <202405021708.267B02842@keescook> 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> <20240502234152.GP2118490@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: <20240502234152.GP2118490@ZenIV> On Fri, May 03, 2024 at 12:41:52AM +0100, Al Viro wrote: > 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. I think that was also fixed for refcount_t. I'll need to go dig out the commit... 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... -- Kees Cook