cfg80211: in-kernel regulatory database
Subsystems (3)
Johannes Berg
maintainercover cfg80211: in-kernel regulatory database
Here's a resend of the database-as-firmware patches.
I've changed it to kmemdup() instead of hanging on to the struct firmware, that way reload actually works without piggy-backing on the existing one that's already loaded.
I've also changed it so you can configure it to not trust the built-in keys and also configure it to load keys from an external directory during build.
So I think literally the only thing that this still needs is Seth's key.
johannes
Johannes Berg
maintainerPATCH 1/4 cfg80211: support loading regulatory database as firmware file
From: Johannes Berg <[email protected]>
As the current regulatory database is only about 4k big, and already difficult to extend, we decided that overall it would be better to get rid of the complications with CRDA and load the database into the kernel directly, but in a new format that is extensible.
The new file format can be extended since it carries a length field on all the structs that need to be extensible.
In order to be able to request firmware when the module initializes, move cfg80211 from subsys_initcall() to the later fs_initcall(); the firmware loader is at the same level but linked earlier, so it can be called from there. Otherwise, when both the firmware loader and cfg80211 are built-in, the request will crash the kernel. We also need to be before device_initcall() so that cfg80211 is available for devices when they initialize.
--- Documentation/networking/regulatory.txt | 8 + net/wireless/Kconfig | 4 +- net/wireless/core.c | 2 +- net/wireless/reg.c | 272 +++++++++++++++++++++++++++++--- 4 files changed, 262 insertions(+), 24 deletions(-)
Documentation/networking/regulatory.txt +8 -0
@@ -19,6 +19,14 @@ core regulatory domain all wireless devices should adhere to. How to get regulatory domains to the kernel ------------------------------------------- +When the regulatory domain is first set up, the kernel will request a +database file (regulatory.db) containing all the regulatory rules. It +will then use that database when it needs to look up the rules for a +given country. + +How to get regulatory domains to the kernel (old CRDA solution) +--------------------------------------------------------------- + Userspace gets a regulatory domain in the kernel by having a userspace agent build it and send it via nl80211. Only expected regulatory domains will be respected by the kernel.
net/wireless/Kconfig +3 -1
@@ -19,6 +19,7 @@ config WEXT_PRIV config CFG80211 tristate "cfg80211 - wireless configuration API" depends on RFKILL || !RFKILL + select FW_LOADER ---help--- cfg80211 is the Linux wireless LAN (802.11) configuration API. Enable this if you have a wireless device.
@@ -167,7 +168,8 @@ config CFG80211_CRDA_SUPPORT depends on CFG80211 help You should enable this option unless you know for sure you have no - need for it, for example when using internal regdb (above.) + need for it, for example when using internal regdb (above) or the + database loaded as a firmware file. If unsure, say Y.
net/wireless/core.c +1 -1
@@ -1384,7 +1384,7 @@ static int __init cfg80211_init(void) out_fail_pernet:return err; } -subsys_initcall (cfg80211_init); +fs_initcall (cfg80211_init); static void __exit cfg80211_exit(void) {
net/wireless/reg.c +250 -22
327 lines not on this page · raw message
Signature · 1 line
2.14.2
Johannes Berg
maintainerPATCH 2/4 cfg80211: support reloading regulatory database
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
If the regulatory database is loaded, and then updated, it may be necessary to reload it. Add an nl80211 command to do this.
Note that this just reloads the database, it doesn't re-apply the rules from it immediately.
--- include/uapi/linux/nl80211.h | 4 +++ net/wireless/nl80211.c | 11 ++++++ net/wireless/reg.c | 80 +++++++++++++++++++++++++++++++++----------- net/wireless/reg.h | 6 ++++ 4 files changed, 81 insertions(+), 20 deletions(-)
include/uapi/linux/nl80211.h +4 -0
@@ -990,6 +990,8 @@* &NL80211_CMD_CONNECT or &NL80211_CMD_ROAM. If the 4 way handshake failed * &NL80211_CMD_DISCONNECT should be indicated instead. * +* @NL80211_CMD_RELOAD_REGDB: Request that the regdb firmware file is reloaded. +* * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use */
@@ -1194,6 +1196,8 @@ enum nl80211_commands {NL80211_CMD_PORT_AUTHORIZED , + NL80211_CMD_RELOAD_REGDB, +/* add new commands above here */ /* used to define NL80211_CMD_MAX below */
net/wireless/nl80211.c +11 -0
@@ -5678,6 +5678,11 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) } } +static int nl80211_reload_regdb (struct sk_buff *skb,struct genl_info *info) +{ +return reg_reload_regdb (); +} +static int nl80211_get_mesh_config (struct sk_buff *skb,struct genl_info *info) {
@@ -12708,6 +12713,12 @@ static const struct genl_ops nl80211_ops[] = { .policy = nl80211_policy, .flags = GENL_ADMIN_PERM, }, + { + .cmd = NL80211_CMD_RELOAD_REGDB, + .doit = nl80211_reload_regdb, + .policy = nl80211_policy, + .flags = GENL_ADMIN_PERM, + }, { .cmd = NL80211_CMD_GET_MESH_CONFIG, .doit = nl80211_get_mesh_config,
net/wireless/reg.c +60 -20
114 lines not on this page · raw message
net/wireless/reg.h +6 -0
@@ -179,4 +179,10 @@ void regulatory_propagate_dfs_state(struct wiphy *wiphy,* @wiphy2 - wiphy it's dfs_region to be checked against that of wiphy1 */ bool reg_dfs_domain_same (struct wiphy *wiphy1,struct wiphy *wiphy2); + +/** +* reg_reload_regdb - reload the regulatory.db firmware file +*/ +int reg_reload_regdb (void ); +#endif /* __NET_WIRELESS_REG_H */
Signature · 1 line
2.14.2
Johannes Berg
maintainerPATCH 3/4 cfg80211: reg: remove support for built-in regdb
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
Parsing and building C structures from a regdb is no longer needed since the "firmware" file (regulatory.db) can be linked into the kernel image to achieve the same effect.
--- Documentation/networking/regulatory.txt | 22 +---- net/wireless/Kconfig | 24 +---- net/wireless/Makefile | 6 -- net/wireless/db.txt | 17 ---- net/wireless/genregdb.awk | 158 -------------------------------- net/wireless/reg.c | 39 -------- net/wireless/regdb.h | 23 ----- 7 files changed, 3 insertions(+), 286 deletions(-) delete mode 100644 net/wireless/db.txt delete mode 100644 net/wireless/genregdb.awk delete mode 100644 net/wireless/regdb.h
Documentation/networking/regulatory.txt +2 -20
@@ -200,23 +200,5 @@ Then in some part of your code after your wiphy has been registered: Statically compiled regulatory database --------------------------------------- -In most situations the userland solution using CRDA as described -above is the preferred solution. However in some cases a set of -rules built into the kernel itself may be desirable. To account -for this situation, a configuration option has been provided -(i.e. CONFIG_CFG80211_INTERNAL_REGDB). With this option enabled, -the wireless database information contained in net/wireless/db.txt is -used to generate a data structure encoded in net/wireless/regdb.c. -That option also enables code in net/wireless/reg.c which queries -the data in regdb.c as an alternative to using CRDA. - -The file net/wireless/db.txt should be kept up-to-date with the db.txt -file available in the git repository here: - - git://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git - -Again, most users in most situations should be using the CRDA package -provided with their distribution, and in most other situations users -should be building and using CRDA on their own rather than using -this option. If you are not absolutely sure that you should be using -CONFIG_CFG80211_INTERNAL_REGDB then _DO_NOT_USE_IT_. +When a database should be fixed into the kernel, it can be provided as a +firmware file at build time that is then linked into the kernel.
net/wireless/Kconfig +1 -23
@@ -140,30 +140,8 @@ config CFG80211_DEBUGFS If unsure, say N. -config CFG80211_INTERNAL_REGDB - bool "use statically compiled regulatory rules database" if EXPERT - default n - depends on CFG80211 - ---help--- - This option generates an internal data structure representing - the wireless regulatory rules described in net/wireless/db.txt - and includes code to query that database. This is an alternative - to using CRDA for defining regulatory rules for the kernel. - - Using this option requires some parsing of the db.txt at build time, - the parser will be upkept with the latest wireless-regdb updates but - older wireless-regdb formats will be ignored. The parser may later - be replaced to avoid issues with conflicts on versions of - wireless-regdb. - - For details see: - - http://wireless.kernel.org/en/developers/Regulatory - - Most distributions have a CRDA package. So if unsure, say N. - config CFG80211_CRDA_SUPPORT - bool "support CRDA" if CFG80211_INTERNAL_REGDB + bool "support CRDA" if EXPERT default y depends on CFG80211 help
net/wireless/Makefile +0 -6
@@ -14,11 +14,5 @@ cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o mesh.o ap.o trace.o ocb.o cfg80211-$(CONFIG_OF) += of.o cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o -cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o CFLAGS_trace.o := -I$(src) - -$(obj)/regdb.c: $(src)/db.txt $(src)/genregdb.awk - @$(AWK) -f $(srctree)/$(src)/genregdb.awk < $< > $@ - -clean-files := regdb.c
net/wireless/db.txt deleted +0 -17
@@ -1,17 +0,0 @@ -# -# This file is a placeholder to prevent accidental build breakage if someone -# enables CONFIG_CFG80211_INTERNAL_REGDB. Almost no one actually needs to -# enable that build option. -# -# You should be using CRDA instead. It is even better if you use the CRDA -# package provided by your distribution, since they will probably keep it -# up-to-date on your behalf. -# -# If you _really_ intend to use CONFIG_CFG80211_INTERNAL_REGDB then you will -# need to replace this file with one containing appropriately formatted -# regulatory rules that cover the regulatory domains you will be using. Your -# best option is to extract the db.txt file from the wireless-regdb git -# repository: -# -# git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-regdb.git -#
net/wireless/genregdb.awk deleted +0 -158
158 lines not on this page · raw message
net/wireless/reg.c +0 -39
@@ -59,7 +59,6 @@#include "core.h" #include "reg.h" #include "rdev-ops.h" -#include "regdb.h" #include "nl80211.h" /*
@@ -495,38 +494,6 @@ static int reg_schedule_apply(const struct ieee80211_regdomain *regdom)return 0 ; } -#ifdef CONFIG_CFG80211_INTERNAL_REGDB -static int reg_query_builtin (const char *alpha2) -{ -const struct ieee80211_regdomain *regdom =NULL ; -unsigned int i; - -for (i =0 ; i < reg_regdb_size; i++) { -if (alpha2_equal (alpha2, reg_regdb[i]->alpha2)) { - regdom =reg_copy_regd (reg_regdb[i]); -break ; - } - } -if (!regdom) -return -ENODATA ; - -return reg_schedule_apply (regdom); -} - -/* Feel free to add any other sanity checks here */ -static void reg_regdb_size_check (void ) -{ -/* We should ideally BUILD_BUG_ON() but then random builds would fail */ -WARN_ONCE (!reg_regdb_size,"db.txt is empty, you should update it..." ); -} -#else -static inline void reg_regdb_size_check (void ) {} -static inline int reg_query_builtin (const char *alpha2) -{ -return -ENODATA ; -} -#endif /* CONFIG_CFG80211_INTERNAL_REGDB */ -#ifdef CONFIG_CFG80211_CRDA_SUPPORT /* Max number of consecutive attempts to communicate with CRDA */ #define REG_MAX_CRDA_TIMEOUTS 10
@@ -863,10 +830,6 @@ int reg_reload_regdb(void)static bool reg_query_database (struct regulatory_request *request) { -/* query internal regulatory database (if it exists) */ -if (reg_query_builtin (request->alpha2) ==0 ) -return true; -if (query_regdb_file (request->alpha2) ==0 )return true;
@@ -3558,8 +3521,6 @@ int __init regulatory_init(void)spin_lock_init (®_pending_beacons_lock);spin_lock_init (®_indoor_lock); -reg_regdb_size_check (); -rcu_assign_pointer (cfg80211_regdomain, cfg80211_world_regdom); user_alpha2[0 ] ='9' ;
net/wireless/regdb.h deleted +0 -23
@@ -1,23 +0,0 @@ -#ifndef __REGDB_H__ -#define __REGDB_H__ - -/* -* Copyright 2009 John W. Linville <[email protected]> -* -* Permission to use, copy, modify, and/or distribute this software for any -* purpose with or without fee is hereby granted, provided that the above -* copyright notice and this permission notice appear in all copies. -* -* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -extern const struct ieee80211_regdomain *reg_regdb[]; -extern int reg_regdb_size; - -#endif /* __REGDB_H__ */
Signature · 1 line
2.14.2
Johannes Berg
maintainerPATCH 4/4 cfg80211: implement regdb signature checking
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
Currently CRDA implements the signature checking, and the previous commits added the ability to load the whole regulatory database into the kernel.
However, we really can't lose the signature checking, so implement it in the kernel by loading a detached signature (regulatory.db.p7s) and check it against built-in keys.
TODO
- add Seth's key, obviously
--- net/wireless/Kconfig | 30 +++++++++++ net/wireless/Makefile | 22 ++++++++ net/wireless/certs/none.x509 | 0 net/wireless/reg.c | 121 ++++++++++++++++++++++++++++++++++++++++++- net/wireless/reg.h | 8 +++ 5 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 net/wireless/certs/none.x509
net/wireless/Kconfig +30 -0
@@ -83,6 +83,36 @@ config CFG80211_CERTIFICATION_ONUS you are a wireless researcher and are working in a controlled and approved environment by your local regulatory agency. +config CFG80211_REQUIRE_SIGNED_REGDB + bool "require regdb signature" if CFG80211_CERTIFICATION_ONUS + default y + select SYSTEM_DATA_VERIFICATION + help + Require that in addition to the "regulatory.db" file a + "regulatory.db.p7s" can be loaded with a valid PKCS#7 + signature for the regulatory.db file made by one of the + keys in the certs/ directory. + +config CFG80211_USE_KERNEL_REGDB_KEYS + bool "allow regdb keys shipped with the kernel" if CFG80211_CERTIFICATION_ONUS + default y + depends on CFG80211_REQUIRE_SIGNED_REGDB + help + Allow the regulatory database to be signed by one of the keys for + which certificates are part of the kernel sources + (in net/wireless/certs/). + + This is currently only Seth Forshee's key, who is the regulatory + database maintainer. + +config CFG80211_EXTRA_REGDB_KEYDIR + string "additional regdb key directory" if CFG80211_CERTIFICATION_ONUS + depends on CFG80211_REQUIRE_SIGNED_REGDB + help + If selected, point to a directory with DER-encoded X.509 + certificates like in the kernel sources (net/wireless/certs/) + that shall be accepted for a signed regulatory database. + config CFG80211_REG_CELLULAR_HINTS bool "cfg80211 regulatory support for cellular base station hints" depends on CFG80211_CERTIFICATION_ONUS
net/wireless/Makefile +22 -0
@@ -16,3 +16,25 @@ cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o CFLAGS_trace.o := -I$(src) + +cfg80211-$(CONFIG_CFG80211_USE_KERNEL_REGDB_KEYS) += shipped-certs.o +ifneq ($(CONFIG_CFG80211_EXTRA_REGDB_KEYDIR),) +cfg80211-y += extra-certs.o +endif + +$(obj)/shipped-certs.c: $(wildcard $(srctree)/$(src)/certs/*.x509) + @echo " GEN $@" + @echo '#include "reg.h"' > $@ + @echo 'const u8 shipped_regdb_certs[] = {' >> $@ + @for f in $^ ; do hexdump -v -e '1/1 "0x%.2x," "\n"' < $$f >> $@ ; done + @echo '};' >> $@ + @echo 'unsigned int shipped_regdb_certs_len = sizeof(shipped_regdb_certs);' >> $@ + +$(obj)/extra-certs.c: $(CONFIG_CFG80211_EXTRA_REGDB_KEYDIR:"%"=%) \ + $(wildcard $(CONFIG_CFG80211_EXTRA_REGDB_KEYDIR:"%"=%)/*.x509) + @echo " GEN $@" + @echo '#include "reg.h"' > $@ + @echo 'const u8 extra_regdb_certs[] = {' >> $@ + @for f in $^ ; do test -f $$f && hexdump -v -e '1/1 "0x%.2x," "\n"' < $$f >> $@ || true ; done + @echo '};' >> $@ + @echo 'unsigned int extra_regdb_certs_len = sizeof(extra_regdb_certs);' >> $@
net/wireless/certs/none.x509 new file +0 -0
net/wireless/reg.c +120 -1
155 lines not on this page · raw message
net/wireless/reg.h +8 -0
@@ -1,5 +1,8 @@#ifndef __NET_WIRELESS_REG_H#define __NET_WIRELESS_REG_H + +#include <net/cfg80211.h> +/* * Copyright 2008-2011 Luis R. Rodriguez <[email protected]> *
@@ -185,4 +188,9 @@ bool reg_dfs_domain_same(struct wiphy *wiphy1, struct wiphy *wiphy2);*/ int reg_reload_regdb (void ); +extern const u8 shipped_regdb_certs[]; +extern unsigned int shipped_regdb_certs_len; +extern const u8 extra_regdb_certs[]; +extern unsigned int extra_regdb_certs_len; +#endif /* __NET_WIRELESS_REG_H */
Signature · 1 line
2.14.2
Re: [PATCH 4/4] cfg80211: implement regdb signature checking
Dear Johannes,
Dear Linux wireless,
Quoted 28 lines · Johannes Berg
From: Johannes Berg <[email protected]>
Currently CRDA implements the signature checking, and the previous commits added the ability to load the whole regulatory database into the kernel.
However, we really can't lose the signature checking, so implement it in the kernel by loading a detached signature (regulatory.db.p7s) and check it against built-in keys.
TODO
- add Seth's key, obviouslySigned-off-by Johannes Berg <[email protected]>--- net/wireless/Kconfig | 30 +++++++++++ net/wireless/Makefile | 22 ++++++++ net/wireless/certs/none.x509 | 0 net/wireless/reg.c | 121 ++++++++++++++++++++++++++++++++++++++++++- net/wireless/reg.h | 8 +++ 5 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 net/wireless/certs/none.x509net/wireless/Kconfig +0
-0
net/wireless/Kconfig config CFG80211_CERTIFICATION_ONUS · line 89
Quoted 7 lines
net/wireless/Kconfig +4
-0@@ -83,6 +83,36 @@ config CFG80211_CERTIFICATION_ONUS you are a wireless researcher and are working in a controlled and approved environment by your local regulatory agency. +config CFG80211_REQUIRE_SIGNED_REGDB + bool "require regdb signature" if CFG80211_CERTIFICATION_ONUS + default y + select SYSTEM_DATA_VERIFICATION
Since v4.15 commit 90a53e4432b122 ("cfg80211: implement regdb signature checking"), CFG80211_REQUIRE_SIGNED_REGDB is enabled unconditionally and users have no flexibility to disable it when CFG80211_CERTIFICATION_ONUS is unset (since the visibility of CFG80211_REQUIRE_SIGNED_REGDB depends on CFG80211_CERTIFICATION_ONUS).
Based on the documentation of CFG80211_CERTIFICATION_ONUS, this option is supposed to stay disabled most of the times, hence users have to live with CFG80211_REQUIRE_SIGNED_REGDB=y and SYSTEM_DATA_VERIFICATION=y enabled in their kernel, which consumes a few tens of KB in the uncompressed binary Image (particularly on arm64).
A few tens of KB is not much, but on embedded systems it matters.
Can you please confirm Wireless subsystem requires CFG80211_REQUIRE_SIGNED_REGDB=y and SYSTEM_DATA_VERIFICATION=y regardless of the status of CFG80211_CERTIFICATION_ONUS ?
Thanks,
Eugeniu