Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp541808rdb; Thu, 21 Dec 2023 18:28:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHy4tt2xqC1CKi4UfdSyofkL1VQvAQ20Qqi61pLHM+5bDF59+jW6MEmOlabVhwCNw3CcQFG X-Received: by 2002:a17:906:4c4a:b0:a23:738b:d5be with SMTP id d10-20020a1709064c4a00b00a23738bd5bemr311387ejw.134.1703212084221; Thu, 21 Dec 2023 18:28:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703212084; cv=none; d=google.com; s=arc-20160816; b=LkV2E4J6WjnFPpWHHD8lowkxuII7ZLD+pSmeGW0nGBTbDz6OmzqZWXE/lMYJA6ZQE+ tDg19c4HeHb+23vi3IehGzlb6TloE4ayVyTSYXRmWDQgbMwlus62ZGFaCUL4TdkiJ4dJ n+AI6rORYIIDJzo1+RRAn5XCE5ZPNEwMf5+0qA3TXUW1w2o10GLmbKLYF4J0v0srcH3b eWqW4akiiCN30Ifxb9XixmcKkh7dU85W4+HljOfhirZkCbJt48239SYb4UZJrLiL+dA4 tgATyu9vgyz30WAcnVQypGtoc/e51Zi7th8TStlF7Uk6qNM5D4sXQdDCXV2anVUdziA0 JOdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from:dkim-signature; bh=NyTkqDg6WwLWozuY326EMKGpYj8UeiaEZFzqtwEMEr0=; fh=/IASj4KK+mUJb39C+oSXhf491hFH5D2t90otYk9aIyM=; b=EexWZ28FyEb2qG6PIwakvsDUv32LMniEEKlqgjqGNP/3eTOqH8ZwTmG5Owf++gmylW rVFpLCcVR6LNVzEHJqsqhsXiFem4u293WfxTqZ+lR+sXUb58AU2wYYH450tbbCTxIwsh OqorHoTcUG/QcN+hQhHU+DpakGlJv5scI50txnkUQmQlWQSLOL2HmSqAGo6Xbr1BLm/t dqlQlZYoITgxoLYwahohgxmMf8dD7ecxRxmHDm5gFcFYkBeq56lRb3yHQi7dKrvp6/d2 Ubko5mphZ/aYQPUf1ch2703PLQjUwUJWD+iayFb3yX8/pi2MrFS3g3guYvK8BJktIfOI bhOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=IlC0YDpU; spf=pass (google.com: domain of linux-kernel+bounces-9262-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9262-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c5-20020a17090603c500b00a1d1f6bb286si1374672eja.302.2023.12.21.18.28.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 18:28:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9262-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=IlC0YDpU; spf=pass (google.com: domain of linux-kernel+bounces-9262-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9262-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 00E791F247A1 for ; Fri, 22 Dec 2023 02:28:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2479323D8; Fri, 22 Dec 2023 02:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="IlC0YDpU" X-Original-To: linux-kernel@vger.kernel.org Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (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 2609C20FB for ; Fri, 22 Dec 2023 02:27:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: b23d8236a07111eeba30773df0976c77-20231222 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=NyTkqDg6WwLWozuY326EMKGpYj8UeiaEZFzqtwEMEr0=; b=IlC0YDpUMP6uCJgd4TE56w04PaWtdh9/2wg4Zvu/aQ8uxu2u8YWPbu4GdSlbGBB/i91ofvda989ATT6DKmeq6nRGPO83Wbdj2zq0Zz7j5hCZ8SI3lIWCSV79D8VlVkNFeK2jKZHJbL5o8wvWAC1lsd8wqQKo8riyt7mfnEMu7Mg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:16c15945-8520-4ac7-9c0b-2746997e149e,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:5d391d7,CLOUDID:dc995c2e-1ab8-4133-9780-81938111c800,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO, DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: b23d8236a07111eeba30773df0976c77-20231222 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 855502034; Fri, 22 Dec 2023 10:27:47 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 22 Dec 2023 10:27:45 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 22 Dec 2023 10:27:45 +0800 From: boy.wu To: Russell King , Matthias Brugger CC: AngeloGioacchino Del Regno , "Boy Wu" , , , Subject: [PATCH] arm: kasan: clear stale stack poison Date: Fri, 22 Dec 2023 10:27:41 +0800 Message-ID: <20231222022741.8223-1-boy.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10-0.324100-8.000000 X-TMASE-MatchedRID: 20do18fyep2bGHSBj+j5WSZm6wdY+F8Kndls9F9zmi3iKUaoIhea7bhd ARHnUbVtXlLd88Celdep0cCmigWLzBmNqsUuotRsws9cphnKwlE+B+IaKi3iScT0k564D5qWs+7 m6nszghjxDYFUSVeB0XYZHJmPi+HdwvvHoQOeXvMdxBAG5/hkWzAKasuXH5J1UekjLrC3lTDcEz 4YkwgVzQzW4ChLfVzzVA/7+pWI2BUdEFCjPPS3/4xVBvj1jbcjfS0Ip2eEHnyTitjWv6+zCBe9C QaLe2PP9xS3mVzWUuBUNjjpwwGmR0kTDcsujd29Bt7dzXQLbrOkxotN8IwXgCM61xnO7ygbYFoo uYX2FOxpt6xIInG8AJdldkdUVkLNgatYyy5QTYH1F4nEZm2WUnmVKZusLp922v9OjYWA2uMMswg 45VMfPadst5iAforfWoC08z/YUWKUTGVAhB5EbQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10-0.324100-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: CAED9D811469AD88D9567D7625B732FCBAC2B7218D7F85C3EE9A8A5D81258E732000:8 X-MTK: N From: Boy Wu We found below OOB crash: [ 33.452494] ================================================================== [ 33.453513] BUG: KASAN: stack-out-of-bounds in refresh_cpu_vm_stats.constprop.0+0xcc/0x2ec [ 33.454660] Write of size 164 at addr c1d03d30 by task swapper/0/0 [ 33.455515] [ 33.455767] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G O 6.1.25-mainline #1 [ 33.456880] Hardware name: Generic DT based system [ 33.457555] unwind_backtrace from show_stack+0x18/0x1c [ 33.458326] show_stack from dump_stack_lvl+0x40/0x4c [ 33.459072] dump_stack_lvl from print_report+0x158/0x4a4 [ 33.459863] print_report from kasan_report+0x9c/0x148 [ 33.460616] kasan_report from kasan_check_range+0x94/0x1a0 [ 33.461424] kasan_check_range from memset+0x20/0x3c [ 33.462157] memset from refresh_cpu_vm_stats.constprop.0+0xcc/0x2ec [ 33.463064] refresh_cpu_vm_stats.constprop.0 from tick_nohz_idle_stop_tick+0x180/0x53c [ 33.464181] tick_nohz_idle_stop_tick from do_idle+0x264/0x354 [ 33.465029] do_idle from cpu_startup_entry+0x20/0x24 [ 33.465769] cpu_startup_entry from rest_init+0xf0/0xf4 [ 33.466528] rest_init from arch_post_acpi_subsys_init+0x0/0x18 [ 33.467397] [ 33.467644] The buggy address belongs to stack of task swapper/0/0 [ 33.468493] and is located at offset 112 in frame: [ 33.469172] refresh_cpu_vm_stats.constprop.0+0x0/0x2ec [ 33.469917] [ 33.470165] This frame has 2 objects: [ 33.470696] [32, 76) 'global_zone_diff' [ 33.470729] [112, 276) 'global_node_diff' [ 33.471294] [ 33.472095] The buggy address belongs to the physical page: [ 33.472862] page:3cd72da8 refcount:1 mapcount:0 mapping:00000000 index:0x0 pfn:0x41d03 [ 33.473944] flags: 0x1000(reserved|zone=0) [ 33.474565] raw: 00001000 ed741470 ed741470 00000000 00000000 00000000 ffffffff 00000001 [ 33.475656] raw: 00000000 [ 33.476050] page dumped because: kasan: bad access detected [ 33.476816] [ 33.477061] Memory state around the buggy address: [ 33.477732] c1d03c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 33.478630] c1d03c80: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00 00 00 [ 33.479526] >c1d03d00: 00 04 f2 f2 f2 f2 00 00 00 00 00 00 f1 f1 f1 f1 [ 33.480415] ^ [ 33.481195] c1d03d80: 00 00 00 00 00 00 00 00 00 00 04 f3 f3 f3 f3 f3 [ 33.482088] c1d03e00: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 [ 33.482978] ================================================================== We find the root cause of this OOB is that arm does not clear stale stack poison in the case of cpuidle. This patch refer to arch/arm64/kernel/sleep.S to resolve this issue. Signed-off-by: Boy Wu --- arch/arm/kernel/sleep.S | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/kernel/sleep.S b/arch/arm/kernel/sleep.S index a86a1d4f3461..93afd1005b43 100644 --- a/arch/arm/kernel/sleep.S +++ b/arch/arm/kernel/sleep.S @@ -127,6 +127,10 @@ cpu_resume_after_mmu: instr_sync #endif bl cpu_init @ restore the und/abt/irq banked regs +#if defined(CONFIG_KASAN) && defined(CONFIG_KASAN_STACK) + mov r0, sp + bl kasan_unpoison_task_stack_below +#endif mov r0, #0 @ return zero on success ldmfd sp!, {r4 - r11, pc} ENDPROC(cpu_resume_after_mmu) -- 2.18.0