From patchwork Wed Jul 26 17:00:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9865413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 97B3F602B1 for ; Wed, 26 Jul 2017 17:01:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88C0028798 for ; Wed, 26 Jul 2017 17:01:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D3402879E; Wed, 26 Jul 2017 17:01:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id A4F1628798 for ; Wed, 26 Jul 2017 17:01:46 +0000 (UTC) Received: (qmail 30508 invoked by uid 550); 26 Jul 2017 17:01:37 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 30460 invoked from network); 26 Jul 2017 17:01:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ai5uMNSpq7iRftRnzR8BH2MaItho9E5aA4UJxZP+AJA=; b=U9I5ltxmv16h2ScZhXH/MfyH3y19xDgEvQk/2lYACwz/GaEYczECGNc0GX5cUIxI/c 5X1OOoPZ5ETL92Zlg93VSBWPzbps2WL/IlGRWPF6l4+ZQL9bkjtNz0ZkZ0rJjGXi1xJL he3yY4pE4qxk38lMrvMZST8N1WudeWz5CQIvom1TK3Fg/NSxYTqDW6Ng9HgH/O/ab0eo xzANam/QbcyCAtZkpNE9BrYmOdm8PtpJT35Qr6QBwGce3CjRrFLrorvxIvF8BfNxP9HH BHscb4uNWABsbYx9SFJpR39s/RiFVI1HBa+svpAC1ZUmCDRfQaLkbs4T82XraXr2/uSE e8yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ai5uMNSpq7iRftRnzR8BH2MaItho9E5aA4UJxZP+AJA=; b=ii02m7IguTcadskbtnmX2AVsYSh7he7wjKY4gyVWAKNdZ6+SeWdvb63pep45F8Swdp oTunBPbKSiGgUW4NxNtjeXSddklOiY/QNFqylZMxj5ksLR8U7Fg3RDCxKNcHq9Qskiu0 3d1goVTy5hB938+6LUSLNRU/jgtinyx3GEZLBMINrC+JIUnZdkbc3fmGIohf+q2Q8wD8 y5glKOBTthuh49DV/jI6ewhMIBY+bv75UTXwdJZcXX2seXjkTS8Enfmk8y00/y7J71O0 13+0tS1NyACss06GgzdlCxmMAcYHktYlEPe4oWWeTKluDGfwueyHg7dJRcPw11lIioev WwRw== X-Gm-Message-State: AIVw113+1vzpYQ7PG2A7kATirWm3esWuvWJadhPo2fJfUic34ei2srZD F6P+hPi5Uk7PUxz0 X-Received: by 10.99.96.196 with SMTP id u187mr1542351pgb.348.1501088484664; Wed, 26 Jul 2017 10:01:24 -0700 (PDT) From: Thomas Garnier To: Russell King , Kees Cook , Andy Lutomirski , Will Drewry , Thomas Garnier , Thomas Gleixner , Al Viro , Dave Martin , Catalin Marinas , Will Deacon , Pratyush Anand , Chris Metcalf , leonard.crestez@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Wed, 26 Jul 2017 10:00:50 -0700 Message-Id: <20170726170051.28328-2-thgarnie@google.com> X-Mailer: git-send-email 2.14.0.rc0.400.g1c36432dff-goog In-Reply-To: <20170726170051.28328-1-thgarnie@google.com> References: <20170726170051.28328-1-thgarnie@google.com> Subject: [kernel-hardening] [PATCH v2 2/3] arm/syscalls: Optimize address limit check X-Virus-Scanned: ClamAV using ClamSMTP Disable the generic address limit check in favor of an architecture specific optimized implementation. The generic implementation using pending work flags did not work well with ARM and alignment faults. The address limit is checked on each syscall return path to user-mode path as well as the irq user-mode return function. If the address limit was changed, a function is called to stop the kernel with an explicit message. The address limit check has to be done before any pending work because they can reset the address limit. For example the lkdtm address limit check does not work because the signal to kill the process will reset the user-mode address limit. Signed-off-by: Thomas Garnier --- arch/arm/kernel/entry-common.S | 11 +++++++++++ arch/arm/kernel/signal.c | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 0b60adf4a5d9..99c908226065 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_AEABI #include #endif @@ -48,10 +49,14 @@ ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) disable_irq_notrace @ disable interrupts + ldr r2, [tsk, #TI_ADDR_LIMIT] + cmp r2, #TASK_SIZE + blne addr_limit_check_failed ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK bne fast_work_pending + /* perform architecture specific actions before user return */ arch_ret_to_user r1, lr @@ -74,6 +79,9 @@ ret_fast_syscall: UNWIND(.cantunwind ) str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 disable_irq_notrace @ disable interrupts + ldr r2, [tsk, #TI_ADDR_LIMIT] + cmp r2, #TASK_SIZE + blne addr_limit_check_failed ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK beq no_work_pending @@ -106,6 +114,9 @@ ENTRY(ret_to_user) ret_slow_syscall: disable_irq_notrace @ disable interrupts ENTRY(ret_to_user_from_irq) + ldr r2, [tsk, #TI_ADDR_LIMIT] + cmp r2, #TASK_SIZE + blne addr_limit_check_failed ldr r1, [tsk, #TI_FLAGS] tst r1, #_TIF_WORK_MASK bne slow_work_pending diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index 5814298ef0b7..5769c15cff89 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -673,3 +673,8 @@ struct page *get_signal_page(void) return page; } + +asmlinkage void addr_limit_check_failed(void) +{ + panic("Incorrect address limit while returning to user-mode."); +}