From patchwork Mon Jan 22 12:38:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13525414 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68A70C47DAF for ; Mon, 22 Jan 2024 12:39:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0081C6B0092; Mon, 22 Jan 2024 07:39:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED2906B0093; Mon, 22 Jan 2024 07:39:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4C2A6B0095; Mon, 22 Jan 2024 07:39:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B9A926B0092 for ; Mon, 22 Jan 2024 07:39:09 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 74E381A099F for ; Mon, 22 Jan 2024 12:39:09 +0000 (UTC) X-FDA: 81706902018.16.4ECBF30 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id D1DC5C000B for ; Mon, 22 Jan 2024 12:39:07 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aa05kvtt; spf=pass (imf28.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705927147; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8CJ3I/7LDGs8hexTud6zRTfvlS0atGDHH81M3ADEHcQ=; b=NotVkabpmm46vrRwTWuvAzbjQuVHZKYItpgmlFdMmOqVeZIDSCC8xNVtmXH/yjJyDxLmBu fl+aVPUDiNnlRAWd5jkR+HrjK7ILCsiPqSXrJ8FZvtpTsp92ooGQEaVu6YYzy5eD9AvT0L h9f56FKoelbp/fpsVjUawU99TVFRIAY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705927147; a=rsa-sha256; cv=none; b=8j2YQIwpOTq1BVKH/lIOkKZNximFD8IZaURv5tJo1Q4WtJx+1LjvR9p+2hY8lQECKpLBYN UHUrSLTre9MO2LUAidAa/YoOcaeJPceCCoRdBwHNyJO3mJFL+aIoIAy2Z6zrxiOt8eNb6g k5O1OsiHsEhHr2YpUJeZNCMjXjReERI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aa05kvtt; spf=pass (imf28.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705927147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8CJ3I/7LDGs8hexTud6zRTfvlS0atGDHH81M3ADEHcQ=; b=aa05kvtt3HsTXHgovh9UtJ8kY/gRoDeW3PRBhkPLmL/HDWEN3FasUoBg78tnCGeJxNb5LY MU8fyureIawjyzoVd7nLqdTkSOixUvViX4RUS8rMRnGEld03yMoKrKzZfdtdi64KQNYCZM hpeT65/vk8E0huiGp3slLgBlt6GvxKo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-277-IYJ33U9IOce8J_5Yad4F5w-1; Mon, 22 Jan 2024 07:39:03 -0500 X-MC-Unique: IYJ33U9IOce8J_5Yad4F5w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6003885A58B; Mon, 22 Jan 2024 12:39:02 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DE802026D66; Mon, 22 Jan 2024 12:39:00 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dan Carpenter Subject: [PATCH 04/10] netfs, fscache: Prevent Oops in fscache_put_cache() Date: Mon, 22 Jan 2024 12:38:37 +0000 Message-ID: <20240122123845.3822570-5-dhowells@redhat.com> In-Reply-To: <20240122123845.3822570-1-dhowells@redhat.com> References: <20240122123845.3822570-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Rspamd-Queue-Id: D1DC5C000B X-Rspam-User: X-Stat-Signature: 4kr3hzsx8cxxpmygu8ge1bbimcxrrgqp X-Rspamd-Server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Epcoe+4A7FYZUSCTtSF2e6Ha3XhIpkUirHKK6QDCQFfSrr/XfXwBfLY+8kGMvRxpEmhvJy/Q6G+wc0ZztD0tIVRudToGttXhBt/Hqb69e45HLPSUxtyC9DeRUUoS09CpuQEeTo1ZZzneKfNNkVO42OHSCihlLAw/t4IX1TIHF9tWyyBoACrNWlQZ2/y8u+uaM9rq2nJf9nz9gLsZ2LuDkWHF2yao/orgSo5snFWPpvkMpC6JnpH5aUioPlJs7bYZK0Wl7ubwFNIZKsWKbbSnTwofVg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Dan Carpenter This function dereferences "cache" and then checks if it's IS_ERR_OR_NULL(). Check first, then dereference. Fixes: 9549332df4ed ("fscache: Implement cache registration") Signed-off-by: Dan Carpenter Signed-off-by: David Howells Link: https://lore.kernel.org/r/e84bc740-3502-4f16-982a-a40d5676615c@moroto.mountain/ # v2 --- fs/netfs/fscache_cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/netfs/fscache_cache.c b/fs/netfs/fscache_cache.c index d645f8b302a2..9397ed39b0b4 100644 --- a/fs/netfs/fscache_cache.c +++ b/fs/netfs/fscache_cache.c @@ -179,13 +179,14 @@ EXPORT_SYMBOL(fscache_acquire_cache); void fscache_put_cache(struct fscache_cache *cache, enum fscache_cache_trace where) { - unsigned int debug_id = cache->debug_id; + unsigned int debug_id; bool zero; int ref; if (IS_ERR_OR_NULL(cache)) return; + debug_id = cache->debug_id; zero = __refcount_dec_and_test(&cache->ref, &ref); trace_fscache_cache(debug_id, ref - 1, where);