From patchwork Thu Dec 14 00:47:51 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: 13492153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACDAAC4332F for ; Thu, 14 Dec 2023 00:48:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EF708D0082; Wed, 13 Dec 2023 19:48:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 39F3C8D0080; Wed, 13 Dec 2023 19:48:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2418E8D0082; Wed, 13 Dec 2023 19:48:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 115EA8D0080 for ; Wed, 13 Dec 2023 19:48:03 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D6475C0BD2 for ; Thu, 14 Dec 2023 00:48:02 +0000 (UTC) X-FDA: 81563586804.14.CFE1815 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) by imf18.hostedemail.com (Postfix) with ESMTP id 116D41C001C for ; Thu, 14 Dec 2023 00:48:00 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NsLzL58t; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702514881; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nejB0rN/5EGuA3SQQpabp67CuxIikS5y1NrnTFuMISI=; b=egb4xss8WawqRXAQrR/gig4Rf0oQeqrHcfOBIa1JUsNHv4NgnRBmfQnX5Be41JCCGzDNpE N10jSLjTPgbTuAJfj+8wGXHu+BCy3KbFjaQU7L6RyMwESdKqyaxLc9LjjDGPFf4kFFR9Qd 6y+QQewg5vUzZI/WS2fitowYADVesII= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NsLzL58t; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702514881; a=rsa-sha256; cv=none; b=yVnFBZEjHuEZ/fZ9yaCK3lN43flSjoZ82sc5w4qhuG8Ol4lUr6Sv+Hvtd4ieCuv5QCWSj2 bv5GKWZqOAyaLSvKYRKyymopLLfelrJUQnyG8xO4yiTyYNAkpNrWUk48XFfMjBXlvWPi5e jHs1D82DJnQTXp4kefK+Wqsr7CqKW6U= 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=1702514879; 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=nejB0rN/5EGuA3SQQpabp67CuxIikS5y1NrnTFuMISI=; b=NsLzL58tlPR9ugxKAnRyMd8DrRr+SxvUinNtJYzd6v9CkqeQBI6h1vLxoqNrpoCC29ye9N snkjrMQ3Lu297rvZMIzUP/4NoNDeq3Szl+q2xjymcO6Gf9ebqHjZLk5pBsolFcBwIiCaFX W97yEg6DpDpdzNXtnmn6OJ6I/lrlXyI= 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 -v2 mm 1/4] lib/stackdepot: add printk_deferred_enter/exit guards Date: Thu, 14 Dec 2023 01:47:51 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 116D41C001C X-Stat-Signature: dyxn5i9b4tio9iexinmitthqa6ax863m X-Rspam-User: X-HE-Tag: 1702514880-706932 X-HE-Meta: U2FsdGVkX18lqL44YSC2NqNCvk0dfouUg5GZ0DHwddD++Opm0YjmXCGhrexom0V963entZESEfkm7ZK07ERo/7Pr5O52v7CG67pJmpEw+O6SOcVToF0pQFMkyNWcarEgRL1LYdEa8QGWEzRJQ/MEM6KNKy2TMSTjP2RZuRAJrmi00p4uJQFxtOoWxVQGEogtRa9sCTraGpiKuCvmU4MPO8sW08cH9F/RwuF60cdakngOoZ7asP3UfyE0MCPwdMyCI2AmWwwICgXuDlx0zpjY9nT4X2hcfBXFpDwcqmTEHLhpK/o4Sbvp/5sxeAd/jB2O0O7pp3mJgdbwVLuuj84FIQZ2jIt+A+bsKr1LtCSHQwF+g+AGt/tbIBvjh2BTL0uZ+EI3Hbg4Ds7/jd0XhfKps7ARwRJTLGVjK18jYer0b7iu1XnoAJ5Ifvn2r+6nVy5UN+4ysSBmhq6HB0dGVZl9IHWjXw2kFYtqyKgAe4Ca6ZbdV+c7Z26pN42ZC811FIABmtgBHKvmW1v34PMJErpu+YfF6IZa5iarVIxa24iL40QCKQggTqXyKfvPtrRibzewNOQQvitA+aarTssSrM2k8Bc9ewtVc9127aqG1DuS1UbDm93IsgDpmK9sJCrzxzENon0iNuFkAn5yG2Ddb4lVHd7Mk7CP1DkIzgcLmDmX9e9AMB3Ca9DfryPQHx4Xi6B1g8AnXRJ1N7g6H+ZpQFR17J+EUJkianOQIhx+tZ/du8tfWmy0EK9tARwemtJpGZzw4d+76xWds3e9AB9LwzXPM8QOUypjE/H4eDTaYLtLOSq06rsvexf7SDaSd8y4cPuL3pXz5J2t+cEI3BYdNqSIMPHRCezhf0zhH7dj9hDpLBlfGbvuc3Z6pHO23pk7KyM3SnHPhozg+iqKd/BOTgOsn+SnJdigcarnphimssqoc3t2kF2+42fDVfQk+odn1AHXC60q8y9RRaCdGAhpCM7 GKxs8a/V ZOo0i5kfV4Hzrg70k93Cj48L3QAbJ4F6agAopqiYrRNhQZeA356Y5kgFJxyInaep+sKAdT5M7AQVC/9wZsqRXndgJ6ujJo4x2WhLb6bDTnyD8rIBaKnjLDHEBDV7iXUdjIQeZNvxQbduK006l+ZBg23nIun0ioIa6MbLYxISdcSfOTIo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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/ Fixes: 108be8def46e ("lib/stackdepot: allow users to evict stack traces") Fixes: cd11016e5f52 ("mm, kasan: stackdepot implementation. Enable stackdepot for SLAB") Reviewed-by: Marco Elver Signed-off-by: Andrey Konovalov --- 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 Thu Dec 14 00:47:52 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: 13492154 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F561C4167B for ; Thu, 14 Dec 2023 00:48:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 249228D0080; Wed, 13 Dec 2023 19:48:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F3B178D0084; Wed, 13 Dec 2023 19:48:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB1978D0083; Wed, 13 Dec 2023 19:48:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CABEE8D0080 for ; Wed, 13 Dec 2023 19:48:03 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9C9F31208B4 for ; Thu, 14 Dec 2023 00:48:03 +0000 (UTC) X-FDA: 81563586846.07.1A70F37 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf17.hostedemail.com (Postfix) with ESMTP id D7F8B40004 for ; Thu, 14 Dec 2023 00:48:01 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ukeh5H64; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702514882; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8YssiUYIuDBfUgViHa8UWZbb+o2fPyHhfOU9iGYPOo4=; b=wzHYdFrD4xlZa3bOMt8VbPjtexvajmEgyu5FeKIUvjPurdz93/KKfFDWUrl/zGqoxZhfLi A+lWrSnJmES6MHntIFoNkqDFGbrbEa3tPg3wX1f9NXtRPgjCZRNasgBNzzJZX1r3yoG40T QkBCHOtZAF6H2AiQ81cjkTmnfrZ05Sc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ukeh5H64; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702514882; a=rsa-sha256; cv=none; b=jMLMKqIp+fJ2bfVUoFrHy3cIG+sFF8eKLzazqeu93tL7U0SpgbYyLVpJu3VFnBNqKUbiE1 tIiJSm13j6wL8opnQhIPqXJfl5AS8ORwfKCO1s/ynObxlrB9Sbx/XdFqCyMPOPl9sKcbCt qndIo2O7HrVASWql3Az1R+xjcPhta/A= 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=1702514880; 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=8YssiUYIuDBfUgViHa8UWZbb+o2fPyHhfOU9iGYPOo4=; b=ukeh5H64ggk42fU3s6NTf9eHd2GIMqqgZ/CqDcfXQdJSfR4jhY5GxkoRPyps3uU323JLgZ TniRsk/5uPbcuJZvJRywDrgPNugzxiX76SI4CJMOmkh/ZLwplUIxY/5qcBKDt2czbq/Gkx jFr5MxIf7T+y9Q0QrUq8z27yYq8OoyQ= 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 -v2 mm 2/4] kasan: handle concurrent kasan_record_aux_stack calls Date: Thu, 14 Dec 2023 01:47:52 +0100 Message-Id: <88fc85e2a8cca03f2bfcae76100d1a3d54eac840.1702514411.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: D7F8B40004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: yy9j1ykci8ggjd4w86odgmtth4yejwn8 X-HE-Tag: 1702514881-684051 X-HE-Meta: U2FsdGVkX1/DB862sgUfOEHOpcaojHkpSFB8+GX91FTK5xhHAe8HlQDe4UtuII3t4AQroR5QIVngCYOVFCuBaWlFiOUdPpCeYnb8amLUCS5yXI4Yexg2nKc8wvIjDksmbFFhh5tlv7OdCd0SVsiS0om3vVfG0z/uTes3DuQ/NC5v8ScaLghPIkSJ8LIV6rdRwnl0DDAb5ELzu5m9XtMB0PSmIXOz6/m+epouTExt6CurXPPGrDegRMJ+/EvW0CUfQHEKj6rmB3vC4WYaXXbbzexmK/voEg4S872NC5TewprPmK/tIurf/6JlxwwKuETz8eOQ3KFG1pr/7GziteShLuUs9SlvuFku9jMJmEgQO2Y/qKJCQs1rnbHkY621csWdDBsj6CxggfH4H0hNvNUC/eFKnYmu4+DYw9Tv7BVoNAjb7Egn9FzMJ1k4Wiunn6g8JeEM/6ck79PtZDDRyT9Thm+m9+8culgx3a0DFdy4obvq6XJSjZHk4/MiOk5r2Kz25uPNzIx5+IqRpkbDB0rLF99necqB6Me25oyyA6Jg4N85lcwFNbisCiV6OR1azNi+XUVtZTc7hS/PiBCnNtLyum93EYbQuj2cFwZu/O4a6wZABcqoIYva99dhjQyRUrCtxthwauE4xQWAE9BkBt3PUHgOS4Rsty8XiFMAOeca68VNHmwIakwmlnS/e3+wDeRhg1bFCsuu12W/fvUcIci5iAaeRpDj3vdcw/OXeF4UZYDVfOkRTCtVCsENT3JfvP/sJfCqPu2IwG+5BvZTyAGg4/ejnwnQmoUMQ1VdXR87HRHpbwH2ZZJIo/V1G61+2ejQapDXxj7lAfWLRIeYOkmwVAfXIbt+f+QDUU8H0t3V6sMgiOEuj3+ONSrp2aAI/YMS3J2oRbNYB6MFswcSNvlyKuCW0njsUP89epSdsoL+WZGm8CNJb0/c1R4rmmMK7WW9QZEPJwCT80J0H/uFSO/ poqW5abY 4BeZhHXrrILC9ONO6lrHs31Te2ardSQFTeQNWTmd/44qlkWuf76tVT6cARfLiYIrqKLSuoe1WiqTI0VvhSEqx8W38vg706rYTAYxjladCsOgUM5C1YYDp0WL8oF6E8an3vzgNGFWvqZgmGE+0WEOaMGt3jg7/WYiy1p2BGClERNA5dFLquMKfWu88n9EPgECGdWe8VItVrOMiUDORvNp5HyvyUiM0bD9gwYx90kh+SSSt6u0x0dLD+slUJWXfeDbIKMt/eXOuCSd5vPDahERIReDsvQS+ljH6CZ5aoHUVK/Jr2noIBDWYz3vqhzyrleFzRH29c/q7LJvSC+c= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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, which in turns leads to incorrect accounting of stack depot handles and refcount underflows in the stack depot code. 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/ Fixes: 773688a6cb24 ("kasan: use stack_depot_put for Generic mode") Signed-off-by: Andrey Konovalov --- Changes v1->v2: - Use per-object spinlock instead of a global one. --- mm/kasan/generic.c | 32 +++++++++++++++++++++++++++++--- mm/kasan/kasan.h | 2 ++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 54e20b2bc3e1..b9d41d6c70fd 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -471,8 +472,18 @@ void kasan_init_object_meta(struct kmem_cache *cache, const void *object) struct kasan_free_meta *free_meta; alloc_meta = kasan_get_alloc_meta(cache, object); - if (alloc_meta) + if (alloc_meta) { __memset(alloc_meta, 0, sizeof(*alloc_meta)); + + /* + * Temporarily disable KASAN bug reporting to allow instrumented + * spin_lock_init to access aux_lock, which resides inside of a + * redzone. + */ + kasan_disable_current(); + spin_lock_init(&alloc_meta->aux_lock); + kasan_enable_current(); + } free_meta = kasan_get_free_meta(cache, object); if (free_meta) __memset(free_meta, 0, sizeof(*free_meta)); @@ -502,6 +513,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 +525,22 @@ 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); + + /* + * Temporarily disable KASAN bug reporting to allow instrumented + * spinlock functions to access aux_lock, which resides inside of a + * redzone. + */ + kasan_disable_current(); + spin_lock_irqsave(&alloc_meta->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(&alloc_meta->aux_lock, flags); + kasan_enable_current(); + + stack_depot_put(old_handle); } void kasan_record_aux_stack(void *addr) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 5e298e3ac909..8b4125fecdc7 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) @@ -249,6 +250,7 @@ struct kasan_global { struct kasan_alloc_meta { struct kasan_track alloc_track; /* Free track is stored in kasan_free_meta. */ + spinlock_t aux_lock; depot_stack_handle_t aux_stack[2]; }; From patchwork Thu Dec 14 00:47:53 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: 13492156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85E3DC4167D for ; Thu, 14 Dec 2023 00:48:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D661C6B0397; Wed, 13 Dec 2023 19:48:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D164A8D0083; Wed, 13 Dec 2023 19:48:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B68A26B039B; Wed, 13 Dec 2023 19:48:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9AED26B0397 for ; Wed, 13 Dec 2023 19:48:04 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6D30B140150 for ; Thu, 14 Dec 2023 00:48:04 +0000 (UTC) X-FDA: 81563586888.29.209E8F6 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf20.hostedemail.com (Postfix) with ESMTP id A59451C0022 for ; Thu, 14 Dec 2023 00:48:02 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mE3jhmI4; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702514882; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fOHzqh8IZvvUQEcAVUngjlYsg+ArhHiPZJoDS72WUGY=; b=71Cxn27jPqeCrl9AOP5phFGFe78LKlEmS6zJnbh8Zm6cQnFN2j9HuSyok3/mHuk1g1gGO9 n5TQyZjZBqZk83GkjduSZ6qRfdNoqDSPhsClhuEhTIjMTWx1IwV23mfbkPMB50HkHuins6 Fr9pvucrCicHJNRZ1txdNnMNWgNa5hU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702514882; a=rsa-sha256; cv=none; b=mHnuAfaNgwpV6Qo48o/KxYUUkPV0CzodQ+yaYdOaJKKvu7cdGQw3f9qZ40mm/USDlogGM/ LnAVE3hsH16KKPYAlVop4ax+BMqXLf1huJ9mFfv1eogj540ATx60kxWHvnzxzU9FIE3Sy7 WFwqBc9eXYLWhoS/IwSksNpG9xC8FBE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mE3jhmI4; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev 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=1702514881; 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=fOHzqh8IZvvUQEcAVUngjlYsg+ArhHiPZJoDS72WUGY=; b=mE3jhmI4IuQyy9Oj7FbJ4UWoTg80r8UlyLdLcotJ2d/EbCumZB6ZIk/usRDEldWY+o2Do0 taeItiOWOIa0q4b6vqwJB8QO9mSeuaXO84ASNC46APW3IbCNy6spdT/VnDOv9ZjJh/7OiI jNBCabIu/dOKWGrgx7tbKL2hH4yxYFI= 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 -v2 mm 3/4] kasan: memset free track in qlink_free Date: Thu, 14 Dec 2023 01:47:53 +0100 Message-Id: <39bbc4d0bc72dfaf02f9dc63ee6f25a8f3a1719c.1702514411.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: A59451C0022 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: swpw94xki6s49dhx6aasastd459inag3 X-HE-Tag: 1702514882-441171 X-HE-Meta: U2FsdGVkX188g0I+rV9M6xRou1ZUp9/VnkEju9EttOO+uEmEVNzAPg+LPyZhSPhwLNsLjVaTWpsBegjHJlHKTqWcbNVW3kOkAy3iOR7Lem1Tm2PkT5msDWjhKyMj1ncZwvh6Q5qF2BLHnuWZ/sCKbf775POANlI5t2G1zfTlYMkrQv9eWojBEJSkNnw0xYVuBDyqJD0X1APkl/I2OdAKIXI7aUkvw8GVbc6JbEW3DRJJ9mck7i9YQbBeE3+M+qX7y/qguBfSkP5ydvHgoJvuBw2pagbS0VJxwDdtvU3jp9fVFUmCr8YSStU+7fM/TgcuedxqUioRbtGf4JaZLjvmQJI00u9G2m/6PU732FQwVOYbAvWWxI0g5l83ho4Y86Q3KKZOfRuchIWcYlvmVf8wUV4Qw911LJzn+yUBf6TRMG08KEi6gA0CglICbgTMFX8Dw9cxggLJO/tkXcgZq3PcE26fSB9ICnBVVydTdv+IwQyrZBfapYCBWwtXhRdC5ewATWnex9jTCAw+zE8FLDAVQ14vUIartQ3uvK+/avzO5owYJc7qm5PemtDra+p546hDRO4cIgo4lqUrAen2arHQhGwirRruu8kYEFXInT49mqFrzbVPhMYxBSX4QFFdThWENS75aIf4mLsgEsimV2Vk9txwQPj+B5zRoD6KoakFySmjxt71iuwksnmBpST+75WtJlOawOlIH54IGdEdeJEd0q3A9/k4llHhgst/WKNCTmAyPxm4tXQYxTkXYWyNRsgZmMo9nzLPfgzbPbX5TyY5W+M9dfT8QDv+JupHW+rOjFtUz2VoHG+xPtvJKTYGj0eOzkdLV917uVSiSAr8Q+ESqw4gOHz7Zs+MJff0JT63LfSM8VI8IERHzfB/jP2EpwUAGXJqjNhyQxKBO9LHz5NZs/l65/i59XRLQnvFeW3CC9HibpEroOd45M8m2vP8mpNumk6Rhsgut5Em49ZsoJ2 lY9f9ysC E4JaEAloFq72f2PkbyPRtoejCp9s7NLpg6xbdCUirbkzi452aNJwJjEYB6m52nUO1+nwrqOdabHw/RthSRt3EJ5is5OY8Gm9nILKg X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. Fixes: 773688a6cb24 ("kasan: use stack_depot_put for Generic mode") Reviewed-by: Marco Elver Signed-off-by: Andrey Konovalov --- 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 Thu Dec 14 00:47:54 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: 13492157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A252C4167D for ; Thu, 14 Dec 2023 00:48:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 579628D0084; Wed, 13 Dec 2023 19:48:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 501888D0083; Wed, 13 Dec 2023 19:48:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DCF78D0084; Wed, 13 Dec 2023 19:48:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1A10B8D0083 for ; Wed, 13 Dec 2023 19:48:05 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D5954A02E9 for ; Thu, 14 Dec 2023 00:48:04 +0000 (UTC) X-FDA: 81563586888.29.8B00B5F Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) by imf21.hostedemail.com (Postfix) with ESMTP id 2DC4A1C0012 for ; Thu, 14 Dec 2023 00:48:02 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=chtz44aT; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702514883; a=rsa-sha256; cv=none; b=K2s2FodOXTnB/nIo4HmxZ2AtshrAEYoZw7sWCfDZ6dXvnrqXK0Yfd3MycBdDqN8BSQkZZt w7K/Im3OwbCGMFMBms0n9nbSdEFiBCoMsFifCoPERlHbjoE7PqaMsgph6qwitg0DXblTQQ 8yXGgvs/6NZUslGP1lNqwCHa698qqT4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=chtz44aT; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.175 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702514883; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nCFM+nFcyoFd/gCQWZCb7EKvVZ+qSBSDeoPEA8Jfh0A=; b=SgxV9yftgPtpP1z9JJls/pInydj1Z/JnnWizdiUrHUQvjlMDD8jSyqs19Bk2jY3D4mUAoe jtsCq8KY4t5KJwUA7zmEX+Lnqs/FQnZRAQB3N89fdYFY1yhSdr+D0XkzGuNTETUImQ1nBv 00vM+rQO8VAvi3cHOxDNKOmZVcrZTBI= 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=1702514881; 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=nCFM+nFcyoFd/gCQWZCb7EKvVZ+qSBSDeoPEA8Jfh0A=; b=chtz44aTYYSc5cpdlXhKLUKTZ86AJYhUci1b1n4MvFn6OsB2ibs7ZQcAic22uNrBAd8YVr Eaf1Gto/kQeCtiRuJu5GHpZr6mJXhZ9iHzXRU8IBsCW4j6J1IghuG97ROmbXrolwlXm6SD iEGh8YGKXQ0g7vJ2SGCdtWFc78uL3S4= 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 -v2 mm 4/4] lib/stackdepot: fix comment in include/linux/stackdepot.h Date: Thu, 14 Dec 2023 01:47:54 +0100 Message-Id: <4123304d92b1ca3831113be5be7771fd225cddf9.1702514411.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2DC4A1C0012 X-Stat-Signature: pksaduyy6qpgukb9b88n1eyq5x6b7gsb X-HE-Tag: 1702514882-4796 X-HE-Meta: U2FsdGVkX19tUWKU3QqTEIX553ZqTYr8v51t6ngsPne/H+dMirAOHnP4fukOYLizK3231Az84NNvHpfx92Sxo6JpxP5FqGzOkIbwq5p/zElIo4kNDYnFKFK8sS35kEo+x0UlGojpQCC/RY6y5JJ+74bup2656yBLtx22ZCZVMcJKmHazilu8+piTzel3coW6EO/JpOdygU/lU4Hhmw+cRIQA5Jk7dI6C6ysbXJ+bKSHFmjA2fkfUP4+uiyGgSjflCYq8/BYPnybr7fWstDEgy8362yS4yXCk4Sy92dNTljksBtMfpLlCG72R8p0l0B2CcJa40ALpJoYQhCzuw1KDCFIkpT6Q1oIVl3D7D/cmtnncF4Wvn4Ed1GcalDitWLu+SEPKhmBiWJ/lJwafXKWfetVAkyT29r/PS0znGtj1+4bhazR3QBk67QnvEykibFECOzl3GctStEGSr4HC9+lUPSuVbEBzC8/Uz3MVv2ptQs8E9i6+w63G3VYFfNumFHJ2axe85QWi12JkQxoGHuQi2NM4saJX/vthanYQBBcXje6PWBTa7E+dJIM615N83zerAhSemDzryoRnp2qTm9zTmZimS8gAj6TcY3Daghjj/V0DOxr3KrKd+wlnEsSYdrol9e6Gfb/CaLpkMFY1+WdG08ZCPqf9q4JETtvyNyT/Zzy2E+T4u4YwEx3Lm2CdOwqLopkxP4Tag8iH6CWwPW9QG+/ahSrMhKcXVkfSqkXuUSH5iQLdnIHINYwGDPWs/uC2Q83F1QAeIFNGSFGs3lrOxP/e00JiF4E1zmrlfjUMdyUjOp32b+MoUa0vUIf4Gh9F1VVckAMIwiO+7T6N5B7upSFr4BaHRa2gYN6B+vJOEwovL0ziywU5KtEpPrvvMZL/Xq3kCELKlyHhFyZn+D/Bl3rdX61mX0PwFi/Nnmbjf1IcHtb8uffLdR02lKqCmOwuFoUieOPwn5FA1WgeZQS i6w6nGP7 xbBUClI5H+QPpzWoIf/eOphbwdlSdRYF0+3M959LVjZerperw+C0WG89UppD15a9qs+hkufaPjv0W3gHRXhn4DhDXGo3quNC8ksri X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov As stack traces can now be evicted from the stack depot, remove the comment saying that they are never removed. Fixes: 108be8def46e ("lib/stackdepot: allow users to evict stack traces") Reviewed-by: Marco Elver Signed-off-by: Andrey Konovalov --- 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. *