Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1103784pxa; Thu, 20 Aug 2020 02:33:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYg8p8RNfqL8qNrcVUhkuAthcvGWxsjnHmjCFlN57rHEALBXT7QMYKmFG7BJF/lJ4n0oXX X-Received: by 2002:a50:fd19:: with SMTP id i25mr2065113eds.101.1597916018319; Thu, 20 Aug 2020 02:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597916018; cv=none; d=google.com; s=arc-20160816; b=Lfj0WQ+6MLeJgBHqBYjMSgVD09u+GXN1cWvGyPP588e0Y3V4ZxAkZHzKU5FqUNAdEf mSeBYXkS44SQUm4Hb+fzgPbgbVhRheo0KiKEQgTLg1gINXbdQcNRNHR4ITBZmCZhvPQR sbo/pcYApsJvdwnZfMnaIp9vPoIvrxsLJecQtnOGG4RZlBvLVjm8Bx9zqGweiFSlcbmz 0fMhEkQo9WzplsEkH3zA8OU2zSNBV+h56EGzdueadO12Tjkg2744H1FgK4LBX1AFmW9/ fDihBi8/CLvK7KeVH7leE9fv6Yuc6Bvw3CLy9J4n1W0VdC4eE91V0NAP86a1Ndsz9dm0 4W2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=it38yg5TsIMRlxdU5FqbwQ2cqVXj6TB7z5vcuiKGwhU=; b=MPUQFMrlBk8e7l8+Mz7/ixC3DgkhjX2tl5IXT0ixruhXEG3yFojhCWkkrIfJ6bD6W3 Plf47xYICr+a1wXQ2CUaYSykanRJx29JmJ/0DLq0pj1aY9txDscD+D+1zn5dudjHGA4E PZhFr9CaAqmw59tP/7oZL9zoM1Wnftq791VURFYnbrfpZOQhfQHDh0VETQSea43wpCei tlpJLHdLmR1w5m3HlEezRAbLJLGrvYiIjxRsSaaovSxWXWTk2R1zu30NHlS5z4Wgdll9 gpXqKeeXabMCZjqsD5d1cU3+aKYegPr27TjIo6BbIAzZN93BCXhfk9Ex1M3L0cRuzEf9 or3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l6mS+z8f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ec14si939802ejb.320.2020.08.20.02.33.14; Thu, 20 Aug 2020 02:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l6mS+z8f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727993AbgHTJcq (ORCPT + 99 others); Thu, 20 Aug 2020 05:32:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:44260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728245AbgHTJcC (ORCPT ); Thu, 20 Aug 2020 05:32:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8A376208E4; Thu, 20 Aug 2020 09:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915922; bh=vxvjVRskRRfqYiS7lGjlXSeNqSaOj3GOptYFi73IQUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l6mS+z8fPHczuDofq67fRRwn+rxRGpaYkDx7RZW/3GRDCN3/OdqfMAKi+6bcv9kka 8Fq0uP6wRQp8dvZFnxqoCbkcFZrYB/T+THk78PPFrkYcgKNvWsYOsIRJMt3KEELGyE Gc2d96ggKkvhmt7LnvQ/HtWKLknd2q+8hg+6e/XU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stafford Horne , Sasha Levin Subject: [PATCH 5.8 181/232] openrisc: Fix oops caused when dumping stack Date: Thu, 20 Aug 2020 11:20:32 +0200 Message-Id: <20200820091621.571260086@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stafford Horne [ Upstream commit 57b8e277c33620e115633cdf700a260b55095460 ] When dumping a stack with 'cat /proc/#/stack' the kernel would oops. For example: # cat /proc/690/stack Unable to handle kernel access at virtual address 0x7fc60f58 Oops#: 0000 CPU #: 0 PC: c00097fc SR: 0000807f SP: d6f09b9c GPR00: 00000000 GPR01: d6f09b9c GPR02: d6f09bb8 GPR03: d6f09bc4 GPR04: 7fc60f5c GPR05: c00099b4 GPR06: 00000000 GPR07: d6f09ba3 GPR08: ffffff00 GPR09: c0009804 GPR10: d6f08000 GPR11: 00000000 GPR12: ffffe000 GPR13: dbb86000 GPR14: 00000001 GPR15: dbb86250 GPR16: 7fc60f63 GPR17: 00000f5c GPR18: d6f09bc4 GPR19: 00000000 GPR20: c00099b4 GPR21: ffffffc0 GPR22: 00000000 GPR23: 00000000 GPR24: 00000001 GPR25: 000002c6 GPR26: d78b6850 GPR27: 00000001 GPR28: 00000000 GPR29: dbb86000 GPR30: ffffffff GPR31: dbb862fc RES: 00000000 oGPR11: ffffffff Process cat (pid: 702, stackpage=d79d6000) Stack: Call trace: [<598977f2>] save_stack_trace_tsk+0x40/0x74 [<95063f0e>] stack_trace_save_tsk+0x44/0x58 [] proc_pid_stack+0xd0/0x13c [] proc_single_show+0x6c/0xf0 [] seq_read+0x1b4/0x688 [<2d6c7480>] do_iter_read+0x208/0x248 [<2182a2fb>] vfs_readv+0x64/0x90 This was caused by the stack trace code in save_stack_trace_tsk using the wrong stack pointer. It was using the user stack pointer instead of the kernel stack pointer. Fix this by using the right stack. Also for good measure we add try_get_task_stack/put_task_stack to ensure the task is not lost while we are walking it's stack. Fixes: eecac38b0423a ("openrisc: support framepointers and STACKTRACE_SUPPORT") Signed-off-by: Stafford Horne Signed-off-by: Sasha Levin --- arch/openrisc/kernel/stacktrace.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/openrisc/kernel/stacktrace.c b/arch/openrisc/kernel/stacktrace.c index 43f140a28bc72..54d38809e22cb 100644 --- a/arch/openrisc/kernel/stacktrace.c +++ b/arch/openrisc/kernel/stacktrace.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -68,12 +69,25 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) { unsigned long *sp = NULL; + if (!try_get_task_stack(tsk)) + return; + if (tsk == current) sp = (unsigned long *) &sp; - else - sp = (unsigned long *) KSTK_ESP(tsk); + else { + unsigned long ksp; + + /* Locate stack from kernel context */ + ksp = task_thread_info(tsk)->ksp; + ksp += STACK_FRAME_OVERHEAD; /* redzone */ + ksp += sizeof(struct pt_regs); + + sp = (unsigned long *) ksp; + } unwind_stack(trace, sp, save_stack_address_nosched); + + put_task_stack(tsk); } EXPORT_SYMBOL_GPL(save_stack_trace_tsk); -- 2.25.1