Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6145060iog; Thu, 23 Jun 2022 12:16:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1slONu7g/gWPquU/b4G84lu0PY/9Na8araY1FgceBIz43T603BSWmoFvFSnCEmGqxhrdb59 X-Received: by 2002:a17:902:ea02:b0:16a:4b1d:71d9 with SMTP id s2-20020a170902ea0200b0016a4b1d71d9mr8945029plg.52.1656011793271; Thu, 23 Jun 2022 12:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011793; cv=none; d=google.com; s=arc-20160816; b=DkfAOGqh0WSIJG5LJiyYeZJf4dAtmqeB5+0RCqSHzHABT6TkKn0krClsyZpBccb8/L i7gEvA8SYISVmwi+gMD68zdpPTtHWF5yCZUzCsnTJVFCNbLmnW8AN6e7nDxsGyl6jo9K u0wdTPtgdGpBvd2J5qmqiFCpfS/J9if+DRXcD4am3zGTln2O4IulwOKL1tBj9D+xBiRy YXlR9wqi46omr/ZIETzXtzYCZn7ht+kQ+GdLHAxzR5Dl/0Z6Og4Jf7Z67s523F3Q4eo6 rnoasLdLkyIt6yNNdkDtdV+9oD839Fh8u/C5f7QJin9tPvc//7WcBipk5XHKuUxHH6zA bUbg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0AUhygJp/Z6tXTPKuWhgP8/GVTx59TFzVkwn4Zcj6M0=; b=kj7L1RG3SrxaSsPLFqOAzSWVrBGmDUQnXgbzTbldFXFOZuMaa/2cbYwVwebr4mh6yV agEPAzsYpeUQg5ahrLVgNY5pGdDGIIGrn/xkvbBH8InCwDXKtHPGDRFgL7GALFGxj3IH hxL6SiEfa/6O5huEc86XDbN4c+zUYsxLU7dbqVbljyCtni/fxsJwhxB4YDYoLSTZzjow b79abWfHwAKNw2TyEJo7h5BLbQcx4GcNcUYpMiCDuZEWKnvKXb9nOJVJlLuBDujUKSNW VpQp3mODa+DirAsXMuRBydo2fvYqwDeie/5Zwl0UAKgUcqqZCBAwBl4e2mQ02xb2bc0j rEbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1ZLCeOg4; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 25-20020a631159000000b003fbcd6ecc16si7653pgr.18.2022.06.23.12.16.21; Thu, 23 Jun 2022 12:16:33 -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=@linuxfoundation.org header.s=korg header.b=1ZLCeOg4; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236605AbiFWSPK (ORCPT + 99 others); Thu, 23 Jun 2022 14:15:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236600AbiFWSOs (ORCPT ); Thu, 23 Jun 2022 14:14:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB60D9B77D; Thu, 23 Jun 2022 10:21:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6354261E0D; Thu, 23 Jun 2022 17:21:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02D8EC341C5; Thu, 23 Jun 2022 17:21:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004881; bh=R/DU5ussio9VSKRaz4p16oSabeAx7muJAL9aw2UUGzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1ZLCeOg4gPZf1EYXgjUeuk/Dc6uWQZFyXxhXT2o61+VctTCDRJ2KEs+0AVjpWt0jx 2fZ7/lsHdrsav9/m080N39cgdUfMmZCE/7wPIfsciFk9fFfPXMKpHTVKg3AsrgziWu WfpUPLKMmY3PvO1BS7hUCqmwqP5atw5c6hc0K98s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wanming Hu , He Ying , Chen Jingwen , Kees Cook , Michael Ellerman , Sasha Levin Subject: [PATCH 4.19 181/234] powerpc/kasan: Silence KASAN warnings in __get_wchan() Date: Thu, 23 Jun 2022 18:44:08 +0200 Message-Id: <20220623164348.172530284@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: He Ying [ Upstream commit a1b29ba2f2c171b9bea73be993bfdf0a62d37d15 ] The following KASAN warning was reported in our kernel. BUG: KASAN: stack-out-of-bounds in get_wchan+0x188/0x250 Read of size 4 at addr d216f958 by task ps/14437 CPU: 3 PID: 14437 Comm: ps Tainted: G O 5.10.0 #1 Call Trace: [daa63858] [c0654348] dump_stack+0x9c/0xe4 (unreliable) [daa63888] [c035cf0c] print_address_description.constprop.3+0x8c/0x570 [daa63908] [c035d6bc] kasan_report+0x1ac/0x218 [daa63948] [c00496e8] get_wchan+0x188/0x250 [daa63978] [c0461ec8] do_task_stat+0xce8/0xe60 [daa63b98] [c0455ac8] proc_single_show+0x98/0x170 [daa63bc8] [c03cab8c] seq_read_iter+0x1ec/0x900 [daa63c38] [c03cb47c] seq_read+0x1dc/0x290 [daa63d68] [c037fc94] vfs_read+0x164/0x510 [daa63ea8] [c03808e4] ksys_read+0x144/0x1d0 [daa63f38] [c005b1dc] ret_from_syscall+0x0/0x38 --- interrupt: c00 at 0x8fa8f4 LR = 0x8fa8cc The buggy address belongs to the page: page:98ebcdd2 refcount:0 mapcount:0 mapping:00000000 index:0x2 pfn:0x1216f flags: 0x0() raw: 00000000 00000000 01010122 00000000 00000002 00000000 ffffffff 00000000 raw: 00000000 page dumped because: kasan: bad access detected Memory state around the buggy address: d216f800: 00 00 00 00 00 f1 f1 f1 f1 00 00 00 00 00 00 00 d216f880: f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >d216f900: 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 ^ d216f980: f2 f2 f2 f2 f2 f2 f2 00 00 00 00 00 00 00 00 00 d216fa00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 After looking into this issue, I find the buggy address belongs to the task stack region. It seems KASAN has something wrong. I look into the code of __get_wchan in x86 architecture and find the same issue has been resolved by the commit f7d27c35ddff ("x86/mm, kasan: Silence KASAN warnings in get_wchan()"). The solution could be applied to powerpc architecture too. As Andrey Ryabinin said, get_wchan() is racy by design, it may access volatile stack of running task, thus it may access redzone in a stack frame and cause KASAN to warn about this. Use READ_ONCE_NOCHECK() to silence these warnings. Reported-by: Wanming Hu Signed-off-by: He Ying Signed-off-by: Chen Jingwen Reviewed-by: Kees Cook Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20220121014418.155675-1-heying24@huawei.com Signed-off-by: Sasha Levin --- arch/powerpc/kernel/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 02b69a68139c..56c33285b1df 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -2017,12 +2017,12 @@ unsigned long get_wchan(struct task_struct *p) return 0; do { - sp = *(unsigned long *)sp; + sp = READ_ONCE_NOCHECK(*(unsigned long *)sp); if (!validate_sp(sp, p, STACK_FRAME_OVERHEAD) || p->state == TASK_RUNNING) return 0; if (count > 0) { - ip = ((unsigned long *)sp)[STACK_FRAME_LR_SAVE]; + ip = READ_ONCE_NOCHECK(((unsigned long *)sp)[STACK_FRAME_LR_SAVE]); if (!in_sched_functions(ip)) return ip; } -- 2.35.1