From patchwork Mon Feb 8 17:57:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 61428 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1582114lbl; Mon, 8 Feb 2016 09:59:15 -0800 (PST) X-Received: by 10.98.14.146 with SMTP id 18mr26682218pfo.35.1454954355062; Mon, 08 Feb 2016 09:59:15 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si47922021pfi.34.2016.02.08.09.59.14; Mon, 08 Feb 2016 09:59:15 -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=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932431AbcBHR7N (ORCPT + 30 others); Mon, 8 Feb 2016 12:59:13 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35600 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756228AbcBHR6C (ORCPT ); Mon, 8 Feb 2016 12:58:02 -0500 Received: by mail-wm0-f51.google.com with SMTP id c200so27480062wme.0 for ; Mon, 08 Feb 2016 09:58:01 -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=hRYsCjKZz5S+bkSVMCEPEzaaO2aoukUG3Wfzu23VHcw=; b=cOv42B9aN0DSfPY2uyWAvqoA4oY37oL3KwVutZjVOLg1S9KdnPOlIpMdScv6zXlkhD LfDZn4LygImQgqZNQkxr1CxDslz+UqauwJv2hDRJvI3BqkUYOqwNiOoRFeIgEX1z/q9+ /YPJ6gNN4Qk1unxJAjJiDgNFT/KVTlo4KYaks= 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=hRYsCjKZz5S+bkSVMCEPEzaaO2aoukUG3Wfzu23VHcw=; b=hfmEcKMiimnCDQiJzPCbOV8Xl14OUUGutorRBDcYrWoW9siZAjyUD5JaE54uBlrPbY kaQ1AzrJxdEt469I0JBCF+Gp4Clk7LBDbfQ3jrcCRCZLwPyR1y8Vec3fO127PQrfuFh7 dpm/3fYNCArcGiFRg4CCZdQAEAkz/F5lRek5H6OGMS8sFW36NHyzBUdYb7NCtcDxsClL 9oI15cqjLqnNUx+RG0XB/t4SvKmeY2wWBScBxc4h+rPZnUySles1n6oD4yyQL7WfVgbi XSH/7uWmxrKZqKJKHJQ+9A3celAkneHcYyKNQlFHg16YY/Vr+JR1mq2UpndXWYzmES9O vkIw== X-Gm-Message-State: AG10YOQXUTzwPdOu36zMiHgdSbXWoOD1De7DNCOC5ZFrNQCU9Na+DKh1Z9Ihn+Frt+bvm5pD X-Received: by 10.28.224.87 with SMTP id x84mr152904wmg.32.1454954280605; Mon, 08 Feb 2016 09:58:00 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id w17sm13664684wmw.5.2016.02.08.09.57.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Feb 2016 09:57:59 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, keescook@chromium.org, akpm@linux-foundation.org, mingo@kernel.org, hpa@zytor.com, heiko.carstens@de.ibm.com, benh@kernel.crashing.org, mpe@ellerman.id.au, mmarek@suse.cz, rusty@rustcorp.com.au, arnd@arndb.de, linux-arch@vger.kernel.org, linux@roeck-us.net Cc: Ard Biesheuvel Subject: [PATCH v5 2/3] kallsyms: don't overload absolute symbol type for percpu symbols Date: Mon, 8 Feb 2016 18:57:47 +0100 Message-Id: <1454954268-3225-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454954268-3225-1-git-send-email-ard.biesheuvel@linaro.org> References: <1454954268-3225-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 Commit c6bda7c988a5 ("kallsyms: fix percpu vars on x86-64 with relocation") overloaded the 'A' (absolute) symbol type to signify that a symbol is not subject to dynamic relocation. However, the original A type does not imply that at all, and depending on the version of the toolchain, many A type symbols are emitted that are in fact relative to the kernel text, i.e., if the kernel is relocated at runtime, these symbols should be updated as well. For instance, on sparc32, the following symbols are emitted as absolute (kindly provided by Guenter Roeck): f035a420 A _etext f03d9000 A _sdata f03de8c4 A jiffies f03f8860 A _edata f03fc000 A __init_begin f041bdc8 A __init_text_end f0423000 A __bss_start f0423000 A __init_end f044457d A __bss_stop f044457d A _end On x86_64, similar behavior can be observed: ffffffff81a00000 A __end_rodata_hpage_align ffffffff81b19000 A __vvar_page ffffffff81d3d000 A _end Even if only a couple of them pass the symbol range check that results in them to be taken into account for the final kallsyms symbol table, it is obvious that 'A' does not mean the symbol does not need to be updated at relocation time, and overloading its meaning to signify that is perhaps not a good idea. So instead, add a new percpu_absolute member to struct sym_entry, and when --absolute-percpu is in effect, use it to record symbols whose addresses should be emitted as final values rather than values that still require relocation at runtime. That way, we can drop the check against the 'A' type. Tested-by: Guenter Roeck Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Rusty Russell Signed-off-by: Ard Biesheuvel --- scripts/kallsyms.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) -- 2.5.0 diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 8fa81e84e295..d39a1eeb080e 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -34,6 +34,7 @@ struct sym_entry { unsigned int len; unsigned int start_pos; unsigned char *sym; + unsigned int percpu_absolute; }; struct addr_range { @@ -171,6 +172,8 @@ static int read_symbol(FILE *in, struct sym_entry *s) strcpy((char *)s->sym + 1, str); s->sym[0] = stype; + s->percpu_absolute = 0; + /* Record if we've found __per_cpu_start/end. */ check_symbol_range(sym, s->addr, &percpu_range, 1); @@ -325,7 +328,7 @@ static int expand_symbol(unsigned char *data, int len, char *result) static int symbol_absolute(struct sym_entry *s) { - return toupper(s->sym[0]) == 'A'; + return s->percpu_absolute; } static void write_src(void) @@ -681,8 +684,15 @@ static void make_percpus_absolute(void) unsigned int i; for (i = 0; i < table_cnt; i++) - if (symbol_in_range(&table[i], &percpu_range, 1)) + if (symbol_in_range(&table[i], &percpu_range, 1)) { + /* + * Keep the 'A' override for percpu symbols to + * ensure consistent behavior compared to older + * versions of this tool. + */ table[i].sym[0] = 'A'; + table[i].percpu_absolute = 1; + } } int main(int argc, char **argv)