From nobody Tue Jun 16 04:40:54 2026 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 3DD232192FA for ; Sat, 18 Apr 2026 14:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776521697; cv=none; b=H7Hnel3xMI/cp2IyUY5FphldBJtJy/UWPM+4ZRmkMrl3nsY+pqHBRBwhf4TwMHNweT2OQkYHLnLqvrsN9EaRs6otkyn2hKbaj9wsycJlQOTQdRqyJ4ONt5dG2r26KXL+ymvgWhltmFbEHGeyfwme+I3AjSF5BAufgBxncKoU5u0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776521697; c=relaxed/simple; bh=0vtjriV52OS0LoUh9dRcGhTFFLQzBz/Qdx+0KfnsHN8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=pWimZMmVfGlkAwogYqxemvo7G6Kpaez5WVjYYz6vMHWM2VdefEIXd5hq2LXKQoYJwvRe6f4eSZK/s3QvRZpvhPpTDTNorlCyIdhrR46H1XXgFF8bX1FPtcmuSJ5mfBCnvfrD3TNqmizdm41n5s6l/+sDWaixUk/qIZVhZtL5jDc= 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=RdjIOTme; arc=none smtp.client-ip=209.85.216.43 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="RdjIOTme" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-35691a231a7so1043428a91.3 for ; Sat, 18 Apr 2026 07:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776521695; x=1777126495; 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=hmK+FaYBx8F8lD/RxIKvrljDvHgFNEYIgLZCmJZ8B00=; b=RdjIOTmeyWUGooS2XfdO+PIoMhg24CjgwGrN8fqA+aR7zNpGrMwx4oINawsLFzLlvr h1ezg58JySsMO7fliFQbe48fBqEiH2dNMfRgwVC8OPhMb0CTChAiptOXliuHV6mck74k CnkL9p2+S9F4Zqt1r/8RkEt1IxRqWqk5oqIs9sNbDlbCv1Y2tcggfT6A+8oLtSCfl1x5 DKWDDCCbwe5tM+WMFmFr/iYkWHTfl7ZqMg3CXhE71BY9xy7BdlUl18tFqaDigGxAdt+6 fjIiFX4oXB2sfyVwybc1DBfw1dDpftqd6FtevV1P9GUmuVPD8qpEi5TdCmb58enlibH2 1cig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776521695; x=1777126495; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hmK+FaYBx8F8lD/RxIKvrljDvHgFNEYIgLZCmJZ8B00=; b=dk0akaXPeMuQ8MkypxMmMEJzCZp+ciP4mc199XpxzN9HcWYpBBlTdJLFlmZkjW3jA1 jqxJlLlmE81zsNBFkeqHaXzxBeiHlt2Yse2fFqHKRf/Uid/jRNdM4rE9eB3VpX5nyQVH lVedQRdxcWcxIKL+3KQDv+hRvFZEHIsH3ltLJ9VuR6qYigOsgnU9zX0ETYEg6Xu0Feu5 8h93LJhc3GjbNAvofyaD/MmDrMUjIfaG7uMvwLyQsp52uA6t6RaWv3FM9T3QKsX601l7 AH+8iMwo43xfRysIaZfFKoK/uyW4BII2fz55vwzFYT3WXVFGj28TQ1oXHRjaK6J/CJx6 H4pA== X-Forwarded-Encrypted: i=1; AFNElJ9KSDG0xE75gX3Jtl+v/sQBwvk+YYIsOS0azkR/Wz8pbfnGBsUGsOGooXoKSec4o556UjiuS+qykqHQws4=@vger.kernel.org X-Gm-Message-State: AOJu0YztDAwMWgQjcOlAGnxRomrYEIcRVM16cU+nbRxuX2oG6nL2VLJo RTRYNt0fYArLVGyoa6rBHhfvxoaneQ+1O/tLOGG9Uz2Zz1t2mYgCNqko X-Gm-Gg: AeBDietq6SA0BrCzCesnDbXq4vBks6c6c+TdJGi/3sLAJ+qj/eLAUftEvyisL3oseu2 QbCC+lvzRU6EeXafSuVsmlzBi6rn2mh6iIUhQtJCwjUHYiSsw4lE+KpUHfmWfO3ViBdFdv5ZLAx 4i6JjmtvFTjeJSatgnWqh9Chd2IH3aZbp5EsUYUYVhcCUqlPP5AMzm4fsOtWIbL1sEs1EyKvJ8j c+ugn6TWBaZ8hdF0MnjahnRcWL1j+Ksh+OcaFS5ptso/athdX5HB15AdpA6+LH4pqA0jZyN/P6w 7s/OlvCxRCAF5ap6MQFEOFQHW7MUutCWTb5gl9A6YshkfHooy4rsnzUURq3ciBTEFB4sWER1kHz F5Bfk1mDZFX5zvNMxP/eNC8OEK7KE0XtMAKdapfij6jFKyP4jqQTle0VGFEN9kUBHFnxWFwuo3g r8mkEquRTyv9cGC42bhC5cSbQS89LcUd1tiW204VzP12g= X-Received: by 2002:a17:90a:f94f:b0:35f:c5cd:cc5 with SMTP id 98e67ed59e1d1-36140498686mr7739972a91.24.1776521695534; Sat, 18 Apr 2026 07:14:55 -0700 (PDT) Received: from xiao.mioffice.cn ([43.224.245.230]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab3ba16sm53389995ad.75.2026.04.18.07.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Apr 2026 07:14:54 -0700 (PDT) From: Xiang Gao To: peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun@kernel.org Cc: longman@redhat.com, linux-kernel@vger.kernel.org, Xiang Gao , stable@vger.kernel.org Subject: [PATCH] lockdep: fix NULL pointer dereference in __lock_set_class() Date: Sat, 18 Apr 2026 22:14:50 +0800 Message-Id: <20260418141450.1499057-1-gxxa03070307@gmail.com> 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D register_lock_class(lock, subclass, 0); hlock->class_idx =3D 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 subc= lass") Cc: stable@vger.kernel.org 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 =3D register_lock_class(lock, subclass, 0); + if (!class) + return 0; hlock->class_idx =3D class - lock_classes; =20 curr->lockdep_depth =3D i; --=20 2.34.1