From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 197DB233955 for ; Wed, 8 Jul 2026 11:08:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783508886; cv=none; b=ipdQ2tqjFCHvRlhT8RoOfCCijRnOEDqP7tkRonyA48b3IFYTNGTzNHtWZvbjvVmZID8NKAGiplI4q0uKzdy1aXDBthWcEKGLFpya12JKoTnHpcRM07Q/G+obR8jrM8HCdxvema5L2bR4pz6k3iH2FHf+GgHbjyCXv+oA1C5AGSI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783508886; c=relaxed/simple; bh=NTcQdvz0cR4eDOgCH5pZ9kcPw+nCYiZrb1LKuCO/DoA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TjJOgtDe8PMkRn7G9FrDnzaJX8wa68bgvyhZJflR5gvVzBsPZmwKkf1+BGH6TkttHUlxZMfAiuHRpsuuu2vd9IKgybO34AiGIFf/4ei+4kiNzkvSY07hFhJJobTyni7yuFoSSOuo6eCW3ik//JZGRjKHYiVXsmXNYmRQPJubfQs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kCQHP4/a; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kCQHP4/a" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-384930ca5e2so561010a91.3 for ; Wed, 08 Jul 2026 04:08:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783508882; x=1784113682; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TXBoNjYqVijB2YGKr+ij7ht747n3ecSYIrYL6ggZywQ=; b=kCQHP4/a30DAPY+VEylDlKyqF2WzadvMH8d8OdGHznWWaY19+3GVk1Di1BxiXYfDxN FyZZMHtcC92DY5zDiCqok5yPVxaYXvo/UAmYk1s4Gca4iAkm4rFD5gtJfz31CII8FKPl q3K+JFOzxXFaLbOokxIQMkM8boHAR5m/0bsd/g1uPMuXAoWbblvik5bcLbbjrUWfXJbC Zbz3oYC7ji2G19uG0e/j3e3qAQad9E0g5SgpmpguuI8VSkD9xKMNHOY8mywvJl1F/3mK e1+9Jgt9RmVhytbNUXWfNb4t1VOOpJFPJEIdoMvOX20WQ4xsKuXszWzh9ELQ6hgWzqH5 MRPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783508882; x=1784113682; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TXBoNjYqVijB2YGKr+ij7ht747n3ecSYIrYL6ggZywQ=; b=nkWswAcOG9HoB9FAtvy3pHQxfVyDPYU4nouYSD5K82fL/VEV3ByYZ8Ebrosumkbghr hRSjS/2egffC2aDEWE4XY7DXI2AXhxO6Ziet+B7yLl8eKp9woaHQvBzbJouCz5iiM9We HnJVXl3zWnwwrwkz+E6jCKoOvkrNiP3hoOUx09nEnc5aRJZCw3eFrL3TNbvr5yBCH/m4 kdviLFDrsv/QyEqAFbCQrymgn6pAe2hjPhPmE+4j82QZ9G9AQWJmEYH7YnHRYqAdW2Hr Y8OWKt2uUwcxgnAfCa/N1gMNagabIqydwrVVtWpBUsLlC4CLL8dOKtwuXfWEIBf2yVSr dnSw== X-Forwarded-Encrypted: i=1; AHgh+RqHktoqnnkLMNxoRWDbmUo1kyAlTrWlySSQ6TdDG3PccKyI+mQ7/QYtxodh+aafxQ7lRL073ZqDYNAPfiI=@vger.kernel.org X-Gm-Message-State: AOJu0Yxoe6i048Pyqm1aPkLogDHHkQBubnImckmRYnhUZr0JnjmHZb3R fRzGocfcAsNl5cg2ZKDfTegUIJOgTzFnKvBbQKzvgBWy2Cg1mh+Tc90m X-Gm-Gg: AfdE7cl1UWFlLkJS8u8xSdRb3Fpgk73XJSo9CiczMw4qUTAETKb9p0WwUMpW2AVtngD Q1akpTz65Zs1ycBhysqQ8M5fpaYacmjohezcC2+I2eqdDto8wa9i3JUSJg5UY0U7MNsq2taK/my cy0DTOHI+iTCO5MgANUgfyKaCcSzTYURp/J0V1qSIpP8R0IcX+uivte7Loz4hF5zrQ8XNg6QC/z vNXqT98SOXfE3uIj8E6ZbQ4PApdeeeyW87MrucpAmJ2PZ4wyLCitzKv5h5SBFdzlRLzJeVawtSK M7bPU+0Tb+MDfXldhvnjHoc5RAf28D94suQsKqxwEmKUPbeM++qhmdrO9HY3+ChzHuMWBmLkPyt iILcKUpoOKArWC28YGHME2Ew3LjZUXFyqUbvJxVn1OrRsshdwgHzd+7iICIrNkaZdzR/Z9wtX5L bS2xQc+tMNmw+I4LCHaJ6wyA== X-Received: by 2002:a17:90b:58e5:b0:36b:9e24:c692 with SMTP id 98e67ed59e1d1-38942f73563mr2056426a91.20.1783508882198; Wed, 08 Jul 2026 04:08:02 -0700 (PDT) Received: from xiao.mioffice.cn ([43.224.245.230]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-387d229a20csm2570824a91.16.2026.07.08.04.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 04:08:01 -0700 (PDT) From: Xiang Gao To: peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun@kernel.org Cc: longman@redhat.com, d@ilvokhin.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Xiang Gao Subject: [PATCH v3] lockdep: fix NULL pointer dereference in __lock_set_class() Date: Wed, 8 Jul 2026 19:07:55 +0800 Message-Id: <20260708110755.1636112-1-gxxa03070307@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260418141450.1499057-1-gxxa03070307@gmail.com> References: <20260418141450.1499057-1-gxxa03070307@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Xiang Gao register_lock_class() can return NULL on failure (e.g., exceeding MAX_LOCKDEP_KEYS or lock_keys_in_use overflow). __lock_set_class() uses the return value directly in pointer arithmetic without a NULL check: class = register_lock_class(lock, subclass, 0); hlock->class_idx = class - lock_classes; If class is NULL, this computes a garbage negative offset that corrupts hlock->class_idx (a bitfield). Any subsequent hlock_class() call on this hlock returns a garbage pointer, leading to memory corruption or a crash. The other call site in __lock_acquire() (line 5112) already handles this correctly with an explicit NULL check. Add the same guard here. Fixes: 64aa348edc61 ("lockdep: lock_set_subclass - reset a held lock's subclass") Cc: stable@vger.kernel.org Reviewed-by: Dmitry Ilvokhin Reviewed-by: Waiman Long Signed-off-by: Xiang Gao --- kernel/locking/lockdep.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 2d4c5bab5af8..e0de81114824 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -5437,6 +5437,8 @@ __lock_set_class(struct lockdep_map *lock, const char *name, lock->wait_type_outer, lock->lock_type); class = register_lock_class(lock, subclass, 0); + if (!class) + return 0; hlock->class_idx = class - lock_classes; curr->lockdep_depth = i; -- 2.34.1