From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ilvokhin.com (mail.ilvokhin.com [178.62.254.231]) (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 180F23D412C for ; Thu, 16 Apr 2026 15:20:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.62.254.231 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776352858; cv=none; b=UJLIfpSksWHFahoTA9al+wtwtrtYzQOdjqHN9eep14+1x28LKRr7wlwRppIyAjlUKJpULSS8yImEBUUy7XkuqGBx9wQYNoZxWlpsahgbWKcCb5sT27Z7u4RcZXfnkQEkNFyzdHVypUh3w79w/2UAvAQQjB9+SQjSqKz4JrlW8NM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776352858; c=relaxed/simple; bh=KETVAuZYvGUTelihfRJk6+umFKjITqsCeIvhERnCEp8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=r/u+CLRLBoOJ/rIaFRd9wLnBcwsB+nhOYsyo/scVsIPCq6ClNMGbeC5b8cPHBAAEpWUgBKkadKGatdBfc6NvypA2tlXhg2klCr58SbP5LRz8bUa7ma3o9OIQhnQ6QmYLSb7BNCZYQUGgyEdxJFlgpowf40F+HJrgRkMcBf7cm1A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com; spf=pass smtp.mailfrom=ilvokhin.com; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b=Xei040Sf; arc=none smtp.client-ip=178.62.254.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b="Xei040Sf" Received: from shell.ilvokhin.com (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 39D8FC7468; Thu, 16 Apr 2026 15:20:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1776352855; bh=JpGZcE8hfRC1GUg4kqnHHZM3B85VDFGYVgvYNiTwk8Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Xei040SfqdyOTH/6EOXTxSaOtlBmKZ2Hn+T0uclQsmHKUXdfjyhzD3IqoXcxO/l+j fhiPVAanTRcF4zQAEai7pRwAvfpkDJzgCknmtuMIcuc8G30LrPPIlFGjgIQ6+soWXD vc9QEwZtgcmkorOt0ZuZud4bWzX2aSNXsyHI4pBI= Date: Thu, 16 Apr 2026 15:20:54 +0000 From: Dmitry Ilvokhin To: Xiang Gao Cc: peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun@kernel.org, longman@redhat.com, linux-kernel@vger.kernel.org, Xiang Gao Subject: Re: [PATCH] lockdep: fix NULL pointer dereference in __lock_set_class() Message-ID: References: <20260416085443.927247-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260416085443.927247-1-gxxa03070307@gmail.com> On Thu, Apr 16, 2026 at 04:54:43PM +0800, 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 Reviewed-by: Dmitry Ilvokhin