From patchwork Sun Apr 19 15:55:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 221016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CB6BC38A30 for ; Sun, 19 Apr 2020 15:55:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6ABAF22202 for ; Sun, 19 Apr 2020 15:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587311737; bh=AXjjzm0OAJt2Bp3VoxLeT77TO2+mdY+nGusLXaZbMbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=H/W4ur9knsEdt0DfX7yFDqMBbAZx3A89b93AQVLuZffYSRAR3jrUmleV7sRWLoXp4 FH+14ETEGwTPBn2PnFDMXH/IbGVNiO6sA6PVPTZJNezYr238GYYmNymUojnhAYSgoY iGUYwvIeHSYV/mQe/GHkoWr8P1Z9QsDN11X338T8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbgDSPzg (ORCPT ); Sun, 19 Apr 2020 11:55:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:46168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbgDSPzg (ORCPT ); Sun, 19 Apr 2020 11:55:36 -0400 Received: from localhost (unknown [213.57.247.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E2C4E21744; Sun, 19 Apr 2020 15:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587311735; bh=AXjjzm0OAJt2Bp3VoxLeT77TO2+mdY+nGusLXaZbMbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B9qZpO+eBiFSNRCmnj5JJrPgrEj+pseH3LcGKrUmk5Q6FmMx7WUOaKY6C53+ktwhw 4ris4gcbbEUYe4azOVzwuIotnS+9YgGrmo/TXSaF9wP3TCPEk9+6DZEVHwCj74T1R6 OHRS8/wGel8+Emno/5wGdsR5aVtZ3h/XWDL+kua8= From: Leon Romanovsky To: "David S. Miller" , Jakub Kicinski Cc: Leon Romanovsky , Borislav Petkov , Jessica Yu , linux-kbuild@vger.kernel.org, Masahiro Yamada , Michal Marek , netdev@vger.kernel.org Subject: [PATCH net-next v2 4/4] kernel/module: Hide vermagic header file from general use Date: Sun, 19 Apr 2020 18:55:06 +0300 Message-Id: <20200419155506.129392-1-leon@kernel.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200419141850.126507-1-leon@kernel.org> References: <20200419141850.126507-1-leon@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Leon Romanovsky VERMAGIC* definitions are not supposed to be used by the drivers, see this [1] bug report, so introduce special define to guard inclusion of this header file and define it in kernel/modules.h and in internal script that generates *.mod.c files. In-tree module build: ➜ kernel git:(vermagic) ✗ make clean ➜ kernel git:(vermagic) ✗ make M=drivers/infiniband/hw/mlx5 ➜ kernel git:(vermagic) ✗ modinfo drivers/infiniband/hw/mlx5/mlx5_ib.ko filename: /images/leonro/src/kernel/drivers/infiniband/hw/mlx5/mlx5_ib.ko <...> vermagic: 5.6.0+ SMP mod_unload modversions Out-of-tree module build: ➜ mlx5 make -C /images/leonro/src/kernel clean M=/tmp/mlx5 ➜ mlx5 make -C /images/leonro/src/kernel M=/tmp/mlx5 ➜ mlx5 modinfo /tmp/mlx5/mlx5_ib.ko filename: /tmp/mlx5/mlx5_ib.ko <...> vermagic: 5.6.0+ SMP mod_unload modversions [1] https://lore.kernel.org/lkml/20200411155623.GA22175@zn.tnic Reported-by: Borislav Petkov Acked-by: Borislav Petkov Acked-by: Jessica Yu Co-developed-by: Masahiro Yamada Signed-off-by: Masahiro Yamada Signed-off-by: Leon Romanovsky --- include/linux/vermagic.h | 5 +++++ kernel/module.c | 3 +++ scripts/mod/modpost.c | 1 + 3 files changed, 9 insertions(+) -- 2.25.2 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h index 9aced11e9000..7768d20ada39 100644 --- a/include/linux/vermagic.h +++ b/include/linux/vermagic.h @@ -1,4 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef INCLUDE_VERMAGIC +#error "This header can be included from kernel/module.c or *.mod.c only" +#endif + #include /* Simply sanity version stamp for modules. */ diff --git a/kernel/module.c b/kernel/module.c index 646f1e2330d2..8833e848b73c 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -4,6 +4,9 @@ Copyright (C) 2001 Rusty Russell, 2002, 2010 Rusty Russell IBM. */ + +#define INCLUDE_VERMAGIC + #include #include #include diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 5c3c50c5ec52..7f7d4ee7b652 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2251,6 +2251,7 @@ static void add_header(struct buffer *b, struct module *mod) * Include build-salt.h after module.h in order to * inherit the definitions. */ + buf_printf(b, "#define INCLUDE_VERMAGIC\n"); buf_printf(b, "#include \n"); buf_printf(b, "#include \n"); buf_printf(b, "#include \n");