From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 D259635AC0C for ; Thu, 11 Jun 2026 18:15:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781201734; cv=none; b=GbacKTMqcwr+6qmKebHI1M58DupJRt1dbqqapz68irzOqkrUHSpX52+krtXZpNIeI+pFo5AH0YIxTj60sBtlo6O3ZEnOHQqOTYvX/8muM9HERXZCI86S61ic/mCQATvuPr/iZDP1M/igj5w0SKsWYnY+peZNEHAB5rPBwJD5BFw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781201734; c=relaxed/simple; bh=bv1u+vkFYDOamVWIB/0iHGW8Aw8Yr4lkHVDW6Pcy+lk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VDFZ5If6hbIAz+l3I/iN/Y6vpclkILdDpsPYxag76P4HbL/uvrdu3Qc7UX7r0/tuXTy5KUJh4M3sxzC9gRafmSt2soajEh2P/aERlWrXmp7pL4Impmizb2UnXQKQqXU1QB2qiYGLLfj/4cd/olPFYO968MyynhDCprS8aKI298I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=TOqTZisg; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TOqTZisg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781201731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ugGupMPQc8KOlttDI8zHATNftHzy71ZDSWGH5RtETa8=; b=TOqTZisg3hkcvz/iZW0/zzgN7TGYEhzbJ0NcVBMaevhv+OIh0CwYgFTsHfzvrKAACX8lqu lr3APNj5jGasMuglTfu+pxev37NWf+jawgNYaYk+CuXUrS3INvTwXo/GabQh8rJHIWUKFz UaVCi7xcDUyKM2SIX+YfBvG1FK4acAM= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-470-OUPsZ7G9PsiSJCkpz34nqg-1; Thu, 11 Jun 2026 14:15:30 -0400 X-MC-Unique: OUPsZ7G9PsiSJCkpz34nqg-1 X-Mimecast-MFC-AGG-ID: OUPsZ7G9PsiSJCkpz34nqg_1781201729 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E60621955F07; Thu, 11 Jun 2026 18:15:28 +0000 (UTC) Received: from [10.22.88.176] (unknown [10.22.88.176]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 95BCA1800583; Thu, 11 Jun 2026 18:15:27 +0000 (UTC) Message-ID: <677f24bb-158b-40dc-939b-9f6c3ad0b0ed@redhat.com> Date: Thu, 11 Jun 2026 14:15:26 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] locking/lockdep: Fix NULL pointer dereference in __lock_set_class() To: Naveen Kumar Chaudhary , peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun@kernel.org Cc: linux-kernel@vger.kernel.org References: Content-Language: en-US From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 On 6/11/26 1:38 PM, Naveen Kumar Chaudhary wrote: > register_lock_class() can return NULL when the lock class pool is > exhausted, graph_lock() fails, or key validation fails. However, > __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 wild offset that corrupts > hlock->class_idx. The subsequent reacquire_held_locks() call will > invoke hlock_class() with this corrupted index, leading to a NULL or > out-of-bounds pointer dereference. > > Add the missing NULL check, consistent with how __lock_acquire() already > handles this case at the same call site. > > Fixes: 64aa348edc61 ("lockdep: lock_set_subclass - reset a held lock's subclass") > Signed-off-by: Naveen Kumar Chaudhary > --- > 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; Reviewed-by: Waiman Long