Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1447249lqm; Thu, 2 May 2024 15:34:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWm7hTRZYaYdlt9XXwsi7JsY5gCYn7NO9Fqc5vD240dhDnOU/RbJhojsp6JavV6kNIiceVXLueCFN5Wsq+zHbacxauSaAhMW4Jwh1JKGg== X-Google-Smtp-Source: AGHT+IFoA93GkozaInvjjqtZ8foSVK656a8b5F11Be6Bs319tPgZi8zmx/l0BAPE3p3SLKD/DjKl X-Received: by 2002:ad4:551a:0:b0:6a0:f2e0:5070 with SMTP id pz26-20020ad4551a000000b006a0f2e05070mr7244328qvb.21.1714689251070; Thu, 02 May 2024 15:34:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714689251; cv=pass; d=google.com; s=arc-20160816; b=CnGx01GI5mJCB1gg3Kg+oWX8gTv3lTFMvOAuGRUMbBbwkvxoN038gRHULreYWTEHwQ o/i9/k/rhX95KkeGvx/B5pFqvVXegfj4pdG3L8rY1E7RFfhZPnkAt3pQSZwcrmBAAMPr 3yBZ25yNeBSo0Nm+4P42AzmE3dXhQO7OoZdJt1llPvrLB6stru0Di11RR3ALfZTq4aLk lcBoJw+r3ml/Qk855XKxujSmpRQ22y6T5Rbp/D0S7lrIwn1aot4x1FKkJSak0hlRy9yD FFQOc96SZQMJz3XtDqhUO1YOhkekhD9mIuGAXTB6rxdkpnwqrEjAWYrtY6kE+oGCyAE6 aXLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Alkyi5JqXUdcGMCJmPn2xNXTUHn7MjYy9EVPcBLGUQQ=; fh=k5rRZn2+69gAAkd2va+UXvf99EgUg/EeH9ptew0aY9I=; b=ZPdYiw5/Tc/hyWUAWhzqNkg94TaCup0wQMYxmOPcRx0DW4O/YWUuIwx7RAGh5NcEFS 4/EHh9VD5MvjeoQGizvFkRkSv/ND95kYrKj1meJNzfX4MKZ7qPT95Eh9r75a1GUW7kR6 X55viagSzO7QHkZlH99oEIPntjmiDsQEJdzbirJQvy6P209s7iU0swaMaaefDH+6ZtJs CZBrMr4urYHsIMvB6TYUx0aiSODQHA32Fb4DWLY2umaJDrubiVBcqG0p0z3GA8Mdvqw5 r7jVp79FJpGmq7JJrMvaptVoap1umzfLED6yyPStexWms9fiPaMfDg7si9/ZezPuIrpZ IjSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KV0UXu5f; 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-167002-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167002-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kc25-20020a056214411900b006a0ae4f0cd2si194570qvb.425.2024.05.02.15.34.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 15:34:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167002-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KV0UXu5f; 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-167002-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167002-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 B99DB1C20C10 for ; Thu, 2 May 2024 22:34:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 209C61CF8B; Thu, 2 May 2024 22:33:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KV0UXu5f" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 4B42D8C1A for ; Thu, 2 May 2024 22:33:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714689227; cv=none; b=fRewIzLqvS6XUahl/wvHaGtJsl6WFEB49OD7gPvAaUeiXuFYAoTsPwRl20C868DqwI9uGo+IogQx0fjX7IEHoo0OXFmgTrQTjFnHve36On95/GXBoiszvA5rU5Mx+bBSwR1RdImM+71JpBJjjakVm32Bh021Net/iQkPwsod3w8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714689227; c=relaxed/simple; bh=zh3jTYlv3gAfsJ0fJDEOOWbgXfu84QDhZ5jAngTPr/A=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=G8jAxV3fncV35GqCAdtOvK/3f7IvCT+G+fMqsExmkr8bjoUwhDsiZAReohEsSM61DQ7o+dkbOm1McfqkdQWimqjePdittqJjrLmBk/avgyBIMxwU/snjMqDFlaKcxS6arO2EciHOjqPlrsGAOdyMoIhuoCefBAXMB2j75U5qg04= 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=KV0UXu5f; arc=none smtp.client-ip=209.85.214.173 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-f173.google.com with SMTP id d9443c01a7336-1ecd9a81966so9591845ad.0 for ; Thu, 02 May 2024 15:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714689223; x=1715294023; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Alkyi5JqXUdcGMCJmPn2xNXTUHn7MjYy9EVPcBLGUQQ=; b=KV0UXu5fQphPwu/En8bFdZb2papNHd9PJxLZ2WTsEqQNz8tuinfCD2icHLLIK4jv3X epozpPCTWjKYEgy7RvzWsKC8cKABBzmDCIF3jWCtxn/BwsdRAln4s6YwOAPx3lvmE81A zY0yGcqQ8nkuoD1xGakPTTyykaawUVOwTUwcA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714689223; x=1715294023; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Alkyi5JqXUdcGMCJmPn2xNXTUHn7MjYy9EVPcBLGUQQ=; b=dSKmy44hVroopwdwKOSz3eCpXd878iZzTpP8RiVV2fbM4dPSv9DqUcsEJxYSh337Ms hNcWbme2mnf1DL1BvTC7z9w1Ak3jNy/5o5rCBMHkOn3LMg4Q+VHSu8Pp2hrp06dnLa5r Ll/VYF3uL+d867F+R91jzhhIQMmTLlyUk09N/b4XAAPS25lAxNKIi7nxyIke/XvkRtBr 6McNRpe67nw+bhoRwxobYjoJLfLTKqagEoseYtRQ58XTqL3kBd66JAUr461CfoArPSN/ aC6QsLIul/Wbrb7h0ZnJia26f2yBo7A1+JKBiavRw0HoQ12IX8aNBF7XLVmmyiuMkW8j T6DA== X-Forwarded-Encrypted: i=1; AJvYcCXc5LxN94QD/s9h2eDl0lhjJ/HmBOHgLzpNnUvaBYv9eYsRT6znRdCbScu7QF9thQG6AZaJ6r6T7tXT+eGyt5wvfiQr2gzxHfijntpe X-Gm-Message-State: AOJu0Yyl41UmduhjwSAfox2DcNto6HOpmZ90ZW5W90OB0RbAOnfGx6yh XJSggBS+GOjIesF3YcUDXfj1cD35687fsJpW2LV48rXaRC3eJFM0Gb35aKQosA== X-Received: by 2002:a17:902:ce81:b0:1e2:7734:63dd with SMTP id f1-20020a170902ce8100b001e2773463ddmr5911220plg.30.1714689223609; Thu, 02 May 2024 15:33:43 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id e15-20020a17090301cf00b001ec852124f6sm1859006plh.309.2024.05.02.15.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 15:33:42 -0700 (PDT) From: Kees Cook To: Christian Brauner , Will Deacon Cc: Kees Cook , Al Viro , Jan Kara , 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 , Peter Zijlstra , Boqun Feng , Mark Rutland , Kent Overstreet , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 0/5] fs: Do not allow get_file() to resurrect 0 f_count Date: Thu, 2 May 2024 15:33:35 -0700 Message-Id: <20240502222252.work.690-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1562; i=keescook@chromium.org; h=from:subject:message-id; bh=zh3jTYlv3gAfsJ0fJDEOOWbgXfu84QDhZ5jAngTPr/A=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmNBTDFUoY6TVoqmQxs375eqvdFBj89/ctuDLOW 2+X99yJ49+JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZjQUwwAKCRCJcvTf3G3A JspPEACtGBTA/04xGkfNe0POOY6UGlh9ESMNyH/8oZZ8d3UQPt4M6jepl1PWlD4m3cEnHJK7W59 Ew1O/o3JMO6xpM/DaYhVWnWU6vmyOuXC2BLL3sC0H78DoDCS1YeGvgwcsLvoJQkPR6yocxZc1Lp ArPQeS2n1GN6Natd2CKQpRU1hHaVx8V4k47jJ1C1ooXgDt7NaA3v3Mxp2k1nkVABc40Xt0iPZHe N135yJYCUnJcpYLB0ibjarI10wI4Q38s3kkHaSPBUFFlyZzwaqs8cVJtVafb+WFIadgKLSgplR6 Gvo818ypPYTYB7jNIlptvHB2MpN4nJBL6DYjM9W9EA22HbIDDGJexmcFxNXqlQl/qXZpFt7XmnP Q6IX+BvQ65e6Zl3n+AYDDb+8lD/3uddFxKLY+yN8uImNTJaomfLEsLEdpWNQISX4Sd0iZoqRgNU wW8OcE471z7VJafbM8my64tY9J+xrj7sh3jZrbv695WaOXZVOZhvKl4yHNKdmuB7SwoTxzGJp8c 6H/kFSBF+jTC0H5n89DfR0Uuy/y1HoONrXrvE252vDox1DwVh8Gfz62Vr1+HtbNlBpcN9K4w/k7 /tznwjyRyIqPUxNhJJzdX9hpAs9d/CHvDyY8049XOPocPYOnqRtriVf3abZjlh68t5HB+axTGF/ GHusxWn D0shXk1Q== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Hi, Failure with f_count reference counting are better contained by an actual reference counting type, like refcount_t. The first step is for get_file() to use inc_not_zero to avoid resurrection. I also found a couple open-coded modifications of f_count that should be using get_file(). Since long ago, f_count was switched to atomic_long_t, so to get proper reference count checking, I've added a refcount_long_t API, and then converted f_count to refcount_long_t. Now if there are underflows (or somehow an overflow), we'll see them reported. -Kees Kees Cook (5): fs: Do not allow get_file() to resurrect 0 f_count drm/vmwgfx: Do not directly manipulate file->f_count drm/i915: Do not directly manipulate file->f_count refcount: Introduce refcount_long_t and APIs fs: Convert struct file::f_count to refcount_long_t MAINTAINERS | 2 +- Makefile | 11 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 5 +- drivers/gpu/drm/vmwgfx/ttm_object.c | 2 +- fs/file.c | 4 +- fs/file_table.c | 6 +- include/linux/fs.h | 7 +- include/linux/refcount-impl.h | 344 ++++++++++++++++++++++++++ include/linux/refcount.h | 341 +------------------------ include/linux/refcount_types.h | 12 + lib/refcount.c | 17 +- 11 files changed, 398 insertions(+), 353 deletions(-) create mode 100644 include/linux/refcount-impl.h -- 2.34.1