From patchwork Wed Jul 12 22:33:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 107537 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1411864qge; Wed, 12 Jul 2017 15:34:33 -0700 (PDT) X-Received: by 10.99.45.193 with SMTP id t184mr6205151pgt.209.1499898873580; Wed, 12 Jul 2017 15:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499898873; cv=none; d=google.com; s=arc-20160816; b=AzNG6lEDRvAixwmEE9oxbbNWyA7H7b1Hoy9iwQJXx284/wo/Us8k9u+yP6pCM54b7w hgDayULWs8/6PBP4MhmG2AVWcHZQrqLNbo4mfFKTaqWxrknrNfw9sndjBQHu1F/FCDU2 bbI5Tc+KnyyuBbub4rL2rHudAqwYe035rjLto6v2nyzlN9OWNc62qV6gdbbJ8UHJGLo4 ycUJtACTZo5Xrdlab3/oIo35AxHEljXkM4PptjzaPil3U54C7Mbok9zF2EXYh2nFoUIz iRf9lodrcY6B3YDj3PU3pwvHJnKalkKWMQkf3lkKW4XXSASBXJMdYEkHpNOtYDSHJAat O0cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=7EyuFeGwty1MDglq47PCyDi6zyCIg7PrwwpWMKKRfvY=; b=wJdbkW+SRZwxRxLXDQS3vDHUqVqAUR/RvfsqEo6+IdP1fS9BaOr5iueVH6hhC4HeVX PudVJdU20LySWxYfPtu4KcZIl6AEVW3pzEUMO1Kublfh3ZDgMSe7N5NMcmfXXxwCmz83 K4F+ih2z1Kj1R2QP833efkscNishIgy7EWB2/Or4J0ZJ3sZ7/laNDbgIoWVlrsecwDiL XOpTIeoh11534XOJMCZjgwNsMexeg3bKvhy/uIrxTbTBHQH86er44W6HGgfsSgq7CN9m snxQkbo33rrXDT0badzSg7vlM/XM6LJDae/nLOt2xOltVE+8XAGaS3mLvtWL8jrxUJMN DHtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si2959805plp.163.2017.07.12.15.34.33; Wed, 12 Jul 2017 15:34:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752721AbdGLWeS (ORCPT + 25 others); Wed, 12 Jul 2017 18:34:18 -0400 Received: from foss.arm.com ([217.140.101.70]:59118 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752523AbdGLWeQ (ORCPT ); Wed, 12 Jul 2017 18:34:16 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE36D164F; Wed, 12 Jul 2017 15:34:15 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0E6C23F3E1; Wed, 12 Jul 2017 15:34:13 -0700 (PDT) From: Mark Rutland To: ard.biesheuvel@linaro.org, kernel-hardening@lists.openwall.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: akashi.takahiro@linaro.org, catalin.marinas@arm.com, dave.martin@arm.com, james.morse@arm.com, labbott@fedoraproject.org, will.deacon@arm.com, keescook@chromium.org, Mark Rutland Subject: [RFC PATCH 5/6] arm64: keep track of current stack Date: Wed, 12 Jul 2017 23:33:02 +0100 Message-Id: <1499898783-25732-6-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1499898783-25732-1-git-send-email-mark.rutland@arm.com> References: <1499898783-25732-1-git-send-email-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To reliably check stack bounds, we'll need to know whether we're on a task stack, or an IRQ stack. Stash the base of the current stack in thread_info so that we have this information. Signed-off-by: Mark Rutland --- arch/arm64/include/asm/thread_info.h | 3 +++ arch/arm64/kernel/asm-offsets.c | 3 +++ arch/arm64/kernel/entry.S | 7 +++++++ arch/arm64/kernel/head.S | 6 ++++++ arch/arm64/kernel/process.c | 4 ++++ 5 files changed, 23 insertions(+) -- 1.9.1 diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h index 3684f86..ae4f44b 100644 --- a/arch/arm64/include/asm/thread_info.h +++ b/arch/arm64/include/asm/thread_info.h @@ -62,6 +62,9 @@ struct thread_info { #endif unsigned long pcp_offset; int preempt_count; /* 0 => preemptable, <0 => bug */ +#ifdef CONFIG_VMAP_STACK + unsigned long current_stack; +#endif }; #define INIT_THREAD_INFO(tsk) \ diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 17001be..10c8ffa 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -40,6 +40,9 @@ int main(void) DEFINE(TSK_TI_PREEMPT, offsetof(struct task_struct, thread_info.preempt_count)); DEFINE(TSK_TI_PCP, offsetof(struct task_struct, thread_info.pcp_offset)); DEFINE(TSK_TI_ADDR_LIMIT, offsetof(struct task_struct, thread_info.addr_limit)); +#ifdef CONFIG_VMAP_STACK + DEFINE(TSK_TI_CUR_STK, offsetof(struct task_struct, thread_info.current_stack)); +#endif #ifdef CONFIG_ARM64_SW_TTBR0_PAN DEFINE(TSK_TI_TTBR0, offsetof(struct task_struct, thread_info.ttbr0)); #endif diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 773b3fea..7c8b164 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -258,6 +258,9 @@ alternative_else_nop_endif /* switch to the irq stack */ mov sp, x26 +#ifdef CONFIG_VMAP_STACK + str x25, [tsk, #TSK_TI_CUR_STK] +#endif /* * Add a dummy stack frame, this non-standard format is fixed up @@ -275,6 +278,10 @@ alternative_else_nop_endif */ .macro irq_stack_exit mov sp, x19 +#ifdef CONFIG_VMAP_STACK + and x19, x19, #~(THREAD_SIZE - 1) + str x19, [tsk, #TSK_TI_CUR_STK] +#endif .endm /* diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index db77cac..3363846 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -325,6 +325,9 @@ __primary_switched: add sp, x4, #THREAD_SIZE adr_l x5, init_task msr tpidr_el1, x5 // Save thread_info +#ifdef CONFIG_VMAP_STACK + str x4, [x5, #TSK_TI_CUR_STK] +#endif adr_l x8, vectors // load VBAR_EL1 with virtual msr vbar_el1, x8 // vector table address @@ -616,6 +619,9 @@ __secondary_switched: mov x3, #THREAD_START_SP add sp, x1, x3 ldr x2, [x0, #CPU_BOOT_TASK] +#ifdef CONFIG_VMAP_STACK + str x1, [x2, #TSK_TI_CUR_STK] +#endif msr tpidr_el1, x2 mov x29, #0 b secondary_start_kernel diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 4212da3..5dc5797 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -294,6 +294,10 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, ptrace_hw_copy_thread(p); +#ifdef CONFIG_VMAP_STACK + p->thread_info.current_stack = (unsigned long)p->stack; +#endif + return 0; }