Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp3406075rdb; Tue, 29 Aug 2023 14:41:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFXpJarfdTV6HyA1PQAgc/Klhivz1MefJQ9AnN0E6W+ojDv3tnHCI2SmWBDfRI7Ny7aJWM X-Received: by 2002:adf:dc81:0:b0:318:c108:67b0 with SMTP id r1-20020adfdc81000000b00318c10867b0mr226931wrj.48.1693345305522; Tue, 29 Aug 2023 14:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693345305; cv=none; d=google.com; s=arc-20160816; b=crEzcyXLsKK32Qq/6WFuktf4snTA38ZhqjGfCpY5X4VLdcK6lTMw54aT9FaaZRmhA4 qU/qdhM0Hl5qVNKEImMS7yHcKY2+iLkByP/R1ayNcpWURkp4jRYMO8RsQgRaQUC+Tsrw MioGOINwf870T+ElardQkfVDWHqwiR+4HXBwwaXnkqmsw4GnmYli5kWIzQLok7Z34Hfr QnnYCGWBT/G4vbAg8Saq6XwASlOhVrc4zkGSnGwRIkPt4BrTYux2R1xpfn95NX+O1VyV pDuGr0C1hrxke+kVlHqLYi++7CXeA7LfyP5ouhkc3Jt3rawxcg4JkGv16LtdTvAfKfu0 STnw== 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=nl/mi/sJhm8d2IDMyyx9SK432XHk6oEEQ1PTooRDAe8=; fh=J1Qt2dYQZwHfoASHEf8Q1j6KnDtpzzpCUlDsDM7WT0M=; b=MRudbxHw5fKQjcAqM9pXgZKIuhNYTYO/mAE/1VVW10xs4ESGFyohtoC0cdmbwXcCFr Txk6/wy7tz78Cbowc0Hh6low6yQi6qvG0V2YasIgeUpZC42DDBB0zhyItJxrCPMLyIcv dTSdfVn2iNTDlcq4zHfRQ8RqpLSjtzuJfi9nTAxa0KrEQ6QoMDH4PlOX0VkWYvsXAuRC 7zXll+bujP5T7u53h+Awn785N+dQgMk6WWwUjBYeFsbsDJ07f86qIZDsUmPIqk80Ml0I ntCd4BFW/e0IX5fCH+1CVptogAPlDGDVKPA3iKkgMiUXwtXbgDrBO5iGifRHt9gSoE2f nZ4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=GlaqijiJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m22-20020a50ef16000000b0052a4737a084si4566069eds.397.2023.08.29.14.41.13; Tue, 29 Aug 2023 14:41:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=GlaqijiJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237735AbjH2ROx (ORCPT + 99 others); Tue, 29 Aug 2023 13:14:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237767AbjH2ROh (ORCPT ); Tue, 29 Aug 2023 13:14:37 -0400 Received: from out-250.mta1.migadu.com (out-250.mta1.migadu.com [IPv6:2001:41d0:203:375::fa]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B4F81BD for ; Tue, 29 Aug 2023 10:14:00 -0700 (PDT) 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=1693329225; 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=nl/mi/sJhm8d2IDMyyx9SK432XHk6oEEQ1PTooRDAe8=; b=GlaqijiJCNuxG7rw/crBXwYIu+bsbRgtfNjI15SsNv8t1sbXPGyc+8Qf9Y8QvqLJiZuTi7 ZNtWdGIvQFFzknC6Cszo4DXXBT6fdVhnEoWLc28FUoQtxU/76o7hIYC2gdCczCKWh6/THq P/TGvd/MEaLMkz+3R7oGxuH+BvdITeQ= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 15/15] kasan: use stack_depot_evict for tag-based modes Date: Tue, 29 Aug 2023 19:11:25 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov Evict stack traces from the stack depot for the tag-based KASAN modes once they are evicted from the stack ring. Signed-off-by: Andrey Konovalov --- mm/kasan/tags.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index 7dcfe341d48e..fa6b0f77a7dd 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -96,7 +96,7 @@ static void save_stack_info(struct kmem_cache *cache, void *object, gfp_t gfp_flags, bool is_free) { unsigned long flags; - depot_stack_handle_t stack; + depot_stack_handle_t stack, old_stack; u64 pos; struct kasan_stack_ring_entry *entry; void *old_ptr; @@ -120,6 +120,8 @@ static void save_stack_info(struct kmem_cache *cache, void *object, if (!try_cmpxchg(&entry->ptr, &old_ptr, STACK_RING_BUSY_PTR)) goto next; /* Busy slot. */ + old_stack = READ_ONCE(entry->stack); + WRITE_ONCE(entry->size, cache->object_size); WRITE_ONCE(entry->pid, current->pid); WRITE_ONCE(entry->stack, stack); @@ -131,6 +133,9 @@ static void save_stack_info(struct kmem_cache *cache, void *object, smp_store_release(&entry->ptr, (s64)object); read_unlock_irqrestore(&stack_ring.lock, flags); + + if (old_stack) + stack_depot_evict(old_stack); } void kasan_save_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) -- 2.25.1