From patchwork Mon Jan 22 22:32:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13526326 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 CB32DC46CD2 for ; Mon, 22 Jan 2024 22:32:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E12DD6B0093; Mon, 22 Jan 2024 17:32:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D76176B0095; Mon, 22 Jan 2024 17:32:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0AF78D0003; Mon, 22 Jan 2024 17:32:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 88FFD6B0095 for ; Mon, 22 Jan 2024 17:32:49 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 585CB16035E for ; Mon, 22 Jan 2024 22:32:49 +0000 (UTC) X-FDA: 81708398058.04.F23C18A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 977F21C0013 for ; Mon, 22 Jan 2024 22:32:47 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eL6cwtUN; spf=pass (imf21.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=1705962767; 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=A0GrIJ/2zxfmqQJ7ZHwMnghsm2JkL0HRrRsEEQXO9mdRkDLu5Q0xv12Vl7p3GTY5Pt2a4l 7XA7xuv0ptBCepVMIHMxxFiRYfxIpfEK1OuZp6WHILlMwn67wT/nOFb9DUH7WDeJokaRxS P0TJTMGHPAu1YYlFoWo2X7nMWH9AVuU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705962767; a=rsa-sha256; cv=none; b=sv8FYoP711j/U3V4d8jGqKsQuo/IgBuf34YUPBqlMDAewi1AWRsPvtQTEj5WNbXTpqU753 01615jTZXU5h3RWxRQZDFxpEZnp8WPjH9SlD3Cw/V+t1kY5Rt1PpcsAXCRjegpqZ1SAkSD HTnKAWA6HXM5p2KJ/ifhX4oir9aR4vg= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eL6cwtUN; spf=pass (imf21.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=1705962766; 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=eL6cwtUNVTeCOPwNu+dqKA+2qnSaaJXO1ku7lFHi1nvewDeDeBtICJDrWeeeWVxSmPekXS KHv+HB2WUwkfGYeki9DRCDivQlrYgG73uzZewXbv7StqklImLcb7guH0NTXQC2/1JJRqbJ zRVYIpQiJGgO/r1U8a2lu10cxgUzjEg= 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-635-kqQQMgafNgqLwRACAr_1zQ-1; Mon, 22 Jan 2024 17:32:45 -0500 X-MC-Unique: kqQQMgafNgqLwRACAr_1zQ-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 D92CC106CFE2; Mon, 22 Jan 2024 22:32:44 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 040A32026D66; Mon, 22 Jan 2024 22:32:42 +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 v2 04/10] netfs, fscache: Prevent Oops in fscache_put_cache() Date: Mon, 22 Jan 2024 22:32:17 +0000 Message-ID: <20240122223230.4000595-5-dhowells@redhat.com> In-Reply-To: <20240122223230.4000595-1-dhowells@redhat.com> References: <20240122223230.4000595-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Stat-Signature: fdf6tsqwn8orp76tt17ywnj5j6d1menp X-Rspamd-Server: rspam10 X-Rspamd-Queue-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j9EMzuqByPkPYAuX0h24moxjT8A+0NgualAib3yaDJL3Y7e1ENLQforEyL9iVvB7K6TeYdD8s9SWazzx1T2y+8cLO8ID/PtxHR9Z+RbOevYaUO5wxgyk9Kq7yLaOGREL6qRbKghbTVu2ldh0DcfrAOWLWA4cUvxosDHz4yE/Qst3GGEo8kJ30OxCB2iCRfzcLGf9l/Yexq0DnBESJFoSYKitw9ObDgbdtICMzTjDEVXpJMLD1hh1UCCBh3np5ypf8aBXvYRx1MLTuSdo9Y0gHCk4jIpLxdSVAwmSHNMmyDX7T9w2XU+9X/jLbbQ== 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);