Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2636100pxa; Mon, 17 Aug 2020 15:05:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVgo3m7uPG7Ji8r53ucE0kVTrcF+MjDcndtYstIX7+5js5SxDrCnyQBh0slzGl+uDq3uTs X-Received: by 2002:a05:6402:22d5:: with SMTP id dm21mr16499928edb.211.1597701915040; Mon, 17 Aug 2020 15:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597701915; cv=none; d=google.com; s=arc-20160816; b=uzmksv2lMCBdTgtAduUqroug7PYojKVLkRBjdjjuPj0W6Ah2KI7WI5HapPUweM/Svu mvSw9/fIBJTTHfYQQi8OVHm52vQ09/jlFAENP9oGmwN5PdyM+p+trGGoqpe12WoOCnM1 lr95pvqVdryFuezUwc9vP+biX5I0Gb2dEcqqTnj9I0r0TPuCiDKSG6RqoIyl47bbZoDi S6M6rUC1jRxHKm2donkCPKtnP9BidEDQnx6Zc7v1q7Cu8uPk2ludDAqPX1ZYbfWU1R+X JQNIw5GsJlb5fHch/jXr0pym34uKG4l8XyR1Ki9w1/QToDnNbTIHccpG0Y6UF0SOY2sp 2kLA== 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=u9bYCV4959iYfi0C3bomkcdTTQK+HOZkMbXJEEtkp+I=; b=EggGm/e3nR7y+cejj/8e1rPlrmFe60GNm7ECK1jEhQZR8tMqOwEKHN2E8lwkuIDwkA BLvToZFC9TM2OwxyP87MdMVRL0qyuQI+bObmdVfZhcVZQ0s5ZLO0dl1cgsoHpfi4A00r 4SYVizHTYEtEzoy1EowASX07wLe3neMMcsgaqy/tSpqmvanz3sbjrW41QngxLlxxe6Wt YbjHRmP7bxVB/kv+cbjtJBOM8MeqRVS+d9Tg5DzCpvly5PaQXfOqtdWOarQc5Q784+88 cG6yfMMom1syd/YZqPq8Ep+7Fn/cgBXUviV/izXnSIsgitRkbf4Px7GwSOKHsfsFmrdl MZlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I3h5SgYj; 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 gh12si12218805ejb.75.2020.08.17.15.04.51; Mon, 17 Aug 2020 15:05:15 -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=I3h5SgYj; 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 S2387856AbgHQPwb (ORCPT + 99 others); Mon, 17 Aug 2020 11:52:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:49112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730676AbgHQPkl (ORCPT ); Mon, 17 Aug 2020 11:40:41 -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 94EBF22BEB; Mon, 17 Aug 2020 15:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678840; bh=oiYqFNOTIqWznWy5oZ7YjAKLAwxOQpK6HJg4N1XZrkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I3h5SgYjodMPr9cCbqvMpQ10cJlP115b1EU3hqejCBPjAD5we5niJfADD4czef1b/ +P9u7vH4mtB324uopY/Cp5XQmPjZVR9iXxnj3dnz1ZLdrFb8jBb3aUD6PZhwckerj0 lh7lxyxq3hR2mwBhs4AKUchPfiOr1zFDz+GZjurI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miles Chen , Nick Desaulniers , Nathan Huckleberry , Russell King Subject: [PATCH 5.8 449/464] ARM: 8992/1: Fix unwind_frame for clang-built kernels Date: Mon, 17 Aug 2020 17:16:42 +0200 Message-Id: <20200817143855.280685160@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@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: Nathan Huckleberry commit b4d5ec9b39f8b31d98f65bc5577b5d15d93795d7 upstream. Since clang does not push pc and sp in function prologues, the current implementation of unwind_frame does not work. By using the previous frame's lr/fp instead of saved pc/sp we get valid unwinds on clang-built kernels. The bounds check on next frame pointer must be changed as well since there are 8 less bytes between frames. This fixes /proc//stack. Link: https://github.com/ClangBuiltLinux/linux/issues/912 Reported-by: Miles Chen Tested-by: Miles Chen Cc: stable@vger.kernel.org Reviewed-by: Nick Desaulniers Signed-off-by: Nathan Huckleberry Signed-off-by: Russell King Signed-off-by: Greg Kroah-Hartman --- arch/arm/kernel/stacktrace.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) --- a/arch/arm/kernel/stacktrace.c +++ b/arch/arm/kernel/stacktrace.c @@ -22,6 +22,19 @@ * A simple function epilogue looks like this: * ldm sp, {fp, sp, pc} * + * When compiled with clang, pc and sp are not pushed. A simple function + * prologue looks like this when built with clang: + * + * stmdb {..., fp, lr} + * add fp, sp, #x + * sub sp, sp, #y + * + * A simple function epilogue looks like this when built with clang: + * + * sub sp, fp, #x + * ldm {..., fp, pc} + * + * * Note that with framepointer enabled, even the leaf functions have the same * prologue and epilogue, therefore we can ignore the LR value in this case. */ @@ -34,6 +47,16 @@ int notrace unwind_frame(struct stackfra low = frame->sp; high = ALIGN(low, THREAD_SIZE); +#ifdef CONFIG_CC_IS_CLANG + /* check current frame pointer is within bounds */ + if (fp < low + 4 || fp > high - 4) + return -EINVAL; + + frame->sp = frame->fp; + frame->fp = *(unsigned long *)(fp); + frame->pc = frame->lr; + frame->lr = *(unsigned long *)(fp + 4); +#else /* check current frame pointer is within bounds */ if (fp < low + 12 || fp > high - 4) return -EINVAL; @@ -42,6 +65,7 @@ int notrace unwind_frame(struct stackfra frame->fp = *(unsigned long *)(fp - 12); frame->sp = *(unsigned long *)(fp - 8); frame->pc = *(unsigned long *)(fp - 4); +#endif return 0; }