Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp969339rdh; Fri, 24 Nov 2023 02:16:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/HHD2SvMF1r/N3SvaDEWUvLtg6Yqe0WoyXgurvz3kuhuIwY+kfinI0gDA+09rnhbigmIU X-Received: by 2002:a05:6a20:7d96:b0:14c:c393:6af with SMTP id v22-20020a056a207d9600b0014cc39306afmr2877819pzj.0.1700820990335; Fri, 24 Nov 2023 02:16:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700820990; cv=none; d=google.com; s=arc-20160816; b=TKfnbdKwTI0RW//mrmnh13u/zSRUAgfO/SXRQMf7gN15h5kQQwWPPTzzvfH96yhOsB rmS2bzIDy9P2hFEfAijnuEg+jc+p8Bb/heTbQPNz9v9hvRNIpz6wrWdWcfvMkloAX+Ci pd1UaMaPT4W4leKgsZmJs58eGQ3qACPhTvVl8uo80wjWeFrq+1eqms9hLhMyz4v+WWYU 1T+lqjBfeNd+wrKzOyOQc6tqpweXVuExf2b8t8HGr1nUnETo7WfJysLG5FFxp6yu0dAz NK3Qmk+qNBT+S1nvsLUdDLHCgReMtN74q8AZBvZlHQfMliNI4IsFKXsF0rKvseAGinx1 KJ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=u7aU0X/sqpgYUwPx+c8pZR8R1BH27ZWy+KyLcXN294M=; fh=Vo2q+OLEOabn+mTy7BNGeCnEtFHPqDncSLh0VGkQ1eg=; b=kUvRnroeb3f+eLPupunE1Shp5Gcv3cQnmDsjZ6LJUftIaldg3ka6HXgdXSLOlgAchB ZdfIRBTy6ASX5j/jFMGedlJW5gPDBuz9S3KC4jvwCsZOUEwZeCLh+RoIGpjt2PtwpNY9 EMYqWQbtodveLGiU4hXpF23tot82sXwC0RK6dgYEneGCWq+ls5zM55kV5t+jZ8fpZ93e ayEf6kVvG32GrbzvWu7grcV50pvE5CaozNf8aADoKmWQxrBFPeZ3jb8+N9Av4+SrE7Nw E1b/cMBBzi1GWwA+X3VubKg9k0ha0JoiqWEqYu1j7doIZPU0Qbp25sTpTiN3SzHxgo+t vZMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ODfqP21F; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=we9vcT+0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id m13-20020a634c4d000000b00577680ccf1bsi3280721pgl.709.2023.11.24.02.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 02:16:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ODfqP21F; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=we9vcT+0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 030F080A52BA; Fri, 24 Nov 2023 02:16:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345407AbjKXKQL (ORCPT + 99 others); Fri, 24 Nov 2023 05:16:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345564AbjKXKQA (ORCPT ); Fri, 24 Nov 2023 05:16:00 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0933810F2; Fri, 24 Nov 2023 02:16:07 -0800 (PST) Date: Fri, 24 Nov 2023 10:16:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1700820965; h=from:from:sender:sender:reply-to: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=u7aU0X/sqpgYUwPx+c8pZR8R1BH27ZWy+KyLcXN294M=; b=ODfqP21FCJ75BJfo2CCuiEk2W4AsW1oux3GfYfEF7atGab1B99ONoW/YyTU4ZH+STegTzs k1TIpPO0ykX884zdwHFbHwBvyuJ2ZIqOBNlX8VzPuZGZkPgZC3Ssrt6pFG3LF5xt1PYH/x Ozg38cWP6Lle2Ncsv6oWFBf/MSiaz+tmbY+Rk/9Er/tSOUIWvun+s79DT81yqUxikkh780 RCndUSqcdXHcaiDvnVRQ6B+6JPaPjZ22rk6+RjJ2rd8BHScBoDpBZq/YzHfM/TAoTVEKZu XdbwikS9wUHdmP/jgMD+2AiRQl0eT9jB/eru/abYm7W6g/CuyytuUGy/mPqtXA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1700820965; h=from:from:sender:sender:reply-to: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=u7aU0X/sqpgYUwPx+c8pZR8R1BH27ZWy+KyLcXN294M=; b=we9vcT+0pRShDzUC5kMESoq761AX60N3OQojJGXMqzMkM3HG0Po5IUa1nDiyYsdfnAmLWl U0OOd6MXfv4t4ACQ== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/urgent] lockdep: Fix block chain corruption Cc: Kent Overstreet , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231121114126.GH8262@noisy.programming.kicks-ass.net> References: <20231121114126.GH8262@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Message-ID: <170082096447.398.12922994682541625976.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 24 Nov 2023 02:16:28 -0800 (PST) The following commit has been merged into the locking/urgent branch of tip: Commit-ID: bca4104b00fec60be330cd32818dd5c70db3d469 Gitweb: https://git.kernel.org/tip/bca4104b00fec60be330cd32818dd5c70db3d469 Author: Peter Zijlstra AuthorDate: Tue, 21 Nov 2023 12:41:26 +01:00 Committer: Peter Zijlstra CommitterDate: Fri, 24 Nov 2023 11:04:54 +01:00 lockdep: Fix block chain corruption Kent reported an occasional KASAN splat in lockdep. Mark then noted: > I suspect the dodgy access is to chain_block_buckets[-1], which hits the last 4 > bytes of the redzone and gets (incorrectly/misleadingly) attributed to > nr_large_chain_blocks. That would mean @size == 0, at which point size_to_bucket() returns -1 and the above happens. alloc_chain_hlocks() has 'size - req', for the first with the precondition 'size >= rq', which allows the 0. This code is trying to split a block, del_chain_block() takes what we need, and add_chain_block() puts back the remainder, except in the above case the remainder is 0 sized and things go sideways. Fixes: 810507fe6fd5 ("locking/lockdep: Reuse freed chain_hlocks entries") Reported-by: Kent Overstreet Signed-off-by: Peter Zijlstra (Intel) Tested-by: Kent Overstreet Link: https://lkml.kernel.org/r/20231121114126.GH8262@noisy.programming.kicks-ass.net --- kernel/locking/lockdep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index e85b5ad..151bd3d 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3497,7 +3497,8 @@ static int alloc_chain_hlocks(int req) size = chain_block_size(curr); if (likely(size >= req)) { del_chain_block(0, size, chain_block_next(curr)); - add_chain_block(curr + req, size - req); + if (size > req) + add_chain_block(curr + req, size - req); return curr; } }