From patchwork Thu May 5 03:52:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12839037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E98D2C433EF for ; Thu, 5 May 2022 03:53:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241303AbiEED5H (ORCPT ); Wed, 4 May 2022 23:57:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbiEED5G (ORCPT ); Wed, 4 May 2022 23:57:06 -0400 X-Greylist: delayed 29375 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 04 May 2022 20:53:27 PDT Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 657F863A2; Wed, 4 May 2022 20:53:27 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-08.nifty.com with ESMTP id 2453qiRF021346; Thu, 5 May 2022 12:52:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com 2453qiRF021346 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1651722765; bh=Xp/Il9izgFFUGGxMDiJyqVoFfLzqSe5l32yd/T521y4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VY6oS+YVRhjSqtwoy042ugda75ysUAUIojehflDfnYTlp0JXZa0/elFOosRxjN67y JB6wRXlIL+0hEDv6YYMKMHwOFokVvVyV1HCmyvZG2wfz88aw6fNnFR6bHU1cgndSjK FOX57Bxocv6ly6biNS23x+aHpiucHsoBUqjqzKb37LTSf97G4CpZ7nJ+qTF7G4diCO uBEy1qIfBSutBrP70b58TsC5abSyO8ZEM1ZyCLx687ET9MztvtdnA7lDENDmAcQWxV uTJW+1HnxjlmM3hY53g0j96oH3R0NV5dL+q3Btg4qnTiqd7GlYyAr06XqJoG4xGkan QPzClrr4Kkqdg== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: Luis Chamberlain , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Masahiro Yamada Subject: [PATCH v2 1/3] module: do not pass opaque pointer for symbol search Date: Thu, 5 May 2022 12:52:10 +0900 Message-Id: <20220505035212.1130858-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505035212.1130858-1-masahiroy@kernel.org> References: <20220505035212.1130858-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: There is no need to use an opaque pointer for check_exported_symbol() or find_exported_symbol_in_section. Pass (struct find_symbol_arg *) explicitly. Signed-off-by: Masahiro Yamada --- kernel/module/main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index fe44d46c378b..28ece86d99dc 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -244,11 +244,9 @@ static __maybe_unused void *any_section_objs(const struct load_info *info, #endif static bool check_exported_symbol(const struct symsearch *syms, - struct module *owner, - unsigned int symnum, void *data) + struct module *owner, unsigned int symnum, + struct find_symbol_arg *fsa) { - struct find_symbol_arg *fsa = data; - if (!fsa->gplok && syms->license == GPL_ONLY) return false; fsa->owner = owner; @@ -285,16 +283,15 @@ int cmp_name(const void *name, const void *sym) static bool find_exported_symbol_in_section(const struct symsearch *syms, struct module *owner, - void *data) + struct find_symbol_arg *fsa) { - struct find_symbol_arg *fsa = data; struct kernel_symbol *sym; sym = bsearch(fsa->name, syms->start, syms->stop - syms->start, sizeof(struct kernel_symbol), cmp_name); if (sym != NULL && check_exported_symbol(syms, owner, - sym - syms->start, data)) + sym - syms->start, fsa)) return true; return false; From patchwork Thu May 5 03:52:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12839040 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A690C433FE for ; Thu, 5 May 2022 03:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241949AbiEED5K (ORCPT ); Wed, 4 May 2022 23:57:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232757AbiEED5H (ORCPT ); Wed, 4 May 2022 23:57:07 -0400 Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BEDFB7C0; Wed, 4 May 2022 20:53:27 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-08.nifty.com with ESMTP id 2453qiRG021346; Thu, 5 May 2022 12:52:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com 2453qiRG021346 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1651722766; bh=Ucyg107RFa+06vZD++CcuYxSjjefwnfQNS/0NyIzQIg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DDIoxuNtXpepdbpzi5Z7MHUW865iucz9GQYpLQS2CZ1upBYd/EGLOdXL+IZFspXZY 5kJSySkgstLpH/LcspuJwA6nx6LmAZp8yTg6HOpnEAiC1s0UYZGXQNrAQN26PvGXwc iu/jwS2BoJfA4NDck0geugmn5V9QOxjCFQsaagT4pVtoSd3RuiI27IlmOE8HjR6VYP fY8+742PWFg2VXeDiy12jFfYXUjmpnSfv9+5vwwBDV7nFvD56e6ZU5SK4PEDTvBvyL AvInFzB82DrGPAj03o99b1g7vssaV4jObEkFIpxnwi1CUf2QwbJm/NNKX47w5qvl8q gsoT9TBwurGog== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: Luis Chamberlain , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Masahiro Yamada Subject: [PATCH v2 2/3] module: do not binary-search in __ksymtab_gpl if fsa->gplok is false Date: Thu, 5 May 2022 12:52:11 +0900 Message-Id: <20220505035212.1130858-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505035212.1130858-1-masahiroy@kernel.org> References: <20220505035212.1130858-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: Currently, !fsa->gplok && syms->license == GPL_ONLY) is checked after bsearch() succeeds. It is meaningless to do the binary search in the GPL symbol table when fsa->gplok is false because we know find_exported_symbol_in_section() will fail anyway. This check should be done before bsearch(). Signed-off-by: Masahiro Yamada --- kernel/module/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 28ece86d99dc..22a860d42c16 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -247,8 +247,6 @@ static bool check_exported_symbol(const struct symsearch *syms, struct module *owner, unsigned int symnum, struct find_symbol_arg *fsa) { - if (!fsa->gplok && syms->license == GPL_ONLY) - return false; fsa->owner = owner; fsa->crc = symversion(syms->crcs, symnum); fsa->sym = &syms->start[symnum]; @@ -287,6 +285,9 @@ static bool find_exported_symbol_in_section(const struct symsearch *syms, { struct kernel_symbol *sym; + if (!fsa->gplok && syms->license == GPL_ONLY) + return false; + sym = bsearch(fsa->name, syms->start, syms->stop - syms->start, sizeof(struct kernel_symbol), cmp_name); From patchwork Thu May 5 03:52:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12839038 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FA61C433FE for ; Thu, 5 May 2022 03:53:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241847AbiEED5I (ORCPT ); Wed, 4 May 2022 23:57:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234446AbiEED5H (ORCPT ); Wed, 4 May 2022 23:57:07 -0400 Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A435614027; Wed, 4 May 2022 20:53:27 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-08.nifty.com with ESMTP id 2453qiRH021346; Thu, 5 May 2022 12:52:46 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com 2453qiRH021346 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1651722766; bh=24jtj+UYB0xv342M0DAJe77XkxPBb78c2WJx0IEENiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dIbXKrf05r1Y4YxHOmc4jtJgcvH4V+h2lx5ydXY+efkZW+vFlpmpz0Pa2wesNvy9C G3kHE50VhBIPpkY3VpBTrH1/UaxIW8MBAuWDETlbm8RDSnQNFYwsYcQ0xr6qVRvCv/ 3kK0DC4XvlpHbFuGyAtj7JGMWeWv4I8wbfax9SFg7Z/TQVS772fWmv2wou9U24CWrn buhad7efVW3TKU0u/DyZiGmuPsnv9lVpA6puXgyZXQID+jI9DFB4p9jSJRUufangcN wVzllHHxmylVOvz+smzYoY4/z3S493lVMisRiUiFY501rYnVyzJoPoki9Lznfjt+Vd NsWhkgufBfuwA== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: Luis Chamberlain , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Masahiro Yamada Subject: [PATCH v2 3/3] module: merge check_exported_symbol() into find_exported_symbol_in_section() Date: Thu, 5 May 2022 12:52:12 +0900 Message-Id: <20220505035212.1130858-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505035212.1130858-1-masahiroy@kernel.org> References: <20220505035212.1130858-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: Now check_exported_symbol() always succeeds. Merge it into find_exported_symbol_in_search() to make the code concise. Signed-off-by: Masahiro Yamada --- kernel/module/main.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 22a860d42c16..14686571d4fc 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -243,17 +243,6 @@ static __maybe_unused void *any_section_objs(const struct load_info *info, #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) #endif -static bool check_exported_symbol(const struct symsearch *syms, - struct module *owner, unsigned int symnum, - struct find_symbol_arg *fsa) -{ - fsa->owner = owner; - fsa->crc = symversion(syms->crcs, symnum); - fsa->sym = &syms->start[symnum]; - fsa->license = syms->license; - return true; -} - static const char *kernel_symbol_name(const struct kernel_symbol *sym) { #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS @@ -290,12 +279,15 @@ static bool find_exported_symbol_in_section(const struct symsearch *syms, sym = bsearch(fsa->name, syms->start, syms->stop - syms->start, sizeof(struct kernel_symbol), cmp_name); + if (!sym) + return false; - if (sym != NULL && check_exported_symbol(syms, owner, - sym - syms->start, fsa)) - return true; + fsa->owner = owner; + fsa->crc = symversion(syms->crcs, sym - syms->start); + fsa->sym = sym; + fsa->license = syms->license; - return false; + return true; } /*