From patchwork Sun Jan 3 16:05:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 59109 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp4917244lbb; Sun, 3 Jan 2016 08:08:34 -0800 (PST) X-Received: by 10.66.161.133 with SMTP id xs5mr119342942pab.70.1451837313675; Sun, 03 Jan 2016 08:08:33 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 29si27031195pfk.10.2016.01.03.08.08.33; Sun, 03 Jan 2016 08:08:33 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752044AbcACQIG (ORCPT + 29 others); Sun, 3 Jan 2016 11:08:06 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:34425 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752111AbcACQGb (ORCPT ); Sun, 3 Jan 2016 11:06:31 -0500 Received: by mail-wm0-f53.google.com with SMTP id u188so122808658wmu.1 for ; Sun, 03 Jan 2016 08:06:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DcFf1KMQAzzvVDOi6/0pCDffv9K49eVyh6xaRpf0e0I=; b=P2gi+q/hv+ldsugv/JHpz6H+HDPV41mP/knksri0MADcG8o/5+0lroSbHF1Dybdnc6 uxZ9odMLAG2vZYzFASgB0CUmA/5dgJMskoIqs6UiP05rdfemfdAbrPb/bstXvCWUApq3 rNAczM+SPZOzlXhyUbkMpKy11+m07sHXziljw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DcFf1KMQAzzvVDOi6/0pCDffv9K49eVyh6xaRpf0e0I=; b=cqd/QtxMeVbyI+s2Iu7kEXSBPLxOZqK2/BtkBaiZSD5IF/CS1aK7xtrI6Am7G9aOgb a1o5PlmxpXlG58O6nawtYXFuvimNUGZ/Pm6inSi1J38HcqA3UFOTeQa7Aiq1CSNk5iDQ ZGFhA1whKHJRzd8ghizDDQQnW9aPMYb/Kcf4JW8JpKki3UYma6gMMHlVAvpq2I2zSpER 7wUaPCCMsdQV6mb2cWRA7qGD6Q38pOpVYaMHSjXijjebJHXI1kvuXf3fQoVP6xSHfNlI 0cdw8vm+AY+NZ7/tzou22dGrpwPAFq35OGi7XjkHG7uXuexG3x79U6Z1wNHu+aTba0Dh nwdg== X-Gm-Message-State: ALoCoQnf3sF6ykinvPNGErv//ZEIJrnXpeC0QpjxVT4TJS+FmE0q6mKsSgPaWHPFu9MBx6t4Twppr53lNoyhTAD4MJzAybxXQg== X-Received: by 10.28.139.205 with SMTP id n196mr40235978wmd.0.1451837190003; Sun, 03 Jan 2016 08:06:30 -0800 (PST) Received: from localhost.localdomain (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by smtp.gmail.com with ESMTPSA id i196sm62524801wmf.23.2016.01.03.08.06.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Jan 2016 08:06:29 -0800 (PST) From: Ard Biesheuvel To: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-s390@vger.kernel.org, x86@kernel.org, hpa@zytor.com, mingo@redhat.com, heiko.carstens@de.ibm.com, schwidefsky@de.ibm.com, mattst88@gmail.com, ink@jurassic.park.msu.ru, rth@twiddle.net, tony.luck@intel.com, fenghua.yu@intel.com, catalin.marinas@arm.com, will.deacon@arm.com, arnd@arndb.de, akpm@linux-foundation.org Cc: mark.rutland@arm.com, marc.zyngier@arm.com, Ard Biesheuvel Subject: [PATCH 6/6] arm64: switch to relative exception tables Date: Sun, 3 Jan 2016 17:05:57 +0100 Message-Id: <1451837157-447-7-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451837157-447-1-git-send-email-ard.biesheuvel@linaro.org> References: <1451837157-447-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of using absolute addresses for both the exception location and the fixup, use offsets relative to the exception table entry values. Not only does this cut the size of the exception table in half, it is also a prerequisite for KASLR, since absolute exception table entries are subject to dynamic relocation, which is incompatible with the sorting of the exception table that occurs at build time. Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Ard Biesheuvel --- Note that this patch supersedes the version I sent as part of the series that implements KASLR for arm64: http://thread.gmane.org/gmane.linux.kernel/2116531 arch/arm64/include/asm/assembler.h | 2 +- arch/arm64/include/asm/futex.h | 4 ++-- arch/arm64/include/asm/uaccess.h | 18 ++++++++++-------- arch/arm64/kernel/armv8_deprecated.c | 4 ++-- arch/arm64/mm/extable.c | 2 +- scripts/sortextable.c | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 12eff928ef8b..8094d50f05bc 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -98,7 +98,7 @@ 9999: x; \ .section __ex_table,"a"; \ .align 3; \ - .quad 9999b,l; \ + .long (9999b - .), (l - .); \ .previous /* diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h index 007a69fc4f40..35e73e255ad3 100644 --- a/arch/arm64/include/asm/futex.h +++ b/arch/arm64/include/asm/futex.h @@ -44,7 +44,7 @@ " .popsection\n" \ " .pushsection __ex_table,\"a\"\n" \ " .align 3\n" \ -" .quad 1b, 4b, 2b, 4b\n" \ +" .long (1b - .), (4b - .), (2b - .), (4b - .)\n" \ " .popsection\n" \ ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) \ @@ -135,7 +135,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, " .popsection\n" " .pushsection __ex_table,\"a\"\n" " .align 3\n" -" .quad 1b, 4b, 2b, 4b\n" +" .long (1b - .), (4b - .), (2b - .), (4b - .)\n" " .popsection\n" : "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp) : "r" (oldval), "r" (newval), "Ir" (-EFAULT) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index b2ede967fe7d..ab627e6c06c9 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -36,11 +36,11 @@ #define VERIFY_WRITE 1 /* - * The exception table consists of pairs of addresses: the first is the - * address of an instruction that is allowed to fault, and the second is - * the address at which the program should continue. No registers are - * modified, so it is entirely up to the continuation code to figure out - * what to do. + * The exception table consists of pairs of relative offsets: the first + * is the relative offset to an instruction that is allowed to fault, + * and the second is the relative offset at which the program should + * continue. No registers are modified, so it is entirely up to the + * continuation code to figure out what to do. * * All the routines below use bits of fixup code that are out of line * with the main instruction path. This means when everything is well, @@ -50,9 +50,11 @@ struct exception_table_entry { - unsigned long insn, fixup; + int insn, fixup; }; +#define ARCH_HAS_RELATIVE_EXTABLE + extern int fixup_exception(struct pt_regs *regs); #define KERNEL_DS (-1UL) @@ -125,7 +127,7 @@ static inline void set_fs(mm_segment_t fs) " .previous\n" \ " .section __ex_table,\"a\"\n" \ " .align 3\n" \ - " .quad 1b, 3b\n" \ + " .long (1b - .), (3b - .)\n" \ " .previous" \ : "+r" (err), "=&r" (x) \ : "r" (addr), "i" (-EFAULT)) @@ -192,7 +194,7 @@ do { \ " .previous\n" \ " .section __ex_table,\"a\"\n" \ " .align 3\n" \ - " .quad 1b, 3b\n" \ + " .long (1b - .), (3b - .)\n" \ " .previous" \ : "+r" (err) \ : "r" (x), "r" (addr), "i" (-EFAULT)) diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c index 937f5e58a4d3..8f21b1363387 100644 --- a/arch/arm64/kernel/armv8_deprecated.c +++ b/arch/arm64/kernel/armv8_deprecated.c @@ -299,8 +299,8 @@ static void register_insn_emulation_sysctl(struct ctl_table *table) " .popsection" \ " .pushsection __ex_table,\"a\"\n" \ " .align 3\n" \ - " .quad 0b, 4b\n" \ - " .quad 1b, 4b\n" \ + " .long (0b - .), (4b - .)\n" \ + " .long (1b - .), (4b - .)\n" \ " .popsection\n" \ ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) \ diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c index 79444279ba8c..81acd4706878 100644 --- a/arch/arm64/mm/extable.c +++ b/arch/arm64/mm/extable.c @@ -11,7 +11,7 @@ int fixup_exception(struct pt_regs *regs) fixup = search_exception_tables(instruction_pointer(regs)); if (fixup) - regs->pc = fixup->fixup; + regs->pc = (unsigned long)&fixup->fixup + fixup->fixup; return fixup != NULL; } diff --git a/scripts/sortextable.c b/scripts/sortextable.c index c2423d913b46..af247c70fb66 100644 --- a/scripts/sortextable.c +++ b/scripts/sortextable.c @@ -282,12 +282,12 @@ do_file(char const *const fname) case EM_386: case EM_X86_64: case EM_S390: + case EM_AARCH64: custom_sort = sort_relative_table; break; case EM_ARCOMPACT: case EM_ARCV2: case EM_ARM: - case EM_AARCH64: case EM_MICROBLAZE: case EM_MIPS: case EM_XTENSA: