Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5143128rwl; Sun, 8 Jan 2023 09:16:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXt9jYXPHj8XKtZyffR/r9qRZ4/QcD2z3FzSskTPx06hWc+SQj0u4S9xbpQvNwtq28Zs6uAv X-Received: by 2002:a17:902:ab8f:b0:192:ce7c:dc43 with SMTP id f15-20020a170902ab8f00b00192ce7cdc43mr22823587plr.40.1673198163830; Sun, 08 Jan 2023 09:16:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673198163; cv=none; d=google.com; s=arc-20160816; b=Bp/fI2NA8jUFRtoyX9GZYvXas6S/5WyTf1G/VrBj1tYui8u6GcECxAB9vk5rc17bXX PJVN+VRYVCwRveJIduebHfk5hOkKyWd09rNuuFCq1sDyc3Dw+pYF0wKRaiqGrXKyfCvF 5u441NIaPGAxPuI8SXiCPktXZ9PCYIfpfacNmRKf6Fn/9d0S7aDj2/NwYJvuRy0Jj+0R 78VvUsJbHp0XzFJCdTXq+Cyi1Dov++qEUjXr+V6IQXMAt5zphHZwVBABfu46Tfry3rwe +yPUEhB64fqvQyVwPWWli1lgXUlQQVYbpVLy0SwNawN70lpY8oeXNizWR8GLKUhpA0S7 5A1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:date:from:message-id; bh=kFNORYxvXadCG+ocjZmcumQi7o7+r/PeM6fPxEpi1Cc=; b=CD1erbPt0QZafpqqCd8sUmneTqi4+AJ9LpOzyLaLwrPenMPrClZvat2oZ3XUQmfWxe wme2WfsdchVZ/IwxRFmNYKvmNHPV3RfsTbf4MoOwD88KJWtHXlwdkexu3STd18Qk0Ulw /x6W9D9vMqo0r76fz06/20us70aIVopSNSF1F+Kv72dy9pGQX4/MKzxk+vnAQm1YAb0M X1EOxcY5GQEAtmbZP/yivqjj8GaStBclajr6V3BCT/T26jX7Z1KcdzM4roFc3JO5SRl4 7NGju4Lje+o9us9wqJqlVK2p/QyGzlsbEtbpCQSo1ojSZLJ5GyjLpYqlDhsLdyk/WqAV 4xag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iw11-20020a170903044b00b001781f860a6dsi6515391plb.228.2023.01.08.09.15.52; Sun, 08 Jan 2023 09:16:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-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; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233071AbjAHROi (ORCPT + 65 others); Sun, 8 Jan 2023 12:14:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233663AbjAHROh (ORCPT ); Sun, 8 Jan 2023 12:14:37 -0500 X-Greylist: delayed 382 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 08 Jan 2023 09:14:35 PST Received: from mailout2.hostsharing.net (mailout2.hostsharing.net [83.223.78.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED6C2BC03 for ; Sun, 8 Jan 2023 09:14:35 -0800 (PST) Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL Global TLS RSA4096 SHA256 2022 CA1" (verified OK)) by mailout2.hostsharing.net (Postfix) with ESMTPS id EE25410189A6F; Sun, 8 Jan 2023 18:08:09 +0100 (CET) Received: from localhost (unknown [89.246.108.87]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id C418E603DB87; Sun, 8 Jan 2023 18:08:09 +0100 (CET) X-Mailbox-Line: From e7280be84acda02634bc7cb52c97656182b9c700 Mon Sep 17 00:00:00 2001 Message-Id: From: Lukas Wunner Date: Sun, 8 Jan 2023 18:08:08 +0100 Subject: [PATCH] wifi: cfg80211: Deduplicate certificate loading To: Johannes Berg Cc: linux-wireless@vger.kernel.org, David Howells X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE 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-wireless@vger.kernel.org load_keys_from_buffer() in net/wireless/reg.c duplicates x509_load_certificate_list() in crypto/asymmetric_keys/x509_loader.c for no apparent reason. Deduplicate it. No functional change intended. Signed-off-by: Lukas Wunner Cc: David Howells --- crypto/asymmetric_keys/x509_loader.c | 1 + net/wireless/reg.c | 54 +++++----------------------- 2 files changed, 9 insertions(+), 46 deletions(-) diff --git a/crypto/asymmetric_keys/x509_loader.c b/crypto/asymmetric_keys/x509_loader.c index 1bc169dee22e..a41741326998 100644 --- a/crypto/asymmetric_keys/x509_loader.c +++ b/crypto/asymmetric_keys/x509_loader.c @@ -55,3 +55,4 @@ int x509_load_certificate_list(const u8 cert_list[], pr_err("Problem parsing in-kernel X.509 certificate list\n"); return 0; } +EXPORT_SYMBOL_GPL(x509_load_certificate_list); diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 4f3f31244e8b..af65196c916e 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -737,51 +737,9 @@ static bool valid_country(const u8 *data, unsigned int size, } #ifdef CONFIG_CFG80211_REQUIRE_SIGNED_REGDB -static struct key *builtin_regdb_keys; - -static void __init load_keys_from_buffer(const u8 *p, unsigned int buflen) -{ - const u8 *end = p + buflen; - size_t plen; - key_ref_t key; - - while (p < end) { - /* Each cert begins with an ASN.1 SEQUENCE tag and must be more - * than 256 bytes in size. - */ - if (end - p < 4) - goto dodgy_cert; - if (p[0] != 0x30 && - p[1] != 0x82) - goto dodgy_cert; - plen = (p[2] << 8) | p[3]; - plen += 4; - if (plen > end - p) - goto dodgy_cert; - - key = key_create_or_update(make_key_ref(builtin_regdb_keys, 1), - "asymmetric", NULL, p, plen, - ((KEY_POS_ALL & ~KEY_POS_SETATTR) | - KEY_USR_VIEW | KEY_USR_READ), - KEY_ALLOC_NOT_IN_QUOTA | - KEY_ALLOC_BUILT_IN | - KEY_ALLOC_BYPASS_RESTRICTION); - if (IS_ERR(key)) { - pr_err("Problem loading in-kernel X.509 certificate (%ld)\n", - PTR_ERR(key)); - } else { - pr_notice("Loaded X.509 cert '%s'\n", - key_ref_to_ptr(key)->description); - key_ref_put(key); - } - p += plen; - } - - return; +#include -dodgy_cert: - pr_err("Problem parsing in-kernel X.509 certificate list\n"); -} +static struct key *builtin_regdb_keys; static int __init load_builtin_regdb_keys(void) { @@ -797,11 +755,15 @@ static int __init load_builtin_regdb_keys(void) pr_notice("Loading compiled-in X.509 certificates for regulatory database\n"); #ifdef CONFIG_CFG80211_USE_KERNEL_REGDB_KEYS - load_keys_from_buffer(shipped_regdb_certs, shipped_regdb_certs_len); + x509_load_certificate_list(shipped_regdb_certs, + shipped_regdb_certs_len, + builtin_regdb_keys); #endif #ifdef CONFIG_CFG80211_EXTRA_REGDB_KEYDIR if (CONFIG_CFG80211_EXTRA_REGDB_KEYDIR[0] != '\0') - load_keys_from_buffer(extra_regdb_certs, extra_regdb_certs_len); + x509_load_certificate_list(extra_regdb_certs, + extra_regdb_certs_len, + builtin_regdb_keys); #endif return 0; -- 2.39.0