Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2656916pxa; Mon, 17 Aug 2020 15:42:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9tInUuxu+0XkxYYqMCV4Sp4w/Js3LT44rXtQ7M2PG+Q0Bg5DKZmtSr6Td5/PdjhEkAag9 X-Received: by 2002:a17:906:549:: with SMTP id k9mr16983875eja.104.1597704150949; Mon, 17 Aug 2020 15:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704150; cv=none; d=google.com; s=arc-20160816; b=JeZJnPKbg5D/IYfGAvr2QC7yxPOByAXsZegJCIxzMTWBxR3Ebugv8XEQmFrFHt8Vig NXGvBUyC82XNpChUnxHi9eIjcHimB7fO+za/eUhO/rvY3gfFFbNkNMC8bA1wkYlL4l5m eGB3PayU0R5Kd1phSdXoqHlt1nrEEM0VIAtiqNXURDpo4ClJ+mq4xWnXRigXakZed+zx Ty18a0boQO/P1VdPKkobLYgApOov06nJA/PJTaJp4Omfk0aI3w1fGD1jL1sNPFbUk3Zt +8HGTOAl1wTBAT4Mp7KK0G+/q+qBibeBmMrqjbePKNbX9M859XUeOhdwgjxoqkjQynCF Pt+w== 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=u99PJbTkwFU3oqlKnhub85ZCya6WJRXI62PofEXlmSVruAxgS5dQQ3SzLNGXT5/LAD TowAsnVCckQVwo3WTdEIjCoTqtQ3/Hn+n0J/G+qnNCcyoqhGUbInpNryfRl0AYoaEtxo ycqra47EmJGqCPN3W6yPHS5i16vnd6XdByFYe3SazNIA72sdRVGnsET8kLCXGRhf9xx4 d9ZV7tqusEhTgoHvhX1cZiZsataqaTWjrzc18ztxQKbFdVT+VWiD83CRlYzhrv+yRA9X /Fc3lKOUNkEWJJSjqz3gs61wJXpbpPu5clHg/ShMtxW4O3x/eTt0wvIFGjauFLfhiUva 1liA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pQZlvg6g; 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 o2si11541030ejm.676.2020.08.17.15.42.07; Mon, 17 Aug 2020 15:42:30 -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=pQZlvg6g; 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 S2391084AbgHQSjJ (ORCPT + 99 others); Mon, 17 Aug 2020 14:39:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:45932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388139AbgHQP6f (ORCPT ); Mon, 17 Aug 2020 11:58:35 -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 359CE20760; Mon, 17 Aug 2020 15:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679914; bh=oiYqFNOTIqWznWy5oZ7YjAKLAwxOQpK6HJg4N1XZrkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pQZlvg6gC4wYdGQTb6GRrQm+8TSNJZIOkyeaU+f4enT6aim4qeUpjlOQyzvmXtL9b 1TpIofOYvbK/Ar6XNWS+kLnm+oGh8w7TXjuL2hPZNBmV5f24olzJt3eJdjJigzGkdr jnfiyDnwhKdm9V98AStI0pkuYIOy+o7arZAC0H5w= 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.7 377/393] ARM: 8992/1: Fix unwind_frame for clang-built kernels Date: Mon, 17 Aug 2020 17:17:07 +0200 Message-Id: <20200817143837.895355844@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@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; }