From patchwork Sat Jan 21 09:57:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 46798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp654373wrn; Sat, 21 Jan 2023 02:03:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXtFFLwgHBTzOLMKzmEknsmtfSHPb1jVRTMYOZ/C5Ej+yTllZ5h/4IP1VHoE1ad/mS7pvAOl X-Received: by 2002:a17:90a:45:b0:22b:b888:c525 with SMTP id 5-20020a17090a004500b0022bb888c525mr4223740pjb.43.1674295410909; Sat, 21 Jan 2023 02:03:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674295410; cv=none; d=google.com; s=arc-20160816; b=zVFmrYerqDv0qIX+2qUGKCeHdXTIhksxsodIbdA3qm4ZyVcwOaY6J3KdrCDQrW+d2k HOLio0p/TmHdvQ89/orSmlyivw+f2Um1V/bxEmAEMERlZM/x0mncHtA5BcdquR+dADk7 4w8IzXBzwp9EGAlzuIbmbkl+w05IkkDpJ4GGZOhdGBUo2yq0og6zIOZZo9OChCY3ARDn A9rJAZEaW3ggU73/e108SG8QeUauizFPPWCzzSd5n+AwHpHU8IE8raT4nhWqFGN/LP9b QrRy3ewiMdZ2xCHhiMKfIrZDmFepeNiDRqA1iQORYF7YFIZDU+/YQHTmkQX2rb0GV4m1 c8hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=pmtBArXGsLKsmisCNbGh0SET3ImTh+pYPr5K7kZMwHY=; b=yuCBVu9f2bkxkOz2Jy1ZvB1ZHX4uL4ooXLQa87LF6LqusoVebZ/7QZehR3BIfDD81Z AUO7BtuYE3YkxJUa+KeE2C6CgIK/F36yCT8j2wxheYos3Of1k0JGqZQiyCsWnCKT4hye 3/MZJdGKX5rVAdzYLS4aZb6oemSQJ9fBYi+HySfZD17g4ZslBJQvZ4CiiB3zRP9B92+Y zrlps5DrF2Qq3F0iYD7kPWtSV6uchGdu/uapijrUQ7BQm+wgeJBFYYwAw3OEDnK2UAXC uX2EwxYSgbaxFcqTjHoBrO4u2XdkXnns+HrkopwslCIbcr1v5VmTFD77qsUihLZN/dXf oK+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Hg/rIklR"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020a631d09000000b004c5936dd6e1si26400270pgd.201.2023.01.21.02.03.16; Sat, 21 Jan 2023 02:03:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Hg/rIklR"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229587AbjAUJ53 (ORCPT + 99 others); Sat, 21 Jan 2023 04:57:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjAUJ51 (ORCPT ); Sat, 21 Jan 2023 04:57:27 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59EE81353B; Sat, 21 Jan 2023 01:57:26 -0800 (PST) Date: Sat, 21 Jan 2023 09:57:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1674295045; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pmtBArXGsLKsmisCNbGh0SET3ImTh+pYPr5K7kZMwHY=; b=Hg/rIklRGW36JdCrETInvtXNarbgoLaY/lOyUy6Ak93NEddtHldMfBhO6RcB10IA66ylqH 0awaLLvDoonsItIP7g55GJ0J9tptABoqG1T4t2xPBh2owNGBpdMtjniBP0KGR0MlkZuKRm cFcf3dqM5OEqXNFiS/bKZbrekTRhnWCJt7cSdSLX7AzM2/dJ+FIf8kCq8sZcUuYCWeTDoh dytmtbGeGmRN60lEGQeiO+G2YqHSNJO47oe1NtgIikXy8Sd64rZJLCOo9lV9NhbnmRL++L FxXPSSqr5b3KQOkgvGHoLybtLU7Rou6yRDqgbaThdPmU3hQTfa0w/gDpGMqlOw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1674295045; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pmtBArXGsLKsmisCNbGh0SET3ImTh+pYPr5K7kZMwHY=; b=4KDZn+IABRzw2ZpOJRb75NFBCHriMBZyXnDEBktL1lRqedAeqHcvhKEwXBD7lVM+Z4f2Up l8GMnzHuTSQ/ufBA== From: "tip-bot2 for Michal Kubecek" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Check that module init/exit function is an indirect call target Cc: Michal Kubecek , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230118105215.B9DA960514@lion.mk-sys.cz> References: <20230118105215.B9DA960514@lion.mk-sys.cz> MIME-Version: 1.0 Message-ID: <167429504442.4906.8670860752531771829.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755625984588975182?= X-GMAIL-MSGID: =?utf-8?q?1755625984588975182?= The following commit has been merged into the objtool/core branch of tip: Commit-ID: 03d7a1053cf72372be22b43faada5bca12ff183d Gitweb: https://git.kernel.org/tip/03d7a1053cf72372be22b43faada5bca12ff183d Author: Michal Kubecek AuthorDate: Wed, 18 Jan 2023 11:52:15 +01:00 Committer: Peter Zijlstra CommitterDate: Sat, 21 Jan 2023 10:50:18 +01:00 objtool: Check that module init/exit function is an indirect call target Some out-of-tree modules still do not use module_init() / module_exit() macros and simply create functions with magic names init_module() and cleanup_module() instead. As a result, these functions are not recognized as indirect call targets by objtool and such module fails to load into an IBT enabled kernel. This old way is not even documented any more but it is cleaner to issue a warning than to let the module fail on load without obvious reason. Signed-off-by: Michal Kubecek Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20230118105215.B9DA960514@lion.mk-sys.cz --- tools/objtool/Documentation/objtool.txt | 8 ++++++++ tools/objtool/check.c | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Documentation/objtool.txt index 8a67190..8e53fc6 100644 --- a/tools/objtool/Documentation/objtool.txt +++ b/tools/objtool/Documentation/objtool.txt @@ -410,6 +410,14 @@ the objtool maintainers. can remove this warning by putting the ANNOTATE_INTRA_FUNCTION_CALL directive right before the call. +12. file.o: warning: func(): not an indirect call target + + This means that objtool is running with --ibt and a function expected + to be an indirect call target is not. In particular, this happens for + init_module() or cleanup_module() if a module relies on these special + names and does not use module_init() / module_exit() macros to create + them. + If the error doesn't seem to make sense, it could be a bug in objtool. Feel free to ask the objtool maintainer for help. diff --git a/tools/objtool/check.c b/tools/objtool/check.c index cab1a16..7c40bd5 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -847,8 +847,15 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file) list_for_each_entry(insn, &file->endbr_list, call_node) { int *site = (int *)sec->data->d_buf + idx; + struct symbol *sym = insn->sym; *site = 0; + if (opts.module && sym && sym->type == STT_FUNC && + insn->offset == sym->offset && + (!strcmp(sym->name, "init_module") || + !strcmp(sym->name, "cleanup_module"))) + WARN("%s(): not an indirect call target", sym->name); + if (elf_add_reloc_to_insn(file->elf, sec, idx * sizeof(int), R_X86_64_PC32,