xfrm: add /proc/sys/core/net/xfrm_redact_secret
Subsystems (5)
PATCH 1/1 xfrm: add /proc/sys/core/net/xfrm_redact_secret
when enabled, 1, redact XFRM SA secret in the netlink response to xfrm_get_sa() or dump all sa.
e.g
echo 1 > /proc/sys/net/core/xfrm_redact_secret
ip xfrm state
src 172.16.1.200 dst 172.16.1.100
proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96
the aead secret is redacted.
/proc/sys/core/net/xfrm_redact_secret is a toggle.
Once enabled, either at compile or via proc, it can not be disabled. Redacting secret is a FIPS 140-2 requirement.
--- Documentation/networking/xfrm_sysctl.rst | 7 +++ include/net/netns/xfrm.h | 1 + net/xfrm/Kconfig | 10 ++++ net/xfrm/xfrm_sysctl.c | 20 +++++++ net/xfrm/xfrm_user.c | 76 +++++++++++++++++++++--- 5 files changed, 105 insertions(+), 9 deletions(-)
Documentation/networking/xfrm_sysctl.rst +7 -0
@@ -9,3 +9,10 @@ XFRM Syscall xfrm_acq_expires - INTEGER default 30 - hard timeout in seconds for acquire requests + +xfrm_redact_secret - INTEGER + A toggle to redact xfrm SA's secret to userspace. + When true the kernel, netlink message will redact SA secret + to userspace. This is part of FIPS 140-2 requirement. + Once the value is set to true, either at compile or at run time, + it can not be set to false.
include/net/netns/xfrm.h +1 -0
@@ -64,6 +64,7 @@ struct netns_xfrm {u32 sysctl_aevent_rseqth;int sysctl_larval_drop;u32 sysctl_acq_expires; +u32 sysctl_redact_secret;#ifdef CONFIG_SYSCTL struct ctl_table_header *sysctl_hdr;#endif
net/xfrm/Kconfig +10 -0
@@ -91,6 +91,16 @@ config XFRM_ESP select CRYPTO_SEQIV select CRYPTO_SHA256 +config XFRM_REDACT_SECRET + bool "Redact xfrm SA secret in netlink message" + depends on SYSCTL + default n + help + Enable XFRM SA secret redact in the netlink message. + Redacting secret is a FIPS 140-2 requirement. + Once enabled at compile, the value can not be set to false on + a running system. + config XFRM_IPCOMP tristate select XFRM_ALGO
net/xfrm/xfrm_sysctl.c +20 -0
@@ -4,15 +4,25 @@#include <net/net_namespace.h> #include <net/xfrm.h> +#ifdef CONFIG_SYSCTL +#ifdef CONFIG_XFRM_REDACT_SECRET +#define XFRM_REDACT_SECRET 1 +#else +#define XFRM_REDACT_SECRET 0 +#endif +#endif +static void __net_init __xfrm_sysctl_init (struct net *net) { net->xfrm.sysctl_aevent_etime =XFRM_AE_ETIME ; net->xfrm.sysctl_aevent_rseqth =XFRM_AE_SEQT_SIZE ; net->xfrm.sysctl_larval_drop =1 ; net->xfrm.sysctl_acq_expires =30 ; + net->xfrm.sysctl_redact_secret =XFRM_REDACT_SECRET ; } #ifdef CONFIG_SYSCTL + static struct ctl_table xfrm_table[] = { { .procname = "xfrm_aevent_etime",
@@ -38,6 +48,15 @@ static struct ctl_table xfrm_table[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "xfrm_redact_secret", + .maxlen = sizeof(u32), + .mode = 0644, + /* only handle a transition from "0" to "1" */ + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ONE, + .extra2 = SYSCTL_ONE, + }, {} };
@@ -54,6 +73,7 @@ int __net_init xfrm_sysctl_init(struct net *net) table[1 ].data = &net->xfrm.sysctl_aevent_rseqth; table[2 ].data = &net->xfrm.sysctl_larval_drop; table[3 ].data = &net->xfrm.sysctl_acq_expires; + table[4 ].data = &net->xfrm.sysctl_redact_secret;/* Don't export sysctls to unprivileged users */ if (net->user_ns != &init_user_ns)
net/xfrm/xfrm_user.c +67 -9
114 lines not on this page · raw message
Signature · 1 line
2.20.1
Herbert Xu
maintainerQuoted 11 lines · Antony Antony
when enabled, 1, redact XFRM SA secret in the netlink response to
xfrm_get_sa()or dump all sa.e.g
echo 1 >/proc/sys/net/core/xfrm_redact_secret
ip xfrm state
src 172.16.1.200 dst 172.16.1.100proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96
Quoted 5 lines
the aead secret is redacted.
/proc/sys/core/net/xfrm_redact_secretis a toggle.
Once enabled, either at compile or via proc, it can not be disabled. Redacting secret is a FIPS 140-2 requirement.
Couldn't you use the existing fips_enabled sysctl?
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 12 lines · Herbert Xu
Quoted 11 lines · Antony Antony
when enabled, 1, redact XFRM SA secret in the netlink response to
xfrm_get_sa()or dump all sa.e.g
echo 1 >/proc/sys/net/core/xfrm_redact_secret
ip xfrm state
src 172.16.1.200 dst 172.16.1.100proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96
Quoted 7 lines
Quoted 5 lines
the aead secret is redacted.
/proc/sys/core/net/xfrm_redact_secretis a toggle.
Once enabled, either at compile or via proc, it can not be disabled. Redacting secret is a FIPS 140-2 requirement.Couldn't you use the existing
fips_enabledsysctl?
that could be a step, however, not yet.
Libreswan in FIPS mode with xfrm_redact_secret enabled would work fine, however, enabling xfrm_redact_secret would break Strongswan in FIPS mode. We can add this option fips_enabled once Strongswan does not need SA secret, child_sa->update().
Also there was interest to able to use xfrm_redact_secret independent of FIPS.
I thik for now it best to be ouside fips_enabled.
Am Dienstag, 28. Juli 2020, 17:47:30 CEST schrieb Antony Antony:
Hi Antony,
Quoted 158 lines
when enabled, 1, redact XFRM SA secret in the netlink response to
xfrm_get_sa()or dump all sa.e.g
echo 1 >/proc/sys/net/core/xfrm_redact_secret
ip xfrm state
src 172.16.1.200 dst 172.16.1.100proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96the aead secret is redacted.
/proc/sys/core/net/xfrm_redact_secretis a toggle.
Once enabled, either at compile or via proc, it can not be disabled. Redacting secret is a FIPS 140-2 requirement.Cc Stephan Mueller <[email protected]>Signed-off-by Antony Antony <[email protected]>--- Documentation/networking/xfrm_sysctl.rst | 7 +++ include/net/netns/xfrm.h | 1 + net/xfrm/Kconfig | 10 ++++ net/xfrm/xfrm_sysctl.c | 20 +++++++ net/xfrm/xfrm_user.c | 76 +++++++++++++++++++++--- 5 files changed, 105 insertions(+), 9 deletions(-)(quoted diff) +0
-0
b/Documentation/networking/xfrm_sysctl.rstindex47b9bbdd0179..26432b0ff3ac100644Documentation/networking/xfrm_sysctl.rst +7
-0@@ -9,3 +9,10 @@ XFRM Syscall xfrm_acq_expires - INTEGER default 30 - hard timeout in seconds for acquire requests + +xfrm_redact_secret - INTEGER + A toggle to redact xfrm SA's secret to userspace. + When true the kernel, netlink message will redact SA secret + to userspace. This is part of FIPS 140-2 requirement. + Once the value is set to true, either at compile or at run time, + it can not be set to false.include/net/netns/xfrm.h +1
-0@@ -64,6 +64,7 @@ struct netns_xfrm {u32 sysctl_aevent_rseqth;int sysctl_larval_drop;u32 sysctl_acq_expires; +u32 sysctl_redact_secret;#ifdef CONFIG_SYSCTL struct ctl_table_header *sysctl_hdr;#endif net/xfrm/Kconfig +10
-0@@ -91,6 +91,16 @@ config XFRM_ESP select CRYPTO_SEQIV select CRYPTO_SHA256 +config XFRM_REDACT_SECRET + bool "Redact xfrm SA secret in netlink message" + depends on SYSCTL + default n + help + Enable XFRM SA secret redact in the netlink message. + Redacting secret is a FIPS 140-2 requirement. + Once enabled at compile, the value can not be set to false on + a running system. + config XFRM_IPCOMP tristate select XFRM_ALGOnet/xfrm/xfrm_sysctl.c +20
-0@@ -4,15 +4,25 @@#include <net/net_namespace.h> #include <net/xfrm.h> +#ifdef CONFIG_SYSCTL +#ifdef CONFIG_XFRM_REDACT_SECRET +#define XFRM_REDACT_SECRET 1 +#else +#define XFRM_REDACT_SECRET 0 +#endif +#endif +static void __net_init __xfrm_sysctl_init (struct net *net) { net->xfrm.sysctl_aevent_etime =XFRM_AE_ETIME ; net->xfrm.sysctl_aevent_rseqth =XFRM_AE_SEQT_SIZE ; net->xfrm.sysctl_larval_drop =1 ; net->xfrm.sysctl_acq_expires =30 ; + net->xfrm.sysctl_redact_secret =XFRM_REDACT_SECRET ; } #ifdef CONFIG_SYSCTL + static struct ctl_table xfrm_table[] = { { .procname = "xfrm_aevent_etime",@@ -38,6 +48,15 @@ static struct ctl_table xfrm_table[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "xfrm_redact_secret", + .maxlen = sizeof(u32), + .mode = 0644, + /* only handle a transition from "0" to "1" */ + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ONE, + .extra2 = SYSCTL_ONE, + }, {} };@@ -54,6 +73,7 @@ int __net_init xfrm_sysctl_init(struct net *net) table[1 ].data = &net->xfrm.sysctl_aevent_rseqth; table[2 ].data = &net->xfrm.sysctl_larval_drop; table[3 ].data = &net->xfrm.sysctl_acq_expires; + table[4 ].data = &net->xfrm.sysctl_redact_secret;/* Don't export sysctls to unprivileged users */ if (net->user_ns != &init_user_ns)net/xfrm/xfrm_user.c +5
-3@@ -848,21 +848,78 @@ static int copy_user_offload(struct xfrm_state_offload *xso, struct sk_buff *skb return 0; } -static int copy_to_user_auth (struct xfrm_algo_auth *auth,struct sk_buff *skb) +static int copy_to_user_auth(u32 redact_secret, struct xfrm_algo_auth *auth, + struct sk_buff *skb) {struct xfrm_algo *algo; +struct xfrm_algo_auth *ap;struct nlattr *nla; nla =nla_reserve (skb,XFRMA_ALG_AUTH ,sizeof (*algo) + (auth->alg_key_len +7 ) /8 );if (!nla)return -EMSGSIZE ; - algo =nla_data (nla);strncpy (algo->alg_name, auth->alg_name,sizeof (algo->alg_name)); -memcpy (algo->alg_key, auth->alg_key, (auth->alg_key_len +7 ) /8 ); + +if (redact_secret && auth->alg_key_len) +memset (algo->alg_key,0 , (auth->alg_key_len +7 ) /8 ); +else
net/xfrm/xfrm_user.c static int copy_user_offload(struct xfrm_state_offload · line 877
Quoted 10 lines
net/xfrm/xfrm_user.c +8
-0+memcpy (algo->alg_key, auth->alg_key, + (auth->alg_key_len +7 ) /8 ); algo->alg_key_len = auth->alg_key_len; + nla =nla_reserve (skb,XFRMA_ALG_AUTH_TRUNC ,xfrm_alg_auth_len (auth)); +if (!nla) +return -EMSGSIZE ; + ap =nla_data (nla); +memcpy (ap, auth,sizeof (struct xfrm_algo_auth )); +if (redact_secret)
You test for auth->alg_key_len above. Shouldn't there such a check here too?
Quoted 10 lines
net/xfrm/xfrm_user.c +10
-0+memset (ap->alg_key,0 , (auth->alg_key_len +7 ) /8 ); + else + memcpy(ap->alg_key, auth->alg_key, + (auth->alg_key_len + 7) / 8); +return 0 ; +} + +static int copy_to_user_aead (u32 redact_secret, +struct xfrm_algo_aead *aead,struct sk_buff *skb) +{
net/xfrm/xfrm_user.c static int copy_user_offload(struct xfrm_state_offload *xso, struct sk_buff *skb · line 897
Quoted 10 lines
net/xfrm/xfrm_user.c +10
-0+struct nlattr *nla =nla_reserve (skb,XFRMA_ALG_AEAD ,aead_len (aead)); +struct xfrm_algo_aead *ap; + +if (!nla) +return -EMSGSIZE ; + + ap =nla_data (nla); +memcpy (ap, aead,sizeof (*aead)); + +if (redact_secret)
And here?
Quoted 10 lines
net/xfrm/xfrm_user.c +10
-0+memset (ap->alg_key,0 , (aead->alg_key_len +7 ) /8 ); + else + memcpy(ap->alg_key, aead->alg_key, + (aead->alg_key_len + 7) / 8); +return 0 ; +} + +static int copy_to_user_ealg (u32 redact_secret,struct xfrm_algo *ealg, +struct sk_buff *skb) +{
net/xfrm/xfrm_user.c static int copy_user_offload(struct xfrm_state_offload *xso, struct sk_buff *skb · line 917
Quoted 10 lines
net/xfrm/xfrm_user.c +10
-0+struct xfrm_algo *ap; +struct nlattr *nla =nla_reserve (skb,XFRMA_ALG_CRYPT , +xfrm_alg_len (ealg)); +if (!nla) +return -EMSGSIZE ; + + ap =nla_data (nla); +memcpy (ap, ealg,sizeof (*ealg)); + +if (redact_secret)
Here, too?
Quoted 43 lines
net/xfrm/xfrm_user.c +12
-6+memset (ap->alg_key,0 , (ealg->alg_key_len +7 ) /8 ); + else + memcpy(ap->alg_key, ealg->alg_key, + (ealg->alg_key_len + 7) / 8); +return 0 ; }@@ -884,6 +941,7 @@ static int copy_to_user_state_extra(struct xfrm_state *x, struct sk_buff *skb) {int ret =0 ; +struct net *net =xs_net (x);copy_to_user_state (x, p);@@ -906,20 +964,20 @@ static int copy_to_user_state_extra(struct xfrm_state *x, goto out; }if (x->aead) { - ret =nla_put (skb,XFRMA_ALG_AEAD ,aead_len (x->aead), x- aead); + ret =copy_to_user_aead (net->xfrm.sysctl_redact_secret, + x->aead, skb);if (ret) goto out; }if (x->aalg) { - ret =copy_to_user_auth (x->aalg, skb); -if (!ret) - ret =nla_put (skb,XFRMA_ALG_AUTH_TRUNC , -xfrm_alg_auth_len (x->aalg), x->aalg); + ret =copy_to_user_auth (net->xfrm.sysctl_redact_secret, + x->aalg, skb);if (ret) goto out; }if (x->ealg) { - ret =nla_put (skb,XFRMA_ALG_CRYPT ,xfrm_alg_len (x->ealg), x- ealg); + ret =copy_to_user_ealg (net->xfrm.sysctl_redact_secret, + x->ealg, skb);if (ret)
net/xfrm/xfrm_user.c
Quoted 2 lines
net/xfrm/xfrm_user.c +0
-0goto out; }
Ciao
Stephan
Quoted 166 lines · Stephan Mueller
Am Dienstag, 28. Juli 2020, 17:47:30 CEST schrieb Antony Antony:
Hi Antony,
Quoted 162 lines
when enabled, 1, redact XFRM SA secret in the netlink response to
xfrm_get_sa()or dump all sa.e.g
echo 1 >/proc/sys/net/core/xfrm_redact_secret
ip xfrm state
src 172.16.1.200 dst 172.16.1.100proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96the aead secret is redacted.
/proc/sys/core/net/xfrm_redact_secretis a toggle.
Once enabled, either at compile or via proc, it can not be disabled. Redacting secret is a FIPS 140-2 requirement.Cc Stephan Mueller <[email protected]>Signed-off-by Antony Antony <[email protected]>--- Documentation/networking/xfrm_sysctl.rst | 7 +++ include/net/netns/xfrm.h | 1 + net/xfrm/Kconfig | 10 ++++ net/xfrm/xfrm_sysctl.c | 20 +++++++ net/xfrm/xfrm_user.c | 76 +++++++++++++++++++++--- 5 files changed, 105 insertions(+), 9 deletions(-)(quoted diff) +0
-0
b/Documentation/networking/xfrm_sysctl.rstindex47b9bbdd0179..26432b0ff3ac100644Documentation/networking/xfrm_sysctl.rst +7
-0@@ -9,3 +9,10 @@ XFRM Syscall xfrm_acq_expires - INTEGER default 30 - hard timeout in seconds for acquire requests + +xfrm_redact_secret - INTEGER + A toggle to redact xfrm SA's secret to userspace. + When true the kernel, netlink message will redact SA secret + to userspace. This is part of FIPS 140-2 requirement. + Once the value is set to true, either at compile or at run time, + it can not be set to false.include/net/netns/xfrm.h +1
-0@@ -64,6 +64,7 @@ struct netns_xfrm {u32 sysctl_aevent_rseqth;int sysctl_larval_drop;u32 sysctl_acq_expires; +u32 sysctl_redact_secret;#ifdef CONFIG_SYSCTL struct ctl_table_header *sysctl_hdr;#endif net/xfrm/Kconfig +10
-0@@ -91,6 +91,16 @@ config XFRM_ESP select CRYPTO_SEQIV select CRYPTO_SHA256 +config XFRM_REDACT_SECRET + bool "Redact xfrm SA secret in netlink message" + depends on SYSCTL + default n + help + Enable XFRM SA secret redact in the netlink message. + Redacting secret is a FIPS 140-2 requirement. + Once enabled at compile, the value can not be set to false on + a running system. + config XFRM_IPCOMP tristate select XFRM_ALGOnet/xfrm/xfrm_sysctl.c +20
-0@@ -4,15 +4,25 @@#include <net/net_namespace.h> #include <net/xfrm.h> +#ifdef CONFIG_SYSCTL +#ifdef CONFIG_XFRM_REDACT_SECRET +#define XFRM_REDACT_SECRET 1 +#else +#define XFRM_REDACT_SECRET 0 +#endif +#endif +static void __net_init __xfrm_sysctl_init (struct net *net) { net->xfrm.sysctl_aevent_etime =XFRM_AE_ETIME ; net->xfrm.sysctl_aevent_rseqth =XFRM_AE_SEQT_SIZE ; net->xfrm.sysctl_larval_drop =1 ; net->xfrm.sysctl_acq_expires =30 ; + net->xfrm.sysctl_redact_secret =XFRM_REDACT_SECRET ; } #ifdef CONFIG_SYSCTL + static struct ctl_table xfrm_table[] = { { .procname = "xfrm_aevent_etime",@@ -38,6 +48,15 @@ static struct ctl_table xfrm_table[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "xfrm_redact_secret", + .maxlen = sizeof(u32), + .mode = 0644, + /* only handle a transition from "0" to "1" */ + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ONE, + .extra2 = SYSCTL_ONE, + }, {} };@@ -54,6 +73,7 @@ int __net_init xfrm_sysctl_init(struct net *net) table[1 ].data = &net->xfrm.sysctl_aevent_rseqth; table[2 ].data = &net->xfrm.sysctl_larval_drop; table[3 ].data = &net->xfrm.sysctl_acq_expires; + table[4 ].data = &net->xfrm.sysctl_redact_secret;/* Don't export sysctls to unprivileged users */ if (net->user_ns != &init_user_ns)net/xfrm/xfrm_user.c +7
-3@@ -848,21 +848,78 @@ static int copy_user_offload(struct xfrm_state_offload *xso, struct sk_buff *skb return 0; } -static int copy_to_user_auth (struct xfrm_algo_auth *auth,struct sk_buff *skb) +static int copy_to_user_auth(u32 redact_secret, struct xfrm_algo_auth *auth, + struct sk_buff *skb) {struct xfrm_algo *algo; +struct xfrm_algo_auth *ap;struct nlattr *nla; nla =nla_reserve (skb,XFRMA_ALG_AUTH ,sizeof (*algo) + (auth->alg_key_len +7 ) /8 );if (!nla)return -EMSGSIZE ; - algo =nla_data (nla);strncpy (algo->alg_name, auth->alg_name,sizeof (algo->alg_name)); -memcpy (algo->alg_key, auth->alg_key, (auth->alg_key_len +7 ) /8 ); + +if (redact_secret && auth->alg_key_len) +memset (algo->alg_key,0 , (auth->alg_key_len +7 ) /8 ); +else +memcpy (algo->alg_key, auth->alg_key, + (auth->alg_key_len +7 ) /8 ); algo->alg_key_len = auth->alg_key_len;
Quoted 8 lines
net/xfrm/xfrm_user.c static int copy_user_offload(struct xfrm_state_offload *xso, struct sk_buff *skb · line 877
Quoted 6 lines
net/xfrm/xfrm_user.c +6
-0+ nla =nla_reserve (skb,XFRMA_ALG_AUTH_TRUNC ,xfrm_alg_auth_len (auth)); +if (!nla) +return -EMSGSIZE ; + ap =nla_data (nla); +memcpy (ap, auth,sizeof (struct xfrm_algo_auth )); +if (redact_secret)You test for
auth->alg_key_lenabove. Shouldn't there such a check here too?
It is a good idea add checks before all memset calls. I will send a new version out soon.
thanks,
-antony
PATCH v2 1/1 xfrm: add /proc/sys/core/net/xfrm_redact_secret
In reply to Antony Antonywhen enabled, 1, redact XFRM SA secret in the netlink response to xfrm_get_sa() or dump all sa.
e.g
echo 1 > /proc/sys/net/core/xfrm_redact_secret
ip xfrm state
src 172.16.1.200 dst 172.16.1.100
proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96
the aead secret is redacted.
/proc/sys/core/net/xfrm_redact_secret is a toggle.
Once enabled, either at compile or via proc, it can not be disabled. Redacting secret is a FIPS 140-2 requirement.
---
---v1->v2
- add size checks before memset calls
Documentation/networking/xfrm_sysctl.rst | 7 +++ include/net/netns/xfrm.h | 1 + net/xfrm/Kconfig | 10 ++++ net/xfrm/xfrm_sysctl.c | 20 +++++++ net/xfrm/xfrm_user.c | 76 +++++++++++++++++++++--- 5 files changed, 105 insertions(+), 9 deletions(-)
Documentation/networking/xfrm_sysctl.rst +7 -0
@@ -9,3 +9,10 @@ XFRM Syscall xfrm_acq_expires - INTEGER default 30 - hard timeout in seconds for acquire requests + +xfrm_redact_secret - INTEGER + A toggle to redact xfrm SA's secret to userspace. + When true the kernel, netlink message will redact SA secret + to userspace. This is part of FIPS 140-2 requirement. + Once the value is set to true, either at compile or at run time, + it can not be set to false.
include/net/netns/xfrm.h +1 -0
@@ -64,6 +64,7 @@ struct netns_xfrm {u32 sysctl_aevent_rseqth;int sysctl_larval_drop;u32 sysctl_acq_expires; +u32 sysctl_redact_secret;#ifdef CONFIG_SYSCTL struct ctl_table_header *sysctl_hdr;#endif
net/xfrm/Kconfig +10 -0
@@ -91,6 +91,16 @@ config XFRM_ESP select CRYPTO_SEQIV select CRYPTO_SHA256 +config XFRM_REDACT_SECRET + bool "Redact xfrm SA secret in netlink message" + depends on SYSCTL + default n + help + Enable XFRM SA secret redact in the netlink message. + Redacting secret is a FIPS 140-2 requirement. + Once enabled at compile, the value can not be set to false on + a running system. + config XFRM_IPCOMP tristate select XFRM_ALGO
net/xfrm/xfrm_sysctl.c +20 -0
@@ -4,15 +4,25 @@#include <net/net_namespace.h> #include <net/xfrm.h> +#ifdef CONFIG_SYSCTL +#ifdef CONFIG_XFRM_REDACT_SECRET +#define XFRM_REDACT_SECRET 1 +#else +#define XFRM_REDACT_SECRET 0 +#endif +#endif +static void __net_init __xfrm_sysctl_init (struct net *net) { net->xfrm.sysctl_aevent_etime =XFRM_AE_ETIME ; net->xfrm.sysctl_aevent_rseqth =XFRM_AE_SEQT_SIZE ; net->xfrm.sysctl_larval_drop =1 ; net->xfrm.sysctl_acq_expires =30 ; + net->xfrm.sysctl_redact_secret =XFRM_REDACT_SECRET ; } #ifdef CONFIG_SYSCTL + static struct ctl_table xfrm_table[] = { { .procname = "xfrm_aevent_etime",
@@ -38,6 +48,15 @@ static struct ctl_table xfrm_table[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "xfrm_redact_secret", + .maxlen = sizeof(u32), + .mode = 0644, + /* only handle a transition from "0" to "1" */ + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ONE, + .extra2 = SYSCTL_ONE, + }, {} };
@@ -54,6 +73,7 @@ int __net_init xfrm_sysctl_init(struct net *net) table[1 ].data = &net->xfrm.sysctl_aevent_rseqth; table[2 ].data = &net->xfrm.sysctl_larval_drop; table[3 ].data = &net->xfrm.sysctl_acq_expires; + table[4 ].data = &net->xfrm.sysctl_redact_secret;/* Don't export sysctls to unprivileged users */ if (net->user_ns != &init_user_ns)
net/xfrm/xfrm_user.c +67 -9
114 lines not on this page · raw message
Signature · 1 line
2.20.1
Jakub Kicinski
maintainerQuoted 3 lines · On Thu, 20 Aug 2020 14:04:53 +0200 Antony Antony wrote:
---
Signed-off-by Antony Antony <[email protected]>
A warning here - anything after --- will be cut off by git when applying the patch. Perhaps you could resend the patch without it to save Steffen manual work?
Le 20/08/2020 à 14:04, Antony Antony a écrit :
[snip]
net/xfrm/xfrm_sysctl.c static struct ctl_table xfrm_table[] = { · line 58
Quoted 12 lines
net/xfrm/xfrm_sysctl.c +8
-0@@ -38,6 +48,15 @@ static struct ctl_table xfrm_table[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "xfrm_redact_secret", + .maxlen = sizeof(u32), + .mode = 0644, +/* only handle a transition from "0" to "1" */ + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ONE, + .extra2 = SYSCTL_ONE,
nit for the v3: the '=' of the last two lines is aligned with spaces while the first lines use tabs.
PATCH v3 1/1 xfrm: add /proc/sys/core/net/xfrm_redact_secret
In reply to Antony Antonywhen enabled, 1, redact XFRM SA secret in the netlink response to xfrm_get_sa() or dump all sa.
e.g
echo 1 > /proc/sys/net/core/xfrm_redact_secret
ip xfrm state
src 172.16.1.200 dst 172.16.1.100
proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96
the aead secret is redacted.
/proc/sys/core/net/xfrm_redact_secret is a toggle.
Once enabled, either at compile or via proc, it can not be disabled. Redacting secret is a FIPS 140-2 requirement.
v1->v2
- add size checks before memset callsv1->v3
- replace spaces with tabs for consistancy
--- Documentation/networking/xfrm_sysctl.rst | 7 +++ include/net/netns/xfrm.h | 1 + net/xfrm/Kconfig | 10 ++++ net/xfrm/xfrm_sysctl.c | 20 +++++++ net/xfrm/xfrm_user.c | 76 +++++++++++++++++++++--- 5 files changed, 105 insertions(+), 9 deletions(-)
Documentation/networking/xfrm_sysctl.rst +7 -0
@@ -9,3 +9,10 @@ XFRM Syscall xfrm_acq_expires - INTEGER default 30 - hard timeout in seconds for acquire requests + +xfrm_redact_secret - INTEGER + A toggle to redact xfrm SA's secret to userspace. + When true the kernel, netlink message will redact SA secret + to userspace. This is part of FIPS 140-2 requirement. + Once the value is set to true, either at compile or at run time, + it can not be set to false.
include/net/netns/xfrm.h +1 -0
@@ -64,6 +64,7 @@ struct netns_xfrm {u32 sysctl_aevent_rseqth;int sysctl_larval_drop;u32 sysctl_acq_expires; +u32 sysctl_redact_secret;#ifdef CONFIG_SYSCTL struct ctl_table_header *sysctl_hdr;#endif
net/xfrm/Kconfig +10 -0
@@ -91,6 +91,16 @@ config XFRM_ESP select CRYPTO_SEQIV select CRYPTO_SHA256 +config XFRM_REDACT_SECRET + bool "Redact xfrm SA secret in netlink message" + depends on SYSCTL + default n + help + Enable XFRM SA secret redact in the netlink message. + Redacting secret is a FIPS 140-2 requirement. + Once enabled at compile, the value can not be set to false on + a running system. + config XFRM_IPCOMP tristate select XFRM_ALGO
net/xfrm/xfrm_sysctl.c +20 -0
@@ -4,15 +4,25 @@#include <net/net_namespace.h> #include <net/xfrm.h> +#ifdef CONFIG_SYSCTL +#ifdef CONFIG_XFRM_REDACT_SECRET +#define XFRM_REDACT_SECRET 1 +#else +#define XFRM_REDACT_SECRET 0 +#endif +#endif +static void __net_init __xfrm_sysctl_init (struct net *net) { net->xfrm.sysctl_aevent_etime =XFRM_AE_ETIME ; net->xfrm.sysctl_aevent_rseqth =XFRM_AE_SEQT_SIZE ; net->xfrm.sysctl_larval_drop =1 ; net->xfrm.sysctl_acq_expires =30 ; + net->xfrm.sysctl_redact_secret =XFRM_REDACT_SECRET ; } #ifdef CONFIG_SYSCTL + static struct ctl_table xfrm_table[] = { { .procname = "xfrm_aevent_etime",
@@ -38,6 +48,15 @@ static struct ctl_table xfrm_table[] = { .mode = 0644, .proc_handler = proc_dointvec }, + { + .procname = "xfrm_redact_secret", + .maxlen = sizeof(u32), + .mode = 0644, + /* only handle a transition from "0" to "1" */ + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ONE, + .extra2 = SYSCTL_ONE, + }, {} };
@@ -54,6 +73,7 @@ int __net_init xfrm_sysctl_init(struct net *net) table[1 ].data = &net->xfrm.sysctl_aevent_rseqth; table[2 ].data = &net->xfrm.sysctl_larval_drop; table[3 ].data = &net->xfrm.sysctl_acq_expires; + table[4 ].data = &net->xfrm.sysctl_redact_secret;/* Don't export sysctls to unprivileged users */ if (net->user_ns != &init_user_ns)
net/xfrm/xfrm_user.c +67 -9
114 lines not on this page · raw message
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Antony Antony <[email protected]>
Date: Thu, 20 Aug 2020 20:35:49 +0200
Quoted 1 line
Redacting secret is a FIPS 140-2 requirement.
Why not control this via the kernel lockdown mode rather than making an ad-hoc API for this?
Quoted 7 lines · David Miller
From: Antony Antony <[email protected]>
Date: Thu, 20 Aug 2020 20:35:49 +0200Quoted 1 line
Redacting secret is a FIPS 140-2 requirement.
Why not control this via the kernel lockdown mode rather than making an ad-hoc API for this?
Let me try to use kernel lockdown mode. thanks for the idea.
From a quick googling I guess it would be part of "lockdown= confidentiality".
I wonder if kernel lockdown would allow disabling just this one feature independent of other lockdowns.
-antony
Hi David,
Quoted 6 lines · Antony Antony
Quoted 5 lines · David Miller
From: Antony Antony <[email protected]>
Date: Thu, 20 Aug 2020 20:35:49 +0200Quoted 1 line
Redacting secret is a FIPS 140-2 requirement.
Quoted 7 lines
Quoted 2 lines
Why not control this via the kernel lockdown mode rather than making an ad-hoc API for this?
Let me try to use kernel lockdown mode. thanks for the idea.
From a quick googling I guess it would be part of "lockdown= confidentiality".
I wonder if kernel lockdown would allow disabling just this one feature independent of other lockdowns.
I looked at kernel lockdown mode code and documentation. I am thinking xfrm_redact is probably not a kernel lockdown mode feature. There is no kernel lockdown setting per net namespace.
During an initial discussions of xfrm_redact we thought per namespace would be useful in some use cases.
If there is a way to set lockdown per net namespace it would be better than /proc/sys/core/net/xfrm_redact_secret.
David Miller
maintainerFrom: Antony Antony <[email protected]>
Date: Thu, 27 Aug 2020 22:15:36 +0200
Quoted 2 lines
If there is a way to set lockdown per net namespace it would be better than
/proc/sys/core/net/xfrm_redact_secret.
Lockmode is a whole system attribute.
As should any facility that restricts access to keying information stored inside of the kernel.
PATCH 1/1 xfrm: redact SA secret with lockdown confidentiality
In reply to Antony Antonyredact XFRM SA secret in the netlink response to xfrm_get_sa() or dumpall sa.
Enable this at build time and set kernel lockdown to confidentiality.
e.g.
cat /sys/kernel/security/lockdown
none integrity [confidentiality]
ip xfrm state
src 172.16.1.200 dst 172.16.1.100
proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96
note: the aead secret is redacted. Redacting secret is also a FIPS 140-2 requirement.
v1->v2
- add size checks before memset callsv2->v3
- replace spaces with tabs for consistencyv3->v4
- use kernel lockdown instead of a /proc setting
--- include/linux/security.h | 1 + net/xfrm/Kconfig | 9 +++++ net/xfrm/xfrm_user.c | 76 ++++++++++++++++++++++++++++++++++++---- security/security.c | 1 + 4 files changed, 80 insertions(+), 7 deletions(-)
include/linux/security.h +1 -0
@@ -126,6 +126,7 @@ enum lockdown_reason {LOCKDOWN_PERF ,LOCKDOWN_TRACEFS ,LOCKDOWN_XMON_RW , +LOCKDOWN_XFRM_SECRET , LOCKDOWN_CONFIDENTIALITY_MAX, };
net/xfrm/Kconfig +9 -0
@@ -91,6 +91,15 @@ config XFRM_ESP select CRYPTO_SEQIV select CRYPTO_SHA256 +config XFRM_REDACT_SECRET + bool "Redact xfrm SA secret" + depends on XFRM && SECURITY_LOCKDOWN_LSM + default n + help + Redats XFRM SA secret in the netlink message to user space. + Redacting secret is also a FIPS 140-2 requirement. + e.g. ip xfrm state; will show redacted the SA secret. + config XFRM_IPCOMP tristate select XFRM_ALGO
net/xfrm/xfrm_user.c +69 -7
116 lines not on this page · raw message
security/security.c +1 -0
@@ -64,6 +64,7 @@ const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_PERF] = "unsafe use of perf", [LOCKDOWN_TRACEFS] = "use of tracefs", [LOCKDOWN_XMON_RW] = "xmon read and write access", + [LOCKDOWN_XFRM_SECRET] = "xfrm SA secret", [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", };
Signature · 1 line
2.20.1
Steffen Klassert
maintainerRe: [PATCH] xfrm: redact SA secret with lockdown confidentiality
Quoted 3 lines · Antony Antony
redact XFRM SA secret in the netlink response to
xfrm_get_sa()or dumpall sa.
Enable this at build time and set kernel lockdown to confidentiality.
Wouldn't it be better to enable is at boot or runtime? This defaults to 'No' at build time, so distibutions will not compile it in. That means that noone who uses a kernel that comes with a Linux distribution can use that.
Re: [PATCH] xfrm: redact SA secret with lockdown confidentiality
Quoted 9 lines · Steffen Klassert
Quoted 3 lines · Antony Antony
redact XFRM SA secret in the netlink response to
xfrm_get_sa()or dumpall sa.
Enable this at build time and set kernel lockdown to confidentiality.Wouldn't it be better to enable is at boot or runtime? This defaults to 'No' at build time, so distibutions will not compile it in. That means that noone who uses a kernel that comes with a Linux distribution can use that.
It is a good idea. I will send new version soon.
thanks,
-antony
PATCH v5 1/1 xfrm: redact SA secret with lockdown confidentiality
In reply to Antony Antonyredact XFRM SA secret in the netlink response to xfrm_get_sa() or dumpall sa.
Enable lockdown, confidentiality mode, at boot or at run time.
e.g. when enabled:
cat /sys/kernel/security/lockdown
none integrity [confidentiality]
ip xfrm state
src 172.16.1.200 dst 172.16.1.100
proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96
note: the aead secret is redacted. Redacting secret is also a FIPS 140-2 requirement.
v1->v2
- add size checks before memset callsv2->v3
- replace spaces with tabs for consistencyv3->v4
- use kernel lockdown instead of a /proc settingv4->v5
- remove kconfig option
--- include/linux/security.h | 1 + net/xfrm/xfrm_user.c | 74 ++++++++++++++++++++++++++++++++++++---- security/security.c | 1 + 3 files changed, 69 insertions(+), 7 deletions(-)
include/linux/security.h +1 -0
@@ -127,6 +127,7 @@ enum lockdown_reason {LOCKDOWN_PERF ,LOCKDOWN_TRACEFS ,LOCKDOWN_XMON_RW , +LOCKDOWN_XFRM_SECRET , LOCKDOWN_CONFIDENTIALITY_MAX, };
net/xfrm/xfrm_user.c +67 -7
108 lines not on this page · raw message
security/security.c +1 -0
@@ -65,6 +65,7 @@ const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_PERF] = "unsafe use of perf", [LOCKDOWN_TRACEFS] = "use of tracefs", [LOCKDOWN_XMON_RW] = "xmon read and write access", + [LOCKDOWN_XFRM_SECRET] = "xfrm SA secret", [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", };
Signature · 1 line
2.20.1
Steffen Klassert
maintainerRe: [PATCH ipsec-next v5] xfrm: redact SA secret with lockdown confidentiality
Quoted 26 lines · Antony Antony
redact XFRM SA secret in the netlink response to
xfrm_get_sa()or dumpall sa.
Enable lockdown, confidentiality mode, at boot or at run time.e.g. when enabled:
cat/sys/kernel/security/lockdown
none integrity [confidentiality]ip xfrm state
src 172.16.1.200 dst 172.16.1.100proto esp spi 0x00000002 reqid 2 mode tunnel replay-window 0 aead rfc4106(gcm(aes)) 0x0000000000000000000000000000000000000000 96note: the aead secret is redacted. Redacting secret is also a FIPS 140-2 requirement.
v1->v2
- add size checks before memset callsv2->v3
- replace spaces with tabs for consistencyv3->v4
- use kernel lockdown instead of a /proc settingv4->v5
- remove kconfig option
Quoted 7 lines
Reviewed-by Stephan Mueller <[email protected]>Signed-off-by Antony Antony <[email protected]>--- include/linux/security.h | 1 + net/xfrm/xfrm_user.c | 74 ++++++++++++++++++++++++++++++++++++---- security/security.c | 1 + 3 files changed, 69 insertions(+), 7 deletions(-)
I'm ok with this and I plan to apply it to ipsec-next if I do not see objections from the LSM people.