Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp5143956pjo; Tue, 11 Feb 2020 04:50:00 -0800 (PST) X-Google-Smtp-Source: APXvYqxaAwd9egKwD61PfIDKWVfkaMekJqcFlNy51SIJXQ1bmPhA4xGTnoLEgMyIP1vmf3ARJCBD X-Received: by 2002:aca:5150:: with SMTP id f77mr2671678oib.52.1581425400187; Tue, 11 Feb 2020 04:50:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581425400; cv=none; d=google.com; s=arc-20160816; b=psVcIN/ntNtO4lpGs6oSQaZy6XVVkDsAtC36SupjEo7Lo3ppbjcPTXGvai16FLjo17 PuQ6F4WLHf7zQRlgD62MbZoLDBgZQ/e4VLcUG/4WAFIvIO31h+xCiagxRrkkcr1Noa1u fhb5krIfN6/1hWwW80w6rNHO+gxxay6au+97P6Lc7dVrr73OUXbNsLwtEHe7ZT/H9n8Q Lwp8SUXMfXe6Lg38AVGiXDfgLSklQ++zqyax7MiwuVsn2aUHPYTKDlcyXw3Z9XlTuvEa fXw5MgxPkKlSPBzbJ6TtFbIyY5QDttZm/T5+cdqTf9siPaqGRdWtLgTZ5HAwxuSWKfEY FrAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=9plbAKehKACSbq5ZDSH3nyAYOom3lI4n1ZVetrShQqc=; b=qr5WWWpIFHgsuJ/6otw1uRERf0WKZfJ74irfazONDbH44ttdI/bPXmTRyIpkqC/E0+ tlQTFExtZ7Iq2VOz2+7VawjlmlptGNztVSlrMeSDtfs8BKU7syC9GFPTal791F6OZVTY 2EavjGeoOuuqtKMgQfSHwu0R3s/YvAUbNqnhjFUMqSp1MunJ16nCW7dW3HyECXE7xl0I Ov74UNKt31W2iXQ+2ORcuBvsBCaAyO8H86LGuYaA4/bFagEyI1Sf3N1/uszLD7f74Weu thIC8DtuF5JhstLoJR/Mi6QdTdU3btHWmN5D8h5wu2jm7ZzRgos26MWAvu/Tph/AAylG 5WYA== 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 r67si1677799oie.145.2020.02.11.04.49.48; Tue, 11 Feb 2020 04:50:00 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728429AbgBKMrs (ORCPT + 99 others); Tue, 11 Feb 2020 07:47:48 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:45926 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728023AbgBKMrp (ORCPT ); Tue, 11 Feb 2020 07:47:45 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1j1Ux0-0007Wz-AS; Tue, 11 Feb 2020 13:47:38 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id C86A01C2017; Tue, 11 Feb 2020 13:47:37 +0100 (CET) Date: Tue, 11 Feb 2020 12:47:37 -0000 From: "tip-bot2 for Josh Poimboeuf" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: core/objtool] objtool: Add relocation check for alternative sections Cc: Linus Torvalds , Josh Poimboeuf , Borislav Petkov , Julien Thierry , x86 , LKML In-Reply-To: <7b90b68d093311e4e8f6b504a9e1c758fd7e0002.1581359535.git.jpoimboe@redhat.com> References: <7b90b68d093311e4e8f6b504a9e1c758fd7e0002.1581359535.git.jpoimboe@redhat.com> MIME-Version: 1.0 Message-ID: <158142525750.411.6760839149757331330.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the core/objtool branch of tip: Commit-ID: dc4197236c20e761f2007c641afd193f81a00a74 Gitweb: https://git.kernel.org/tip/dc4197236c20e761f2007c641afd193f81a00a74 Author: Josh Poimboeuf AuthorDate: Mon, 10 Feb 2020 12:32:40 -06:00 Committer: Borislav Petkov CommitterDate: Tue, 11 Feb 2020 13:39:52 +01:00 objtool: Add relocation check for alternative sections Relocations in alternative code can be dangerous, because the code is copy/pasted to the text section after relocations have been resolved, which can corrupt PC-relative addresses. However, relocations might be acceptable in some cases, depending on the architecture. For example, the x86 alternatives code manually fixes up the target addresses for PC-relative jumps and calls. So disallow relocations in alternative code, except where the x86 arch code allows it. This code may need to be tweaked for other arches when objtool gets support for them. Suggested-by: Linus Torvalds Signed-off-by: Josh Poimboeuf Signed-off-by: Borislav Petkov Reviewed-by: Julien Thierry Link: https://lkml.kernel.org/r/7b90b68d093311e4e8f6b504a9e1c758fd7e0002.1581359535.git.jpoimboe@redhat.com --- tools/objtool/check.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 9016ae1..b038de2 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -768,6 +768,27 @@ static int handle_group_alt(struct objtool_file *file, insn->ignore = orig_insn->ignore_alts; insn->func = orig_insn->func; + /* + * Since alternative replacement code is copy/pasted by the + * kernel after applying relocations, generally such code can't + * have relative-address relocation references to outside the + * .altinstr_replacement section, unless the arch's + * alternatives code can adjust the relative offsets + * accordingly. + * + * The x86 alternatives code adjusts the offsets only when it + * encounters a branch instruction at the very beginning of the + * replacement group. + */ + if ((insn->offset != special_alt->new_off || + (insn->type != INSN_CALL && !is_static_jump(insn))) && + find_rela_by_dest_range(insn->sec, insn->offset, insn->len)) { + + WARN_FUNC("unsupported relocation in alternatives section", + insn->sec, insn->offset); + return -1; + } + if (!is_static_jump(insn)) continue;