From patchwork Tue Dec 12 00:14:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 176970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7419145vqy; Mon, 11 Dec 2023 16:14:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1UEmnyTLu5yoGad58t2ucW9pHozHLXSZI2p/SAGmJlIqi7+57g5O5613Nd9tjqWj84IIZ X-Received: by 2002:a17:902:d2cf:b0:1d0:c986:8aae with SMTP id n15-20020a170902d2cf00b001d0c9868aaemr3076365plc.97.1702340093517; Mon, 11 Dec 2023 16:14:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702340093; cv=none; d=google.com; s=arc-20160816; b=Onxb+qFv9V28XDca4empeo/Hqt7oxENuN7wdaHJzw+EivHVysXp/NIEghz1Oij6EaW ttWRYuO3QP7gr0sMTJXhSNH0DGY6e0B5NEoMeMBLg+FuR3umZPWyOBKfNJCsc1GGAW/y cyNwAueNOLxs/8/g+0KUYZ5fYz6Vv8FyGAZAindyLkw8B3bdTgNpm5m2h40DRKY2n0aX rTXgtrU50wCKFid2v8hLabEsq+HT0SIAa0/OTGn5ycV3RAGU6YGQFOQJOQdAHcA7ENII RwcU/el3H8Z6fvyYf8aZBbfqq+hZhm5fGMTu9GDODXUH3NG0w7zazc7hK83k584ZSy7k surw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vOaXJmSZ4mgcOuCRTmHs9viCNJ5mspLX8zhenk2W1qY=; fh=R37Itr4vM4DSdM7nCVEJRaUzpyR01xRhpmD5Puf7xME=; b=zyqmPT8qb1cJBgyA++v0h+j00ipPt8GDg0Zv75adjvLUlX0uJ5hrybuyWWVnjAahiw nq87aJchjyuxhvXagVwNNf1gvDH64eRDfOAXUpH14jePLwXLMJ14v+qgICwFTTlQ2/mw OtWkuZieadHKwfCvDVmXGcjBYrCgrRnFVn/CBOgWG0W0GQz550qDtRREQ2mjCPVheql2 yEofm1dGKDYQ3N2/wjxgO9n3t55NMEq7Giy/qF7TL6yVmEsqRTREox9TLvcRDAQsAJ7U 4aPrBJst0d2AMY3HF3sVQvEr1w7W1QR8j3dh/BIaKS7QKfyUwsH+Oz9dkGzCDDoT3GHf gUoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZFY0MXvU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id x9-20020a170902820900b001cfb971ee07si4523239pln.165.2023.12.11.16.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 16:14:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZFY0MXvU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 86748809B767; Mon, 11 Dec 2023 16:14:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345425AbjLLAOG (ORCPT + 99 others); Mon, 11 Dec 2023 19:14:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345394AbjLLAOE (ORCPT ); Mon, 11 Dec 2023 19:14:04 -0500 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF517B8 for ; Mon, 11 Dec 2023 16:14:10 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702340049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vOaXJmSZ4mgcOuCRTmHs9viCNJ5mspLX8zhenk2W1qY=; b=ZFY0MXvUwTln62U1tHBt6KK8Dqg+6tfH+i/GfcUa4eujPC2CC53JaDXpaZhT1eWOt98GO5 rQ36NXtwX/bnZpsUbbyhXz3bTvVFqA6FvpYHeqX+qP0YEUP3BL6KN8k/7Q6TNtfpTILzXF HbnIpR5duzaXmjUbV13x2oH9iQ3NxmE= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Tetsuo Handa , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 1/4] lib/stackdepot: add printk_deferred_enter/exit guards Date: Tue, 12 Dec 2023 01:14:00 +0100 Message-Id: <6c38c31e304a55449f76f60b6f72e35f992cad99.1702339432.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 16:14:42 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785032965876998761 X-GMAIL-MSGID: 1785032965876998761 From: Andrey Konovalov Stack depot functions can be called from various contexts that do allocations, including with console locks taken. At the same time, stack depot functions might print WARNING's or refcount-related failures. This can cause a deadlock on console locks. Add printk_deferred_enter/exit guards to stack depot to avoid this. Reported-by: Tetsuo Handa Closes: https://lore.kernel.org/all/000000000000f56750060b9ad216@google.com/ Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- lib/stackdepot.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 870cce2f4cbd..a0be5d05c7f0 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -506,12 +506,14 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, bucket = &stack_table[hash & stack_hash_mask]; read_lock_irqsave(&pool_rwlock, flags); + printk_deferred_enter(); /* Fast path: look the stack trace up without full locking. */ found = find_stack(bucket, entries, nr_entries, hash); if (found) { if (depot_flags & STACK_DEPOT_FLAG_GET) refcount_inc(&found->count); + printk_deferred_exit(); read_unlock_irqrestore(&pool_rwlock, flags); goto exit; } @@ -520,6 +522,7 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, if (new_pool_required) need_alloc = true; + printk_deferred_exit(); read_unlock_irqrestore(&pool_rwlock, flags); /* @@ -541,6 +544,7 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, } write_lock_irqsave(&pool_rwlock, flags); + printk_deferred_enter(); found = find_stack(bucket, entries, nr_entries, hash); if (!found) { @@ -562,6 +566,7 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, depot_keep_new_pool(&prealloc); } + printk_deferred_exit(); write_unlock_irqrestore(&pool_rwlock, flags); exit: if (prealloc) { @@ -600,9 +605,11 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, return 0; read_lock_irqsave(&pool_rwlock, flags); + printk_deferred_enter(); stack = depot_fetch_stack(handle); + printk_deferred_exit(); read_unlock_irqrestore(&pool_rwlock, flags); *entries = stack->entries; @@ -619,6 +626,7 @@ void stack_depot_put(depot_stack_handle_t handle) return; write_lock_irqsave(&pool_rwlock, flags); + printk_deferred_enter(); stack = depot_fetch_stack(handle); if (WARN_ON(!stack)) @@ -633,6 +641,7 @@ void stack_depot_put(depot_stack_handle_t handle) } out: + printk_deferred_exit(); write_unlock_irqrestore(&pool_rwlock, flags); } EXPORT_SYMBOL_GPL(stack_depot_put); From patchwork Tue Dec 12 00:14:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 176969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7419086vqy; Mon, 11 Dec 2023 16:14:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5ab0T4LfCsGfwIzUcE25ceHIwmL8DIJ3YbQLLHaLAbz9A6LYBOigiO6ncuvRoAbaZkyPN X-Received: by 2002:a17:90a:ec08:b0:286:d210:1498 with SMTP id l8-20020a17090aec0800b00286d2101498mr2384322pjy.12.1702340093564; Mon, 11 Dec 2023 16:14:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702340093; cv=none; d=google.com; s=arc-20160816; b=duOgsAiGGgqsO8JmXgQHuwj3P8FOfBxrdUjbPnK1fJcMECvk2dccAotJQnpQHyd+g9 0xeByVmIOhNEQGOGKpQVdAC9wzuUGpxud7NWpqRt+8PSwexCap5pzg8DzXWn8PzrblyP RNyKnoDjNphOBkjrCMXjJtd2Qj8rmlH2g6BNg/yJfo9c9HLuPZCt4Ffbt+1YYU4JbYnY Mf2iVbRRMRC+uJpctMWgbhld6FQZrXk6p2EzS9bdMeVopv+Y94DSqPe7kSNUlgDIq0S5 7/BoT5vewGunJQGpxt/k5Ni2BXcyQHmwXroGZFFdl3/z47bW9seDZFMra+UYglg1iZVA 6NAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=x4Cn8Rdft153TNfaMCqmpUoRbUij/xgpu9Ka1HxHDYI=; fh=xumGgQ3/A3VHYu1DQDaIWA+Xl29EI5lD+bm6U+z1O60=; b=RQ7/++DF74FAKzMMyX6liNro44kAsEPesbUg1/qHFUM+mSVuxIb0VCPC38lwsyCX2U uZzH6K4ONQBzvv+j5s0qqtyF7gFaQRyFG9jGY6vE2PKMJHu+yqt+5L+r7M0WnUHwSEbP 2BJ0tEZ4YK1GxWpZYUfd1P/HE/tWU65DfOU8bK53e6bLwE+ZHvltNBu2QdFMcndv03RL KtaO+OGCLmPvTxuar13Jrt+zybgqgUph+lWC6wPeL02kT2XmwodEvXeDv4T1fyjDy2Sl 0NZR46DhRhG7oWxAeoZumhJScoF3SWFh+COlkxIhLYxFaRU8Y/v5opI9scy//qg+uvl+ iWSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="UvkDjF/5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h22-20020a17090ac39600b0028688bdbcc4si8284627pjt.161.2023.12.11.16.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 16:14:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="UvkDjF/5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 7CCBC809EE0D; Mon, 11 Dec 2023 16:14:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345433AbjLLAOI (ORCPT + 99 others); Mon, 11 Dec 2023 19:14:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345415AbjLLAOF (ORCPT ); Mon, 11 Dec 2023 19:14:05 -0500 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [IPv6:2001:41d0:203:375::ae]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98EFCAD for ; Mon, 11 Dec 2023 16:14:11 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702340049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x4Cn8Rdft153TNfaMCqmpUoRbUij/xgpu9Ka1HxHDYI=; b=UvkDjF/5ctTo0nGnQabktnmBPXGfus3/X3idORYN6B4D44rXq0KJToDsQKy9BeHFX8qw7b qQCY+W0sZZweOoacCTj/1cWItkpd82s9p4KPKbjHROXaD7+UwOj6FNmJAKaJ2G1O+XKX3R d6piyZ++vR5FIz/37yANY5B0lerp6zk= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Tetsuo Handa , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov , syzbot+186b55175d8360728234@syzkaller.appspotmail.com Subject: [PATCH mm 2/4] kasan: handle concurrent kasan_record_aux_stack calls Date: Tue, 12 Dec 2023 01:14:01 +0100 Message-Id: <432a89fafce11244287c8af757e73a2eb22a5354.1702339432.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 16:14:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785032965944094102 X-GMAIL-MSGID: 1785032965944094102 From: Andrey Konovalov kasan_record_aux_stack can be called concurrently on the same object. This might lead to a race condition when rotating the saved aux stack trace handles. Fix by introducing a spinlock to protect the aux stack trace handles in kasan_record_aux_stack. Reported-by: Tetsuo Handa Reported-by: syzbot+186b55175d8360728234@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/000000000000784b1c060b0074a2@google.com/ Signed-off-by: Andrey Konovalov --- This can be squashed into "kasan: use stack_depot_put for Generic mode" or left standalone. --- mm/kasan/generic.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 54e20b2bc3e1..ca5c75a1866c 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,8 @@ #include "kasan.h" #include "../slab.h" +DEFINE_SPINLOCK(aux_lock); + /* * All functions below always inlined so compiler could * perform better optimizations in each of __asan_loadX/__assn_storeX @@ -502,6 +505,8 @@ static void __kasan_record_aux_stack(void *addr, depot_flags_t depot_flags) struct kmem_cache *cache; struct kasan_alloc_meta *alloc_meta; void *object; + depot_stack_handle_t new_handle, old_handle; + unsigned long flags; if (is_kfence_address(addr) || !slab) return; @@ -512,9 +517,15 @@ static void __kasan_record_aux_stack(void *addr, depot_flags_t depot_flags) if (!alloc_meta) return; - stack_depot_put(alloc_meta->aux_stack[1]); + new_handle = kasan_save_stack(0, depot_flags); + + spin_lock_irqsave(&aux_lock, flags); + old_handle = alloc_meta->aux_stack[1]; alloc_meta->aux_stack[1] = alloc_meta->aux_stack[0]; - alloc_meta->aux_stack[0] = kasan_save_stack(0, depot_flags); + alloc_meta->aux_stack[0] = new_handle; + spin_unlock_irqrestore(&aux_lock, flags); + + stack_depot_put(old_handle); } void kasan_record_aux_stack(void *addr) From patchwork Tue Dec 12 00:14:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 176972 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7419802vqy; Mon, 11 Dec 2023 16:16:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIITPW4AHC759zhmgR7qISqglRUq8pazB8gRamskGTjHnazDZMvKs/xiO1nQmsAOcoy1YL X-Received: by 2002:a05:6a00:139f:b0:6ce:725f:7d9d with SMTP id t31-20020a056a00139f00b006ce725f7d9dmr6642772pfg.14.1702340175945; Mon, 11 Dec 2023 16:16:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702340175; cv=none; d=google.com; s=arc-20160816; b=tXBFFAlfwdeo6ZfQxq9vpUay51GN5+I0kFnaw95f+pZm4XU9ITj6BfDDiTi/ksKb7a +FTSanKjnrCpiq+ne2UGYQGefe9WdE4G8W7y6le/0IPAeV+Yr3laPOkCnd+eePBMp3Bw jxX+v6oMWTMBpU7v/5F0v1iSSnLPIdZPXIT57hsGpBGHQ5YvBt53TeEtbVDDIrx2lvEf Z92gLzxw7UhGVK7Zzh7OSdPHfm+aWhEjsWPXXSOD9X6UBR8qFueCcZoWkRRompVIT83u +DUXZGpOu4AeSTCKkBanlEUJv5zNgLqhb1Ow8H7oFwQPABoqFcJT0xNArAjsHTHCwPZB Ji4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OwbAGppKL3WPs8Dt+2mYc7aec7Z15bPqx/lY8lY4n/4=; fh=R37Itr4vM4DSdM7nCVEJRaUzpyR01xRhpmD5Puf7xME=; b=w6kVh1k61o3v2aDUaQ27QyAFVAMjaVkf0s86OxQidtgZd0BvrbC0qfJBzIVR5bfOgt l0vaIeZV8+btVanBQa8Fhjq4HOUs1VNk5ysOiHCBy4++MQ9pPEV/LMJRsPww4Gz9l4R1 YlC1aRbSyMwA5B4ItT1m6LBWtWEEX9/6vMabcIZJsVT39WjiPikMMDOq9zc2wel41M0C pjv9glvlC0/BT1m7fOQDWkwdIzi7N0pAB4hdeEfw23hmD69on17n39USP9vuhR9fI6aa 9qMb1oonwjQd3oKljLaZP0/H6e1sJqPwI+ydbVsdFig32gao2fTgqOWOm6Cu8GRfR6qi WSvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=AhuNEvWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id du23-20020a056a002b5700b006cdf3e98118si6575162pfb.118.2023.12.11.16.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 16:16:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=AhuNEvWc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id BEF0D807C5FD; Mon, 11 Dec 2023 16:15:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345460AbjLLAOJ (ORCPT + 99 others); Mon, 11 Dec 2023 19:14:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345418AbjLLAOF (ORCPT ); Mon, 11 Dec 2023 19:14:05 -0500 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [IPv6:2001:41d0:203:375::b0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 170FBB5 for ; Mon, 11 Dec 2023 16:14:12 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702340050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OwbAGppKL3WPs8Dt+2mYc7aec7Z15bPqx/lY8lY4n/4=; b=AhuNEvWc+xId+ebmaR6PLfGdXFqw+Wg1SNRrPQ1ZlK1Sc1etaByaW4J7PAGKThBVnj447n j8TePKCfHAMCJ1KwilljkT2LUfiq2L5u0pH0HA7XJfeRd1JbF++UGx/w+zfsttHD227a+f IZQYQmT7JGekNhMS5pIy488rlfoaazI= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Tetsuo Handa , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 3/4] kasan: memset free track in qlink_free Date: Tue, 12 Dec 2023 01:14:02 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 16:15:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785033052439716582 X-GMAIL-MSGID: 1785033052439716582 From: Andrey Konovalov Instead of only zeroing out the stack depot handle when evicting the free stack trace in qlink_free, zero out the whole track. Do this just to produce a similar effect for alloc and free meta. The other fields of the free track besides the stack trace handle are considered invalid at this point anyway, so no harm in zeroing them out. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- This can be squashed into "kasan: use stack_depot_put for Generic mode" or left standalone. --- mm/kasan/quarantine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index 265ca2bbe2dd..782e045da911 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -157,7 +157,7 @@ static void qlink_free(struct qlist_node *qlink, struct kmem_cache *cache) if (free_meta && *(u8 *)kasan_mem_to_shadow(object) == KASAN_SLAB_FREETRACK) { stack_depot_put(free_meta->free_track.stack); - free_meta->free_track.stack = 0; + __memset(&free_meta->free_track, 0, sizeof(free_meta->free_track)); } /* From patchwork Tue Dec 12 00:14:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 176971 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7419289vqy; Mon, 11 Dec 2023 16:15:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNJMVjHdjXtCIm+Mozky6EoDt6/W0Xm7RcvIU7ADv14J4ujmBMsRItJzgvBbq9kVdqjmwu X-Received: by 2002:a92:d150:0:b0:35d:6220:ac8b with SMTP id t16-20020a92d150000000b0035d6220ac8bmr6261177ilg.58.1702340110029; Mon, 11 Dec 2023 16:15:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702340109; cv=none; d=google.com; s=arc-20160816; b=jBrNQ8SrmJx2XcnuPF4RNFCkJb2NyKTaVIdaj5MyaGa/Ur3qCpgUaDUay2JOY2L/2l YOo3WaenXifl7BirH+ShYvtTOjYya2oEh/nbzJ4zqkUHqXScIhbBGyuLK/xeDAQf8Api mLwQ49KWHiGy3GsO8FGXSdWEsQaLH5DNt51Eg+ihByBJTTmx1B0FK74HmhLZ3Jkb1N6j sQaZYpyxgGLQPDUbfsJ14ojjbMx0j7UAOHeS+6XyBQWCA79m0815InnhvYGSw3o10z2R eIXZ3d0kWyTf3YBrw3OBV7RiMuDo85VgHRISCwIKk+XsA5lN5RSfJVPKjS34FC8TraeL fEmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4v2xeqlY3bmUQ3FXCYD1mACtOfLEO5nvek1y1ZiQa0s=; fh=R37Itr4vM4DSdM7nCVEJRaUzpyR01xRhpmD5Puf7xME=; b=q7WeBUJ2Svg+Vpn+KPdUx1WHwLspOc/uWPJ76CxZLUCOZqY7oHiKva3B+3/IA4ZAS4 yGcXZZImS4puWakfamazbJ2IEcmEoMkqsXEqO0ixftgxCEuhDWcgykchLffv6c14lf9F a+CT41vHsKxM6Yc2e94IIx1a8wC5DuBkUyzqmhh6JxBCp8DQAETOdWZ4ipKbnVCzOmx3 dMC6VWZ4WQckHDRlNNtsJqoL9dyM5RKNtw7SRF2iXaDc3lzdbN0GgovcILtHKzBRzmkh mBfKPAQJlNUMz3zdSplWSvdx2kKecWQv0bfeUzpWNRaPtWTMFOPjLRcllXHupkz8ijUZ he2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pkglrqnI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id o20-20020a656154000000b005c14fc66cc4si6784497pgv.380.2023.12.11.16.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 16:15:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pkglrqnI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 0187380BC124; Mon, 11 Dec 2023 16:15:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345472AbjLLAOK (ORCPT + 99 others); Mon, 11 Dec 2023 19:14:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345426AbjLLAOG (ORCPT ); Mon, 11 Dec 2023 19:14:06 -0500 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9946EB8 for ; Mon, 11 Dec 2023 16:14:12 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702340051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4v2xeqlY3bmUQ3FXCYD1mACtOfLEO5nvek1y1ZiQa0s=; b=pkglrqnIvLL1i2TrN6B8oPzonG4Tx1w7mQXL6y13N9tGc5e12sY7eb+AJFYGp9qNNRA6C8 fsFj5WhSBPxuf9OzL/2ucnnjhPh0g/dy12UZ2lGf3lPYNFaJYLPQY3wu39tWi6RGT9VYZk uDz7QstHoOYA5j+8ntWl6s9I7C6+Dv4= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Tetsuo Handa , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 4/4] lib/stackdepot: fix comment in include/linux/stackdepot.h Date: Tue, 12 Dec 2023 01:14:03 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 11 Dec 2023 16:15:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785032983357645527 X-GMAIL-MSGID: 1785032983357645527 From: Andrey Konovalov As stack traces can now be evicted from the stack depot, remove the comment saying that they are never removed. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- Can be squashed into "lib/stackdepot: allow users to evict stack traces" or left standalone. --- include/linux/stackdepot.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index a6796f178913..adcbb8f23600 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -11,8 +11,6 @@ * SLUB_DEBUG needs 256 bytes per object for that). Since allocation and free * stack traces often repeat, using stack depot allows to save about 100x space. * - * Stack traces are never removed from the stack depot. - * * Author: Alexander Potapenko * Copyright (C) 2016 Google, Inc. *