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 93C852765D4 for ; Thu, 16 Apr 2026 15:05:15 +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=1776351916; cv=none; b=HVQT/JbN6Ll/8fTeHNkvT2jPXKRyGiY+xsiADfqaUnAeVNBg3DSNYvJMTK4RqM0eY9D47YyUa9kS4L44RKOkpOMl0dzUR1wynlwXQsOUzjTSULZ2N2ItCwkpYCwDVca2qHsOWh+vislzN6BIT2mH+Ic5fSUndaV1B3kr5sVcAkc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776351916; c=relaxed/simple; bh=eHwt/va35RX0B3XvH4wXeA/Nm8JL1UL7yeNyEasE/T8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=W7H0QGLcy3N+jt5P4pDRIkG0EOQACK1DT1RzQGjGDbRtBXGUukQ6ynJTIwa6URiWMctmdwMoaqvOf2k1Y/2Bu91TdANal8/+lN+1Uk42VqECxffc0zYoGP4JppoMibxYu/A6XWJhv+rzEAU4hd4ytt2g7FI9uBZK3vO0SJr3XqU= 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=jINeIuOF; 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="jINeIuOF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776351914; 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=m4gb75M8YCvPYkbm9loOeyD3KdV2s+awxP4z+g+nqNQ=; b=jINeIuOF1w6glFMxuRK926RZiBYtm0mdWLI4rVMQQWPjghz1TFyRee09q+htzXL9BUCWj+ 3asdfcIGk6xFSg+V8mbDHd/IJKWx5GKUT7F25WdnUTMqt4TKZCFMaofJDlY9jI1FkA4q1S snQor+VKtIwl8C1EBhNsPtAz0x5ywp0= Received: from mx-prod-mc-03.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-115-m4Xf4pBlPnWbp2yE0l7h_Q-1; Thu, 16 Apr 2026 11:05:05 -0400 X-MC-Unique: m4Xf4pBlPnWbp2yE0l7h_Q-1 X-Mimecast-MFC-AGG-ID: m4Xf4pBlPnWbp2yE0l7h_Q_1776351902 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 38ACD195605F; Thu, 16 Apr 2026 15:05:02 +0000 (UTC) Received: from [10.17.17.49] (unknown [10.17.17.49]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D856D1955F25; Thu, 16 Apr 2026 15:05:00 +0000 (UTC) Message-ID: <96c3f46d-0d32-463c-9ebb-f6e740e3ce5a@redhat.com> Date: Thu, 16 Apr 2026 11:04:59 -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] lockdep: fix NULL pointer dereference in __lock_set_class() To: Xiang Gao , peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun@kernel.org Cc: linux-kernel@vger.kernel.org, Xiang Gao References: <20260416085443.927247-1-gxxa03070307@gmail.com> Content-Language: en-US From: Waiman Long In-Reply-To: <20260416085443.927247-1-gxxa03070307@gmail.com> 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 4/16/26 4:54 AM, Xiang Gao wrote: > 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. > > 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; LKTM, maybe you can add "Fixes: 64aa348edc61 ("lockdep: lock_set_subclass - reset a held lock's subclass")" Reviewed-by: Waiman Long