From patchwork Sat Jan 31 19:49:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 44093 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 210C72359E for ; Sat, 31 Jan 2015 19:52:41 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf13424965wgh.1 for ; Sat, 31 Jan 2015 11:52:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=qyBv1nJvmQ3zpOBgq92OCGrjL6eN0wIdfJii1yGLApg=; b=SMFy8NroIn2KW1r8KhIeuxWfFQih9+8NL/yZC+F/R98mwvQjdVMVco7pv4ahHwb2u8 IZKeb3dx8iWGmLEZ3wi+DuxFrRKILdnfvqON6X2UWntLUpCF/+DA4hgSHSjbOx3xI2tf vNN8YBJ1D6NnId1K/giL7wrFaCyDj+I5xcq9GAKRe1erUwTV/nq00lk6VswW1g9iDETi lPiLo1yFuv5QkLvoWA2AuVcTDIUOMaabqz1v66GfzKV7DevNjXOZheyLX7k3hEd5Vqb4 RcVJITWPDhtNgvO68yo8lOCIxZVfuUL8+bZosb0WDE801FqzxhwlDk3cIxqSyi08CWl8 7LDg== X-Gm-Message-State: ALoCoQmGp3oh1vaPnvk2ml7lPyOTzvSM9Hztao8HY/bHP13GWCDfsKo2u3KsqauIpb5Rz/dBMRai X-Received: by 10.112.30.131 with SMTP id s3mr1556973lbh.13.1422733960280; Sat, 31 Jan 2015 11:52:40 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.162 with SMTP id dd2ls173254lad.81.gmail; Sat, 31 Jan 2015 11:52:39 -0800 (PST) X-Received: by 10.152.23.98 with SMTP id l2mr12174893laf.46.1422733959932; Sat, 31 Jan 2015 11:52:39 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id t2si13004361lal.88.2015.01.31.11.52.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 11:52:39 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by mail-la0-f53.google.com with SMTP id gq15so30397386lab.12 for ; Sat, 31 Jan 2015 11:52:39 -0800 (PST) X-Received: by 10.112.63.134 with SMTP id g6mr8397024lbs.52.1422733959809; Sat, 31 Jan 2015 11:52:39 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp432144lbj; Sat, 31 Jan 2015 11:52:38 -0800 (PST) X-Received: by 10.70.50.41 with SMTP id z9mr18103427pdn.31.1422733953052; Sat, 31 Jan 2015 11:52:33 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id uz6si17550834pac.156.2015.01.31.11.52.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Jan 2015 11:52:33 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YHe3c-00017D-34; Sat, 31 Jan 2015 19:50:16 +0000 Received: from mail-wi0-f172.google.com ([209.85.212.172]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YHe3W-0008PM-Sq for linux-arm-kernel@lists.infradead.org; Sat, 31 Jan 2015 19:50:11 +0000 Received: by mail-wi0-f172.google.com with SMTP id h11so9334790wiw.5 for ; Sat, 31 Jan 2015 11:49:48 -0800 (PST) X-Received: by 10.194.76.73 with SMTP id i9mr26212226wjw.93.1422733788793; Sat, 31 Jan 2015 11:49:48 -0800 (PST) Received: from ards-macbook-pro.local ([197.130.213.20]) by mx.google.com with ESMTPSA id p6sm12474256wia.14.2015.01.31.11.49.42 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 11:49:47 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux@arm.linux.org.uk, nico@linaro.org, dave.martin@linaro.org Subject: [PATCH resend 1/4] ARM: handle interworking and out-of-range relocations separately Date: Sat, 31 Jan 2015 19:49:16 +0000 Message-Id: <1422733759-27236-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1422733759-27236-1-git-send-email-ard.biesheuvel@linaro.org> References: <1422733759-27236-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150131_115011_100077_74E09FBE X-CRM114-Status: GOOD ( 10.90 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.172 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Currently, interworking calls on module boundaries are not supported, and are handled by the same error handling code path as non-interworking calls whose targets are simply out of range. Before modifying the handling of those out-of-range jump and call relocations in a subsequent patch, move the handling of interworking restrictions out of it. Acked-by: Nicolas Pitre Signed-off-by: Ard Biesheuvel --- arch/arm/kernel/module.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index 6a4dffefd357..16804df4857c 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -98,14 +98,19 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, case R_ARM_PC24: case R_ARM_CALL: case R_ARM_JUMP24: + if (sym->st_value & 3) { + pr_err("%s: section %u reloc %u sym '%s': unsupported interworking call (ARM -> Thumb)\n", + module->name, relindex, i, symname); + return -ENOEXEC; + } + offset = __mem_to_opcode_arm(*(u32 *)loc); offset = (offset & 0x00ffffff) << 2; if (offset & 0x02000000) offset -= 0x04000000; offset += sym->st_value - loc; - if (offset & 3 || - offset <= (s32)0xfe000000 || + if (offset <= (s32)0xfe000000 || offset >= (s32)0x02000000) { pr_err("%s: section %u reloc %u sym '%s': relocation %u out of range (%#lx -> %#x)\n", module->name, relindex, i, symname, @@ -155,6 +160,22 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, #ifdef CONFIG_THUMB2_KERNEL case R_ARM_THM_CALL: case R_ARM_THM_JUMP24: + /* + * For function symbols, only Thumb addresses are + * allowed (no interworking). + * + * For non-function symbols, the destination + * has no specific ARM/Thumb disposition, so + * the branch is resolved under the assumption + * that interworking is not required. + */ + if (ELF32_ST_TYPE(sym->st_info) == STT_FUNC && + !(sym->st_value & 1)) { + pr_err("%s: section %u reloc %u sym '%s': unsupported interworking call (Thumb -> ARM)\n", + module->name, relindex, i, symname); + return -ENOEXEC; + } + upper = __mem_to_opcode_thumb16(*(u16 *)loc); lower = __mem_to_opcode_thumb16(*(u16 *)(loc + 2)); @@ -182,18 +203,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, offset -= 0x02000000; offset += sym->st_value - loc; - /* - * For function symbols, only Thumb addresses are - * allowed (no interworking). - * - * For non-function symbols, the destination - * has no specific ARM/Thumb disposition, so - * the branch is resolved under the assumption - * that interworking is not required. - */ - if ((ELF32_ST_TYPE(sym->st_info) == STT_FUNC && - !(offset & 1)) || - offset <= (s32)0xff000000 || + if (offset <= (s32)0xff000000 || offset >= (s32)0x01000000) { pr_err("%s: section %u reloc %u sym '%s': relocation %u out of range (%#lx -> %#x)\n", module->name, relindex, i, symname,