Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3289730lfo; Mon, 23 May 2022 00:49:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUxmxTPgOeGGWxw74yC6Jys/mrvpAY2R7XBa1zJoWhIRu6id3jO1D2rBHj7Vkg8hzPgmuq X-Received: by 2002:a17:90b:4acb:b0:1df:af66:1d2 with SMTP id mh11-20020a17090b4acb00b001dfaf6601d2mr25230413pjb.181.1653292167865; Mon, 23 May 2022 00:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653292167; cv=none; d=google.com; s=arc-20160816; b=tKSI9JV/38xrbtnIqrFOsj7G89ETBP+4MCTFWP9lJiZSwIU/gRcXgf4BOmoZlfCvsu rU5+q83oO7o16Y9p7NPgnq+vrz30S27aWY6HVgRrnkz96mNA5EKLC0hlzauge1S/1avL oYqzXlM8CNzObRkg+Bo1uTdX2sJnvSW5tSrelCD84QQmiiwtcLNnBruX+/6m6Xv92JU0 af4sTY9wauOJ8eo/xU0YtehQjX9Me91XPXNPwiUN+uqyS+0sKXCJ0x9MffNm7ZfKAZAG Ne9cGVbjC7AJfR/W+bKwUIDROROgLProkaPjQOhwUOGiSo2qyTDmuzaXbtsWuo2m1bM1 6F7g== 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:date:to:from:subject:message-id; bh=jWPQBGnCBBiuAI8dxCyzMz7yeZjGXcO6EQYp1E/gPQA=; b=hMUeq/vMW2N5n4kkJSJbasOhVnajv7AgAO5wpDryBtzDqx2qCLTM/p0StFVVXRFGOX 38ukkiiAFADGiX8ylmuy+WhejKnrk81w1Q5JUjXvyYizaI0oaW3ZqMvGG+T03BlFtB1a bI/QOYeI2fdv3xXlbDr12why0Ggl2rd6KE6Tw0gYYxkn7OgQ60lgne1POHd9u9jny5OY hE9HBZ0H7yYfP0ONXHqjptCSJbHUtmjyXz7FHZ6jdJdgrqPtM55REStzVSpFcDWW2sNK bK9MTbOsdavDFMN0bPYKUCncZxLMDdTJFRZhGPWNT7CPYpPWE9N6tn5atHKKqg34wPXZ Guvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f62-20020a636a41000000b003fa8e644434si190978pgc.39.2022.05.23.00.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:49:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F1E182218F5; Sun, 22 May 2022 23:54:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348216AbiETKjp (ORCPT + 99 others); Fri, 20 May 2022 06:39:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239447AbiETKjl (ORCPT ); Fri, 20 May 2022 06:39:41 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E51914D25 for ; Fri, 20 May 2022 03:39:32 -0700 (PDT) X-UUID: 0fc3d0681b8843af85197e923aaa4c03-20220520 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.5,REQID:eeff4b10-2339-4f06-9d8a-4050195bf023,OB:0,LO B:0,IP:0,URL:0,TC:0,Content:20,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACT ION:release,TS:20 X-CID-META: VersionHash:2a19b09,CLOUDID:795c027a-5ef6-470b-96c9-bdb8ced32786,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:3,EDM:-3,IP:nil,URL:0,File:nil ,QS:0,BEC:nil X-UUID: 0fc3d0681b8843af85197e923aaa4c03-20220520 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 898076341; Fri, 20 May 2022 18:39:29 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.186) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Fri, 20 May 2022 18:39:28 +0800 Received: from mtksdccf07 (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Fri, 20 May 2022 18:39:28 +0800 Message-ID: <95510f5fd4913f800d36052e573c56029b22b104.camel@mediatek.com> Subject: Re: [PATCH] scs: Release kasan vmalloc poison in scs_free process From: Yee Lee To: Date: Fri, 20 May 2022 18:39:27 +0800 In-Reply-To: <20210923095316.13867-1-yee.lee@mediatek.com> References: <20210923095316.13867-1-yee.lee@mediatek.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-MTK: N X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no 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 Test On Thu, 2021-09-23 at 17:53 +0800, yee.lee@mediatek.com wrote: > From: Yee Lee > > Since scs allocation has been moved to vmalloc region, the > shadow stack is protected by kasan_posion_vmalloc. > However, the vfree_atomic operation needs to access > its context for scs_free process and causes kasan error > as the dump info below. > > This patch Adds kasan_unpoison_vmalloc() before vfree_atomic, > which aligns to the prior flow as using kmem_cache. > The vmalloc region will go back posioned in the following > vumap() operations. > > ================================================================== > BUG: KASAN: vmalloc-out-of-bounds in llist_add_batch+0x60/0xd4 > Write of size 8 at addr ffff8000100b9000 by task kthreadd/2 > > CPU: 0 PID: 2 Comm: kthreadd Not tainted 5.15.0-rc2-11681-(skip) > Hardware name: linux,dummy-virt (DT) > Call trace: > dump_backtrace+0x0/0x43c > show_stack+0x1c/0x2c > dump_stack_lvl+0x68/0x84 > print_address_description+0x80/0x394 > kasan_report+0x180/0x1dc > __asan_report_store8_noabort+0x48/0x58 > llist_add_batch+0x60/0xd4 > vfree_atomic+0x60/0xe0 > scs_free+0x1dc/0x1fc > scs_release+0xa4/0xd4 > free_task+0x30/0xe4 > __put_task_struct+0x1ec/0x2e0 > delayed_put_task_struct+0x5c/0xa0 > rcu_do_batch+0x62c/0x8a0 > rcu_core+0x60c/0xc14 > rcu_core_si+0x14/0x24 > __do_softirq+0x19c/0x68c > irq_exit+0x118/0x2dc > handle_domain_irq+0xcc/0x134 > gic_handle_irq+0x7c/0x1bc > call_on_irq_stack+0x40/0x70 > do_interrupt_handler+0x78/0x9c > el1_interrupt+0x34/0x60 > el1h_64_irq_handler+0x1c/0x2c > el1h_64_irq+0x78/0x7c > _raw_spin_unlock_irqrestore+0x40/0xcc > sched_fork+0x4f0/0xb00 > copy_process+0xacc/0x3648 > kernel_clone+0x168/0x534 > kernel_thread+0x13c/0x1b0 > kthreadd+0x2bc/0x400 > ret_from_fork+0x10/0x20 > > Memory state around the buggy address: > ffff8000100b8f00: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 > ffff8000100b8f80: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 > >ffff8000100b9000: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 > ^ > ffff8000100b9080: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 > ffff8000100b9100: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 > ================================================================== > > CC: Matthias Brugger > CC: Will Deacon > CC: Sami Tolvanen > Signed-off-by: Yee Lee > --- > kernel/scs.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/scs.c b/kernel/scs.c > index e2a71fc82fa0..25c0d8e416e6 100644 > --- a/kernel/scs.c > +++ b/kernel/scs.c > @@ -68,6 +68,7 @@ void scs_free(void *s) > > __scs_account(s, -1); > > + kasan_unpoison_vmalloc(s, SCS_SIZE); > /* > * We cannot sleep as this can be called in interrupt context, > * so use this_cpu_cmpxchg to update the cache, and > vfree_atomic