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.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 BA3A23655DD for ; Wed, 17 Jun 2026 17:26:56 +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=1781717218; cv=none; b=oLziMP+EY0RyeZ5XaqcHdACW25kLcCc5h6O6bln5GH6nYr5HPF56eWzxJWTE5JbV+WPQD7gW97W6edSEcYaQs1iD6qgpGWSQSN+2r59b6mEaFkEtXOHpw9SAH4SelfWp7fjF96wfRZ8dGWb8O+/PE+sIff1fziTqfH311HCmfTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781717218; c=relaxed/simple; bh=SVuWvNXAJdLnmhxDi6bSJ2mD7liZlRdZxDiceBIMOJw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=eYCgh8oIOMYL9R2svJYHXkT5Y5YR5AbkGFv/ohiy4iBmiut5/o7fLRRe/V0ka7hUxe44IebWpylx8flKXgHP8h9BwAsebD8gTW6Py/OFdPaYIUCBRZE5idO2FIOo4aFyS7B5RbsQzZrfTLiGy0Q6ElxzerdeN7ZicJTOXFppXWc= 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=EaxEUetj; arc=none smtp.client-ip=170.10.129.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="EaxEUetj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781717215; 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=0R5glA6CNY35B/kttSdVGEUZr2eYHJh7TmEMbG8qc1I=; b=EaxEUetjsBRcqJworUNQnNc7UM3IO2icSgs05L48OgPJhi3URElQKIgfYxXoRSg7kbrCMV nAPLVGP4kP0NuKqmKxDhMOO0mQ1fzprccYp2MoUhHoiqqb0lSMBAbsYNT9tcKfRVSZ9x0b wZunoV+aEh/dk2QsGpTKMCh8lWvJ8Po= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-hQAzJSqtNm6tWD11wDECyQ-1; Wed, 17 Jun 2026 13:26:53 -0400 X-MC-Unique: hQAzJSqtNm6tWD11wDECyQ-1 X-Mimecast-MFC-AGG-ID: hQAzJSqtNm6tWD11wDECyQ_1781717212 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D98541800675; Wed, 17 Jun 2026 17:26:51 +0000 (UTC) Received: from [10.22.65.196] (unknown [10.22.65.196]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6A5FE1955BC2; Wed, 17 Jun 2026 17:26:50 +0000 (UTC) Message-ID: Date: Wed, 17 Jun 2026 13:26:49 -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: Validate class index in lock_chain_get_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.0 on 10.30.177.12 On 6/16/26 12:40 PM, Naveen Kumar Chaudhary wrote: > lock_chain_get_class() extracts a class index from chain_hlocks[] and > uses it to index directly into lock_classes[] without any validation. > If the chain data references a class that has been zapped (e.g., after > module unload), the class_idx bit will be cleared in lock_classes_in_use > and the function returns a pointer to a stale entry. > > Add a DEBUG_LOCKS_WARN_ON() check using test_bit() on lock_classes_in_use. > Return NULL on failure so callers can handle it gracefully. > > Update the sole caller in lockdep_proc.c to handle the NULL return. > > Signed-off-by: Naveen Kumar Chaudhary > --- > kernel/locking/lockdep.c | 3 +++ > kernel/locking/lockdep_proc.c | 2 +- > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > index 2d4c5bab5af8..ca255269b714 100644 > --- a/kernel/locking/lockdep.c > +++ b/kernel/locking/lockdep.c > @@ -3561,6 +3561,9 @@ struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i) > u16 chain_hlock = chain_hlocks[chain->base + i]; > unsigned int class_idx = chain_hlock_class_idx(chain_hlock); > > + if (DEBUG_LOCKS_WARN_ON(!test_bit(class_idx, lock_classes_in_use))) > + return NULL; > + > return lock_classes + class_idx; > } > > diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c > index 1916db9aa46b..2d1f6b43edd5 100644 > --- a/kernel/locking/lockdep_proc.c > +++ b/kernel/locking/lockdep_proc.c > @@ -170,7 +170,7 @@ static int lc_show(struct seq_file *m, void *v) > > for (i = 0; i < chain->depth; i++) { > class = lock_chain_get_class(chain, i); > - if (!class->key) > + if (!class || !class->key) > continue; > > seq_printf(m, "[%p] ", class->key); When a class is zapped, that particular class should have been removed from the lock chains. Have you hit any cases where this warning can be triggered? Or is this just for making sure that this condition won't be triggered silently if it ever happens? Regards, Longman