From patchwork Wed May 4 19:42:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12838468 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 743ABC433EF for ; Wed, 4 May 2022 19:47:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242764AbiEDTvM (ORCPT ); Wed, 4 May 2022 15:51:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232665AbiEDTvM (ORCPT ); Wed, 4 May 2022 15:51:12 -0400 Received: from condef-08.nifty.com (condef-08.nifty.com [202.248.20.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D29C21A835 for ; Wed, 4 May 2022 12:47:35 -0700 (PDT) Received: from conuserg-09.nifty.com ([10.126.8.72])by condef-08.nifty.com with ESMTP id 244Jhsl1004853 for ; Thu, 5 May 2022 04:43:54 +0900 Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-09.nifty.com with ESMTP id 244JhL7l001234; Thu, 5 May 2022 04:43:22 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com 244JhL7l001234 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1651693402; bh=gyFunNMph3GVNXUoKHHdnuMJ0Tsbpe5rKrwy1jeRjFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OOXAoGQ/oFsI1rqvci6zpTr4wE0/NeUOhggVqXp1QpMkb3R7jAY6pO4rcqOG8K2sv vT7vmu73p78SRaqUC+bpwIqDqB5PQxUc8o10jGLn18EQiCmJRj0DwNMSkjexKZ2KMs we7jYsaxQZYdspcvReR7RtjaYnXQptAPvJNQsV8pdT/S+yJcorywZr7obGJlUvMglx Q+I0lr9/sQzXbHxfu5RZhvFzHxXbOkR1wmgjARAvEqV0gHGbmg9UMkevrJfz3oqtFp iF5noZdfWjWiFxrt1bdY+G5pIgXAJcl6fXjVKXBYwZAi47A/pLpMTp3xVh0COALycn nLc2gYYGFtdlQ== 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 1/3] module: do not pass opaque pointer for symbol search Date: Thu, 5 May 2022 04:42:43 +0900 Message-Id: <20220504194245.1088063-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220504194245.1088063-1-masahiroy@kernel.org> References: <20220504194245.1088063-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.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index c9e2342da28e..d57beb6b4eee 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -445,11 +445,9 @@ struct find_symbol_arg { }; 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; @@ -495,16 +493,15 @@ static 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 Wed May 4 19:42:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12838465 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 DC554C433F5 for ; Wed, 4 May 2022 19:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239983AbiEDTuJ (ORCPT ); Wed, 4 May 2022 15:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377706AbiEDTtx (ORCPT ); Wed, 4 May 2022 15:49:53 -0400 Received: from condef-06.nifty.com (condef-06.nifty.com [202.248.20.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F61F4DF7C for ; Wed, 4 May 2022 12:46:16 -0700 (PDT) Received: from conuserg-09.nifty.com ([10.126.8.72])by condef-06.nifty.com with ESMTP id 244Jhst0002488 for ; Thu, 5 May 2022 04:43:54 +0900 Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-09.nifty.com with ESMTP id 244JhL7m001234; Thu, 5 May 2022 04:43:23 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com 244JhL7m001234 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1651693403; bh=98mPeoJXI1ySCwQ5M2g+AhZXZflDUK/pAReyjjvyXS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=APhVXgF3SPVf2PKJIsbMAnePRT0JFQ2ntS+b1lbf9Y9GPRqtq5tz68oC8TXQm7GCt CUkt0QDH6qiCGxvc/2E1aStctEyNr5SLnKV26bYnmHGovbUXR6u8B3pmxnotzcznwP GiuE8DkbGw92F1gDUHbTlVoWD5GH2jl+4tX0J9Am9pcxQA89OIQJXVlWAOlMC1gEJq HtgCPU0S97XspvLGj9H1OPb2Dp1tD8WrFbBg4n7uxxjwU2QZs5lEIAjgqc83BUEllt YnJd5YpvxmVMQcULTIIe66kwNN1syEb0IsbqZFK/ehABvsnv2uKdBb13VwNpcz6mfr NlFizDg3/HLTw== 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 2/3] module: do not binary-search in __ksymtab_gpl if fsa->gplok is false Date: Thu, 5 May 2022 04:42:44 +0900 Message-Id: <20220504194245.1088063-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220504194245.1088063-1-masahiroy@kernel.org> References: <20220504194245.1088063-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.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index d57beb6b4eee..4380ceb825b9 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -448,8 +448,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]; @@ -497,6 +495,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 Wed May 4 19:42:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12838467 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 8BA7CC433EF for ; Wed, 4 May 2022 19:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233914AbiEDTuk (ORCPT ); Wed, 4 May 2022 15:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232665AbiEDTuj (ORCPT ); Wed, 4 May 2022 15:50:39 -0400 Received: from condef-01.nifty.com (condef-01.nifty.com [202.248.20.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A30B91A835 for ; Wed, 4 May 2022 12:47:02 -0700 (PDT) Received: from conuserg-09.nifty.com ([10.126.8.72])by condef-01.nifty.com with ESMTP id 244JhuC0001316 for ; Thu, 5 May 2022 04:43:56 +0900 Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-09.nifty.com with ESMTP id 244JhL7n001234; Thu, 5 May 2022 04:43:23 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com 244JhL7n001234 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1651693403; bh=w4C7GITZYrtU5qB494mOB6XmSgN1m8R6tiEfRuraIfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FwM5SnP/wA1ExO6evdZcg+Z1du3s/S9auQ+Mz+ZwzhVymGUmVapkiar6soeOiJacK 7U6XPBZXw4RoYb8Ynp0P5Zo+gzrBTWekW2FtwY80c7C0qPAHMuTy8sB3Bl/AlGL0G1 W8xuNtAJVxZqDHuVbQBQZ/0rPf3nIVyfnG8Wl2EAcmNCuVsTYKVRBfHOd03vKdoVly NUfDPV37sERTpFgz+3yFem5fdQoAvnH21VajAVsh0bYY/+HTguZ7BCiEVkTtvZOpME J+Ht/z49DsTsdFaLDAUhNe82xe5v4mLyHxPJGB32KzSttu3vxkvieovoL/P8mL1ssp WCsJe5/Diutvw== 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 3/3] module: merge check_exported_symbol() into find_exported_symbol_in_section() Date: Thu, 5 May 2022 04:42:45 +0900 Message-Id: <20220504194245.1088063-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220504194245.1088063-1-masahiroy@kernel.org> References: <20220504194245.1088063-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.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 4380ceb825b9..6b2afce80c32 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -444,17 +444,6 @@ struct find_symbol_arg { enum mod_license license; }; -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 unsigned long kernel_symbol_value(const struct kernel_symbol *sym) { #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS @@ -500,12 +489,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; } /*