From patchwork Tue Dec 19 21:19:50 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: 181262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2234549dyi; Tue, 19 Dec 2023 13:21:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLwt8bXwyRGh2VeVwdbSS2wQtdzEQV6bVxL7kQYqC63slcbBS9ISMclAOS59ii8bWkmkcg X-Received: by 2002:a05:6a20:1483:b0:18c:9855:e949 with SMTP id o3-20020a056a20148300b0018c9855e949mr14393558pzi.15.1703020860002; Tue, 19 Dec 2023 13:21:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703020859; cv=none; d=google.com; s=arc-20160816; b=uwFwWCtNqIt9kBP9d1/HHtUKLaSzChDfJVcAbGPuoIUc3QWEZiL/0VUFaN1lhKtEqj v5BDZCi+7G5v49DDZV+OnJbpu/0xI9TKPkKRuEEDuliGlWpAF4kxPKu9k3OcNIeh1b0M eD6Pp2/nojhmi+4X4EzRGD/Ws0BZK1UVwgSwNnM5WpcC7/W9xU+d2SHlu4FkX+g3Z+cZ WXXqiP5ntQ1HJO0MocOCEyvfiv4KpsM4J6mH5CRFpcbQF6QHZUXOrg8br49/786yvlq5 DSY8NOuwlNWB+kNjmZAHNgrvHwN7xq7jE7ToFgd12ndewWUR3harQiHQAozj3dpLIWAq DH6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nejB0rN/5EGuA3SQQpabp67CuxIikS5y1NrnTFuMISI=; fh=R37Itr4vM4DSdM7nCVEJRaUzpyR01xRhpmD5Puf7xME=; b=GoA42XFK+nKqUE682rZ6rZ1eQsFi0Wg/FGuian5gBWcMrLjyQNJc8tvbTsrT2BHcnJ Lro29cGnadWyUemhWmeEEYC++asfg3vbpVeqZ+hh2iUzJoYLBSL/0f1o56JO0ni5/gd6 iMxIcBaXlyl7fWcMTLTTfqeQZPW/dAkBVlb0z/ON6OO3etaiyFXsQQk3nJYQkWElAYY9 yJlDb7jdAhF9JjLtjZ4ufRZVrorACChr5bREnCR6hbxX25eUd5j5Tql8HAaQfro906cA xB56zXCwxgD3A0AuFKxceUiVNhum8nLtuwrDX2OG6Tl4tiWE1qsLWaEtOGUjD/08Sysy zWuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=elb7wJjm; spf=pass (google.com: domain of linux-kernel+bounces-5959-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5959-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id fc29-20020a056a002e1d00b006d0a6b4b95dsi14134698pfb.384.2023.12.19.13.20.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 13:20:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5959-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=elb7wJjm; spf=pass (google.com: domain of linux-kernel+bounces-5959-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5959-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C1CA8287841 for ; Tue, 19 Dec 2023 21:20:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE9E040BE4; Tue, 19 Dec 2023 21:20:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="elb7wJjm" X-Original-To: linux-kernel@vger.kernel.org Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (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 151F83D0AB for ; Tue, 19 Dec 2023 21:19:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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=1703020797; 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=elb7wJjmHVmMnqrahneo3nmWE9hHEyTRVGuiSBGymfQVeOW15J6gqNykSrIgFdw9PIMbZF ta1kf9P/xFptBLk6yUizJYveQGUO6hzXz1/PIciaF5j55mJ3tEib32Ug4OJ35XYc+zlmf1 5OklhsBMYdcTGxBkNXOkqzloDUn2vJw= 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 v3 mm 1/4] lib/stackdepot: add printk_deferred_enter/exit guards Date: Tue, 19 Dec 2023 22:19:50 +0100 Message-Id: <82092f9040d075a161d1264377d51e0bac847e8a.1703020707.git.andreyknvl@google.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785746801550215148 X-GMAIL-MSGID: 1785746801550215148 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 Tue Dec 19 21:19: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: 181263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2234612dyi; Tue, 19 Dec 2023 13:21:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFbDWXdS6D24i157rqoLS9UQme1xT9Sn2GJQ2xS0wzX027R/FFcDIofqadrtR2SRgrcD0X/ X-Received: by 2002:aca:2b17:0:b0:3bb:6c93:67d7 with SMTP id i23-20020aca2b17000000b003bb6c9367d7mr246380oik.13.1703020870539; Tue, 19 Dec 2023 13:21:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703020870; cv=none; d=google.com; s=arc-20160816; b=RxvTmPIunE+mcY7gisAmgaJ9JDbz6Y4twOLO10JCH1CAIHJZR7TVhCePO3I9ECRNLq 8GKCqwbVKxu6WEEJ68TOG4wykPqFrWIRM/nTIkFReeAljopkXiZYMwCgbsYb0QIQdZMY hQayFsPxs6u9Jd3ZyMrHVQ29n7X4ozpxDVsAB2oSGjnXJM+2I0nG/He7+ccb5PrG796f 3MWxrc8FUEi1ALpuSr41p2pvDVkqt+Ksp2TTNqZF1uKLjIQeOYqeI7IOoVGT2F/bkYgL /ZWYpo+fELZHEtmbGNn25hHgnuisO1Q4MoIra52BQGQHA+YjFqY6xPOaESzVm8YiH2Uy Awgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=IugD6msAA76PLOkulY8RL+cRtUx1nL2a5VcYM7ZPFvs=; fh=xumGgQ3/A3VHYu1DQDaIWA+Xl29EI5lD+bm6U+z1O60=; b=tHX0BTB3gRND+v280Q6waqY337pzwH4oU9pB1zMfTW0rZMCX05IpESqy9YD9GKxnkC PalQHvazlwQnVawYSbBITJO4INQS/IlUOCz0dq6LKVF29JkgCuWGoFY4ay0GYkNxxrwQ Hn4xzvtrYge7zLxUpUCVd/ZRxIkE4V4kzpxGrT9WTNwsXDibPEx/3mM6gNhfSfX/f/lL rhJZWr5hGKm1jo9N3zg074PAn3e2UnNR6TOsDy2BiaftGR2IJiJyWK8r9/8WDbBLAwbZ UbBtTjAhStpK3GI2WakM2+Lzy1lKIeyh7rrSpPOKFHp/J1fQi2TOuy4zxBOzSMx1GjQf AGfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=IR+Whe6+; spf=pass (google.com: domain of linux-kernel+bounces-5960-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5960-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x6-20020a0cc506000000b0067f32e92d37si7455334qvi.31.2023.12.19.13.21.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 13:21:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5960-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=IR+Whe6+; spf=pass (google.com: domain of linux-kernel+bounces-5960-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5960-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5372F1C25190 for ; Tue, 19 Dec 2023 21:21:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58FDD40BFF; Tue, 19 Dec 2023 21:20:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="IR+Whe6+" X-Original-To: linux-kernel@vger.kernel.org Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (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 E3B0B3D0A2 for ; Tue, 19 Dec 2023 21:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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=1703020798; 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=IugD6msAA76PLOkulY8RL+cRtUx1nL2a5VcYM7ZPFvs=; b=IR+Whe6+qpxv+At+vArbXY01tYtvfspW3PKw8UAncGDGnEEps0UIMWhP+wPzEx5NxY9M8h m1TDVtQZm9HrpXOj1mV5z/Lc+HwiQjOjMkmc/bfj2auMjP1/9llRH/NH6L89Gq+qP7zEz3 M7vUVsknaJSSv98tDJGKvpfbqCVOHN0= 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 v3 mm 2/4] kasan: handle concurrent kasan_record_aux_stack calls Date: Tue, 19 Dec 2023 22:19:51 +0100 Message-Id: <1606b960e2f746862d1f459515972f9695bf448a.1703020707.git.andreyknvl@google.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785746812438391833 X-GMAIL-MSGID: 1785746812438391833 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 raw 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 Reviewed-by: Marco Elver --- Changes v2->v3: - Use raw spinlock to avoid lockdep complaints on RT kernels. Changes v1->v2: - Use per-object spinlock instead of a global one. --- mm/kasan/generic.c | 32 +++++++++++++++++++++++++++++--- mm/kasan/kasan.h | 8 ++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 54e20b2bc3e1..55e6b5db2cae 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 + * raw_spin_lock_init to access aux_lock, which resides inside + * of a redzone. + */ + kasan_disable_current(); + raw_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(); + raw_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; + raw_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..69e4f5e58e33 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,13 @@ struct kasan_global { struct kasan_alloc_meta { struct kasan_track alloc_track; /* Free track is stored in kasan_free_meta. */ + /* + * aux_lock protects aux_stack from accesses from concurrent + * kasan_record_aux_stack calls. It is a raw spinlock to avoid sleeping + * on RT kernels, as kasan_record_aux_stack_noalloc can be called from + * non-sleepable contexts. + */ + raw_spinlock_t aux_lock; depot_stack_handle_t aux_stack[2]; }; From patchwork Tue Dec 19 21:19: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: 181264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2234722dyi; Tue, 19 Dec 2023 13:21:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBM7vK7uzoBpsYWxmBGjs26chpcXf4RGpK8V3aopcJLdXCLpRaBvHqcrw9LFPy0qX/jB2Q X-Received: by 2002:a05:6358:2919:b0:170:b0fe:13a2 with SMTP id y25-20020a056358291900b00170b0fe13a2mr22675126rwb.17.1703020884334; Tue, 19 Dec 2023 13:21:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703020884; cv=none; d=google.com; s=arc-20160816; b=CV43LqhlKOP1YOkiPUkzj8aoajSQQ42SR9aa/E4vgrkIpSiA9D9O4qGNdbIctuhwV1 dsouByu1LMOtjRHAgAdhEnp8c00O09S7aWZkm5h6vqXBVA1ob4jgGpFl9ODkpB52Jzfj G+h4Xbs+BMlT4enpMRdRlUAKiHp8tL5Siro4vn+y6f/MjshvjjuT37aiwetD0nKe/0up fXP4eL2kN8xOCR1xOBoW2gOcvLkPXNPZV/gE8hfHNU1G4aeVUTP9yn11+fzupZ6cVgse qdkTnxcS1SdVQvp6YezQg3kO6ggZl+1fQiMcyTDxwbSU3kn7kn0bDTSMivaeKsD4ryuX mRaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fOHzqh8IZvvUQEcAVUngjlYsg+ArhHiPZJoDS72WUGY=; fh=R37Itr4vM4DSdM7nCVEJRaUzpyR01xRhpmD5Puf7xME=; b=R/Vwf07e52bXd/1A3I4Brk8RIml0VD5p0WrLmu5BOZvaT/TEBAqEUUjyHWRIfxhIj0 Su8fJRozcMdVvEtzHnEIkNLUjf4xE1/lPzjoHFeAvwBcUXifOfRoigDifrGy+ceuC/FP JDHemMLFFR4PP5XS+ng30pPII19tgFh1enk63VC9QsGVTGmmEWE6Y+CvJlOI9cbIJQq8 Fwg1n37F12N+gmdaV/p7IjK/whViU/VdsUEHUGGQBdX8dUDi+mBCzanDd4AJXCKXtQof GlmwSNQp2JUg8Q6CrnU5sBKfu/cMzgV92izOKJNCgkX/Ps+TGlocYOwHrPRoABMHz905 598Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=qSi6bCK8; spf=pass (google.com: domain of linux-kernel+bounces-5961-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5961-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 23-20020a630c57000000b005cd7c92f504si6533375pgm.481.2023.12.19.13.21.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 13:21:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5961-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=qSi6bCK8; spf=pass (google.com: domain of linux-kernel+bounces-5961-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5961-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 134CAB23FD4 for ; Tue, 19 Dec 2023 21:21:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E545B40C0F; Tue, 19 Dec 2023 21:20:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qSi6bCK8" X-Original-To: linux-kernel@vger.kernel.org Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (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 770AD3D0CE for ; Tue, 19 Dec 2023 21:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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=1703020798; 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=qSi6bCK82bZzb5eDpiDbrLAgv900bdtXCroZwQk+HMxNuCcAH6RDEUBSEuZXglh3sQ52dp y4hliOr/Z2u8q2lAKSTk3GSjbIMKCqYtE46R+/r0JsXgn8CkNa8Ohm/TliCh9Gv/qOmJ9H dqjaS5WqDKLwR54ujuGm3mhTRxi7Yx0= 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 v3 mm 3/4] kasan: memset free track in qlink_free Date: Tue, 19 Dec 2023 22:19:52 +0100 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785746826721293694 X-GMAIL-MSGID: 1785746826721293694 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 Tue Dec 19 21:19: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: 181265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2234767dyi; Tue, 19 Dec 2023 13:21:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9OrNJ46SdcDtPJIdHl5k855pz8hLiVQzE9Z6nB60wxeev/axUQAFHPg98+I2vtP0XBphO X-Received: by 2002:a05:6870:2307:b0:1fa:1fa6:231a with SMTP id w7-20020a056870230700b001fa1fa6231amr11379988oao.39.1703020889833; Tue, 19 Dec 2023 13:21:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703020889; cv=none; d=google.com; s=arc-20160816; b=aGiiyFFg5WRH2ZKPkUETsXRgz1jiPg9O1aLuIF1mA9MIthiEcG17P2HauO6rM0kd2d yKbIc71gcUSqT/DXbRRhwinRvRvqlJ2Hu/0AP4ihkCS/2D3iiG2hSheesk2FdmQrzgkO 7VjNxRJUuoXFhIOCXjTG43Ls+9py7NnMwn8wo4JD7lwtE9cRbpoZbG0aBBDjQJxoLrZK gbIoWiDxZ6W3iot9PbpvjLGlnkkaChnj4gxiLjUUBrdWBmhMLXTwuRf2Xpwyw5zATB6E +Hj98k39TuLGz9lR7zy7Dacy6zxktAzPVAWDIDHZnbl6a8Isf5dW56+H61JeUfXcjH5t C48w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nCFM+nFcyoFd/gCQWZCb7EKvVZ+qSBSDeoPEA8Jfh0A=; fh=R37Itr4vM4DSdM7nCVEJRaUzpyR01xRhpmD5Puf7xME=; b=uq5c+7c4XnD9ak5A40Doq3vtGY5cZXRfbLw+xPsfO2oKH4Ha/lg2EmGsb31qtu6P+Q +aJixcd4qiCRgW/JTVWN3sqNbsORlVVbC8WQO4LihcjgYakjvvvoQF23GW7lY0w3oLgk taUqzGFiPoRK7W3E2poXnCK0lWGx+kPR3BrnmYnvGrdc7D2+uzQA4TAUjXOh6UvgihxO sav/SzT8nIGKuk0qEHFMNTYGT8iGe5iYa3cTCU4bLJzV+zRdkZN6oW007bMRAZjhQSUU skvWFly3oVFPoUVHNAHVS8q14rAkhAHVS1swwXAq0S8X3nEpvqXa4N+EaU795cdxDbqO gHWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vWTr3qhn; spf=pass (google.com: domain of linux-kernel+bounces-5962-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5962-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j7-20020a654287000000b005c1b2e37aeasi20353364pgp.384.2023.12.19.13.21.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 13:21:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5962-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vWTr3qhn; spf=pass (google.com: domain of linux-kernel+bounces-5962-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5962-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 05795B24284 for ; Tue, 19 Dec 2023 21:21:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A74240C1A; Tue, 19 Dec 2023 21:20:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="vWTr3qhn" X-Original-To: linux-kernel@vger.kernel.org Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (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 1569C3D0D5 for ; Tue, 19 Dec 2023 21:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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=1703020799; 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=vWTr3qhn77AyDPItr7Jb1Va+xZtAYsJMZbCeKfs5+hQd3T8gMEEYCJMliC2zyzhGEytQiS pdedlVWK/90vwulDxVVraP5pN7YgbdG3MBwinwjLSYYIyJMPDTtGDljZA7elKcrlFiXdm6 5vpKeJm4v97c+Ecf3o21M8gf1GjoJH0= 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 v3 mm 4/4] lib/stackdepot: fix comment in include/linux/stackdepot.h Date: Tue, 19 Dec 2023 22:19:53 +0100 Message-Id: <0ebe712d91f8d302a8947d3c9e9123bc2b1b8440.1703020707.git.andreyknvl@google.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785746832596291288 X-GMAIL-MSGID: 1785746832596291288 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. *