Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp130078rdb; Mon, 22 Jan 2024 14:34:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOrynzpiuCapICpfvrvUlb7uTH5Q1rJRBI/geymT6hmEo7K+i1Ja5Ysvip7jpGHWad8ogm X-Received: by 2002:a05:6808:2216:b0:3bd:415c:6422 with SMTP id bd22-20020a056808221600b003bd415c6422mr4373701oib.44.1705962873174; Mon, 22 Jan 2024 14:34:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705962873; cv=pass; d=google.com; s=arc-20160816; b=jPHjf+c+DAdDOZwCuczL1DxaaV9aiU3mQTgBDjCakOZdOa76u9wmuPJBVoN3aQFPv4 ZdfWSKBaba8kZIA460SgGE8QlJB6U0Dn8fnasgylfUO4P9sJ6iJAN6ZBfS3Sqnyx8sgn hgqZ+OIugUG4ah3/Gq+DXsRXklIjJ1e3l2Z+4cXc/0rihhEFPnI5h7BsZP6+d2gdlxVt JIQeJCf6Kdu73WjMVKJe3Kxu9+EL+GGn42V5w2ihyLMI5UI0Ro1zA5DlFkAiPxRuK0TZ iXImQ7A4ZJYO0ubku7E6Ox+6qVLGQXUhsg87VRYxrocqccAr4AwbW8d8uRRt/pHYwnTH XBNw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=8CJ3I/7LDGs8hexTud6zRTfvlS0atGDHH81M3ADEHcQ=; fh=8qCaggPtbUrdt/xwc3MzyndUXPJZjhBPaGYsFhspncg=; b=mhdhC36Z7+zRvivgcu5kBOYZYxxcnsgjhJO9f92qpW0VbpDyvLXEVaFTCwt0Zti8T6 0MN9rwVZcLVL8lD+28nNuCLdK6B6yLylpfOwdXi5cbh4lzc5SuZM8+wwWK/7ADQGsuRJ UTIX8INvQPYmk8SzJz6OysbqcMK98nMU5k3FFiAATXHaqOS+RKc7JqmxRoAJm2+F1Ke/ E3H2vVoayrARUqkZfOG5JdaHGEe9s70KmyUYpJ3LzcOKm4YNvVynVoAJQJkcYQ1Gng44 bXnOJ7ETaYQ7cFvm2yJWYuCAHcoYJPp4gnzOQWBc18k5SYSyKj2c7TGwasZTjo0MKzlL HSyg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aHud4XwU; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-1263-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-1263-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t15-20020ac8588f000000b0042a32d18156si5538914qta.87.2024.01.22.14.34.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 14:34:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-1263-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=@redhat.com header.s=mimecast20190719 header.b=aHud4XwU; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-1263-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-1263-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 E6C051C2680B for ; Mon, 22 Jan 2024 22:34:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3159B38F8C; Mon, 22 Jan 2024 22:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aHud4XwU" X-Original-To: linux-nfs@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A728B39842 for ; Mon, 22 Jan 2024 22:32:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705962771; cv=none; b=EGaHpF2ozozTSQG76+NBKaCSD4HCNCSqEPGaGzDnTb0OCeLThWYc4FSGjWhn+xwg1CKCY0U+1USw0PeEnBuc8wyzESTVPn7Ee02+YgYWsOdVQIMvx4EedamvSESIZS7b5VdBvHAAD2F23uW/FMOJTpO0MxoQLOLpJNhozcTOXvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705962771; c=relaxed/simple; bh=OfIzfUBOegY/aA+DNYcmnKkvNEOiMv9jvlr290zr5sA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=miCZBSQxSNXxSFxpGXovmZz7pVig7f5m94PWTWHvyGw//YTX+3bjaCbPbpX5v/X2n+o8y9C5Z4Ex8f+wRh8X/aiypZlTrEzPpxKxTTxB18voZW/tAZSOjPcr9PChwQZReirrxmP+pmClbNQpc8Aea11uGQPCZhFkSOCW0mQqVmQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aHud4XwU; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705962768; 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=aHud4XwUiCzDnHmLUdWbyaRsy41l+XdKyxF2Gi94FY8gavgVyTDB9tvcB/Fogc1IKFfSfc ma+Tm+RyjEmkiZ705cgmeeTYZIG1LeGoBlwcxokVmqwbt8nc+FqzBMUWZ3GnFCB1dUCADl s/RawRz1+bH5hmzX7YatSVELGxTP37s= 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> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 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);