From patchwork Sat May 13 20:44:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 93593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5964582vqo; Sat, 13 May 2023 13:50:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hTs4WsFFD/BUmMvaAIeO/goEoqbgbL29j4CJWlcNmUmQ72YwSJ1iplGzjmjL4Ku0QDxsQ X-Received: by 2002:a17:902:be03:b0:1ab:797:afbe with SMTP id r3-20020a170902be0300b001ab0797afbemr27937063pls.8.1684011012159; Sat, 13 May 2023 13:50:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684011012; cv=none; d=google.com; s=arc-20160816; b=v4dOD+Xfbiv+llVRU4u9zAWd4gtxNxHp5Lyhe3gKoAZ1xZ/USv7t/PefFHkqJKyMiM fjL1exXPXRa75or7PPM4JQJXJtZBkkEJllfFVGtS5cGJW+xK9EXhVswbpu11Y9MlTPEl kdYypiz/6lfNGTPGymZkBGNt4vfSLRfpxXV+YyWRjyNeRkf51ipKi4/PyRR8RkqQP0e6 5GObd1+N3TkRdaCMIM6fhnYC7rPPIJtEGEZIgM2sG9A7fydNvMUnbegRyyUy3MNlsBZP BXawZuwBh5s+iX4ni6iOsUVChz04FK5gMl2Xw0KSCQUGxhEevhJy6p4QvEZkmAfDh0we MP1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vY4UfwtffzZ9dzQt8zxH7jUGlfoaN19Jb9dps4lJqDY=; b=flDYgOo19ijdNWV8g7MQl1/LwCmz0Xl4yLO8bW+qBh9riROiiKBB+OIZPt2VSnCp8y IdH1qggg1ypiCddxG5V5qyTpb4lDUwwcsOFeepunToncpflIfxYBo2giso5ezMdt+P9a gJ/YYiqirqAr5kKjeGw7XdtrUUQZ67TFmQAhDHj3QWfZJnmiXPAol/gYGhiSfs7Cf9Ld 1GCwyOuBkmdxu5sRx2e0+RC/8zY/CcadotT8T2+5cSaTu5Si9tn+lYOSoNnyVHY6pWVi iQCaks50AC5bouteFzR3UsHiu8r1V8RJpCXdtf/nyLIBk1VIYDgfsrNNMjN2f2JvSnpW dlDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="G5ywJR/T"; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj10-20020a170903048a00b001a64a2b7921si11726897plb.8.2023.05.13.13.49.57; Sat, 13 May 2023 13:50:12 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b="G5ywJR/T"; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232224AbjEMUp4 (ORCPT + 99 others); Sat, 13 May 2023 16:45:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232064AbjEMUpj (ORCPT ); Sat, 13 May 2023 16:45:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B04C53C1B; Sat, 13 May 2023 13:45:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1358561560; Sat, 13 May 2023 20:45:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D4CCC433EF; Sat, 13 May 2023 20:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684010727; bh=Sr1ACpmB4VMo9mQd8LPvpsqLdM7Qav5Pbz5xK//K3hU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G5ywJR/TLYTx7IJRyDK8xhvxfOlb5zRIM724OWkQvCpWrO0wS9LfsIqddx345ZssL UR11qJ5+M1sti/0XgA8yPZIdy0caBnbhxsn6pn9AMQiUqMJq+ULMS8o8xxvls7H0hq ZIN1KOJ79nxKAnPdkZkuTxavrY0GoGtllHbvH9en5pUqVsz/7k3brxbNOxDLbWiDk9 LEVIff2wCAYT2oWWt1KgD+tYC99UoeJnkATyXwpAze5JT33NABBz2GsPWF5VYoP4C2 8ysRQrWsiS0Ed0hHEYa9x+e8vb4bwHZJ8cd67GAU287TqGfowmHuQ6kKycPV6uu7nF 4Y0psjp7htR5Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Pitre , Nicolas Schier , Masahiro Yamada Subject: [PATCH v4 07/21] modpost: squash extable_mismatch_handler() into default_mismatch_handler() Date: Sun, 14 May 2023 05:44:48 +0900 Message-Id: <20230513204502.1593923-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230513204502.1593923-1-masahiroy@kernel.org> References: <20230513204502.1593923-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1765813531367350113?= X-GMAIL-MSGID: =?utf-8?q?1765813531367350113?= Merging these two reduces several lines of code. The extable section mismatch is already distinguished by EXTABLE_TO_NON_TEXT. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 84 ++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 58 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 0bda2f22c985..49357a716519 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -881,27 +881,14 @@ enum mismatch { * targeting sections in this array (white-list). Can be empty. * * @mismatch: Type of mismatch. - * - * @handler: Specific handler to call when a match is found. If NULL, - * default_mismatch_handler() will be called. - * */ struct sectioncheck { const char *fromsec[20]; const char *bad_tosec[20]; const char *good_tosec[20]; enum mismatch mismatch; - void (*handler)(const char *modname, struct elf_info *elf, - const struct sectioncheck* const mismatch, - Elf_Rela *r, Elf_Sym *sym, const char *fromsec); - }; -static void extable_mismatch_handler(const char *modname, struct elf_info *elf, - const struct sectioncheck* const mismatch, - Elf_Rela *r, Elf_Sym *sym, - const char *fromsec); - static const struct sectioncheck sectioncheck[] = { /* Do not reference init/exit code/data from * normal code and data @@ -974,7 +961,6 @@ static const struct sectioncheck sectioncheck[] = { .bad_tosec = { ".altinstr_replacement", NULL }, .good_tosec = {ALL_TEXT_SECTIONS , NULL}, .mismatch = EXTABLE_TO_NON_TEXT, - .handler = extable_mismatch_handler, } }; @@ -1255,60 +1241,42 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, modname, tosym, tosec); break; case EXTABLE_TO_NON_TEXT: - fatal("There's a special handler for this mismatch type, we should never get here.\n"); + warn("%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n", + modname, fromsec, (long)r->r_offset, tosec, tosym); + + if (match(tosec, mismatch->bad_tosec)) + fatal("The relocation at %s+0x%lx references\n" + "section \"%s\" which is black-listed.\n" + "Something is seriously wrong and should be fixed.\n" + "You might get more information about where this is\n" + "coming from by using scripts/check_extable.sh %s\n", + fromsec, (long)r->r_offset, tosec, modname); + else if (is_executable_section(elf, get_secindex(elf, sym))) + warn("The relocation at %s+0x%lx references\n" + "section \"%s\" which is not in the list of\n" + "authorized sections. If you're adding a new section\n" + "and/or if this reference is valid, add \"%s\" to the\n" + "list of authorized sections to jump to on fault.\n" + "This can be achieved by adding \"%s\" to\n" + "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n", + fromsec, (long)r->r_offset, tosec, tosec, tosec); + else + error("%s+0x%lx references non-executable section '%s'\n", + fromsec, (long)r->r_offset, tosec); break; } } -static void extable_mismatch_handler(const char* modname, struct elf_info *elf, - const struct sectioncheck* const mismatch, - Elf_Rela* r, Elf_Sym* sym, - const char *fromsec) -{ - const char* tosec = sec_name(elf, get_secindex(elf, sym)); - Elf_Sym *tosym = find_elf_symbol(elf, r->r_addend, sym); - const char *tosym_name = sym_name(elf, tosym); - - sec_mismatch_count++; - - warn("%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n", - modname, fromsec, (long)r->r_offset, tosec, tosym_name); - - if (match(tosec, mismatch->bad_tosec)) - fatal("The relocation at %s+0x%lx references\n" - "section \"%s\" which is black-listed.\n" - "Something is seriously wrong and should be fixed.\n" - "You might get more information about where this is\n" - "coming from by using scripts/check_extable.sh %s\n", - fromsec, (long)r->r_offset, tosec, modname); - else if (is_executable_section(elf, get_secindex(elf, sym))) - warn("The relocation at %s+0x%lx references\n" - "section \"%s\" which is not in the list of\n" - "authorized sections. If you're adding a new section\n" - "and/or if this reference is valid, add \"%s\" to the\n" - "list of authorized sections to jump to on fault.\n" - "This can be achieved by adding \"%s\" to\n" - "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n", - fromsec, (long)r->r_offset, tosec, tosec, tosec); - else - error("%s+0x%lx references non-executable section '%s'\n", - fromsec, (long)r->r_offset, tosec); -} - static void check_section_mismatch(const char *modname, struct elf_info *elf, Elf_Rela *r, Elf_Sym *sym, const char *fromsec) { const char *tosec = sec_name(elf, get_secindex(elf, sym)); const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec); - if (mismatch) { - if (mismatch->handler) - mismatch->handler(modname, elf, mismatch, - r, sym, fromsec); - else - default_mismatch_handler(modname, elf, mismatch, - r, sym, fromsec); - } + if (!mismatch) + return; + + default_mismatch_handler(modname, elf, mismatch, r, sym, fromsec); } static unsigned int *reloc_location(struct elf_info *elf,