net: diag: fix a potential security issue
Subsystems (3)
cover net: diag: fix a potential security issue
This patch is to void the potential security issue that the family or protocol modules are autoloaded when requesting _diag module by not requesting _diag module if the family or protocol is not added or registered in sock_diag and inet_diag.
As the repost of the patch '[PATCH net] sock_diag: request _diag module only when the family or proto has been registered', this patchset fixes the compiling errors when INET is not set, and also split into two patches to make it clear to review.
Xin Long (2):
sock_diag: request _diag module only when the family has been
registered
inet_diag: request _diag module only when the proto has been
registered
include/linux/net.h | 1 + include/net/protocol.h | 1 + net/core/sock_diag.c | 21 +++++++++++++-------- net/ipv4/inet_diag.c | 3 ++- net/ipv4/protocol.c | 6 ++++++ net/socket.c | 5 +++++ 6 files changed, 28 insertions(+), 9 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 sock_diag: request _diag module only when the family has been registered
Now when using 'ss' in iproute, kernel would try to load all _diag modules. It causes the corresponding family or proto modules to be loaded as well.
Like after 'ss -a', sctp, dccp, af_packet(if it works as a moudle) will be loaded.
As these family or proto modules are loaded unexpectly, this might have some security implications.
This patch is to introduce sock_diag_request_module() in sock_diag where we only request _diag module when it's corresponding family has been registered. The fix for inet_diag will be done in later patch.
Note that we can't just load _diag module without the family or proto loaded, as some symbols in _diag module are from the family or proto moudle.
--- include/linux/net.h | 1 + net/core/sock_diag.c | 21 +++++++++++++-------- net/socket.c | 5 +++++ 3 files changed, 19 insertions(+), 8 deletions(-)
include/linux/net.h +1 -0
@@ -225,6 +225,7 @@ enum {int sock_wake_async (struct socket_wq *sk_wq,int how,int band);int sock_register (const struct net_proto_family *fam);void sock_unregister (int family); +bool sock_is_registered (int family);int __sock_create (struct net *net,int family,int type,int proto,struct socket **res,int kern);int sock_create (int family,int type,int proto,struct socket **res);
net/core/sock_diag.c +13 -8
@@ -207,6 +207,15 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld) }EXPORT_SYMBOL_GPL (sock_diag_unregister); +static int sock_diag_request_module (int family) +{ +if (!sock_is_registered (family)) +return -ENOENT ; + +return request_module ("net-pf-%d-proto-%d-type-%d" ,PF_NETLINK , +NETLINK_SOCK_DIAG , family); +} +static int __sock_diag_cmd (struct sk_buff *skb,struct nlmsghdr *nlh) {int err;
@@ -220,8 +229,7 @@ static int __sock_diag_cmd(struct sk_buff *skb, struct nlmsghdr *nlh)return -EINVAL ;if (sock_diag_handlers[req->sdiag_family] ==NULL ) -request_module ("net-pf-%d-proto-%d-type-%d" ,PF_NETLINK , -NETLINK_SOCK_DIAG , req->sdiag_family); +sock_diag_request_module (req->sdiag_family);mutex_lock (&sock_diag_table_mutex); hndl = sock_diag_handlers[req->sdiag_family];
@@ -247,8 +255,7 @@ static int sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,case TCPDIAG_GETSOCK :case DCCPDIAG_GETSOCK :if (inet_rcv_compat ==NULL ) -request_module ("net-pf-%d-proto-%d-type-%d" ,PF_NETLINK , -NETLINK_SOCK_DIAG ,AF_INET ); +sock_diag_request_module (AF_INET );mutex_lock (&sock_diag_table_mutex);if (inet_rcv_compat !=NULL )
@@ -281,14 +288,12 @@ static int sock_diag_bind(struct net *net, int group)case SKNLGRP_INET_TCP_DESTROY :case SKNLGRP_INET_UDP_DESTROY :if (!sock_diag_handlers[AF_INET ]) -request_module ("net-pf-%d-proto-%d-type-%d" ,PF_NETLINK , -NETLINK_SOCK_DIAG ,AF_INET ); +sock_diag_request_module (AF_INET );break ;case SKNLGRP_INET6_TCP_DESTROY :case SKNLGRP_INET6_UDP_DESTROY :if (!sock_diag_handlers[AF_INET6 ]) -request_module ("net-pf-%d-proto-%d-type-%d" ,PF_NETLINK , -NETLINK_SOCK_DIAG ,AF_INET ); +sock_diag_request_module (AF_INET );break ; }return 0 ;
net/socket.c +5 -0
@@ -2590,6 +2590,11 @@ void sock_unregister(int family) }EXPORT_SYMBOL (sock_unregister); +bool sock_is_registered (int family) +{ +return family <NPROTO &&rcu_access_pointer (net_families[family]); +} +static int __init sock_init (void ) {int err;
Signature · 1 line
2.1.0
PATCH 2/2 inet_diag: request _diag module only when the proto has been registered
The patch 'sock_diag: request _diag module only when the family has been registered' fixed a security issue for sock_diag, the same fix is needed for inet_diag module when requesting _diag module.
--- include/net/protocol.h | 1 + net/ipv4/inet_diag.c | 3 ++- net/ipv4/protocol.c | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-)
include/net/protocol.h +1 -0
@@ -103,6 +103,7 @@ extern struct inet6_protocol __rcu *inet6_protos[MAX_INET_PROTOS];int inet_add_protocol (const struct net_protocol *prot,unsigned char num);int inet_del_protocol (const struct net_protocol *prot,unsigned char num); +bool inet_proto_is_added (unsigned char num);int inet_add_offload (const struct net_offload *prot,unsigned char num);int inet_del_offload (const struct net_offload *prot,unsigned char num);void inet_register_protosw (struct inet_protosw *p);
net/ipv4/inet_diag.c +2 -1
@@ -27,6 +27,7 @@#include <net/inet_hashtables.h> #include <net/inet_timewait_sock.h> #include <net/inet6_hashtables.h> +#include <net/protocol.h> #include <net/netlink.h> #include <linux/inet.h>
@@ -52,7 +53,7 @@ static DEFINE_MUTEX(inet_diag_table_mutex);static const struct inet_diag_handler *inet_diag_lock_handler (int proto) { -if (!inet_diag_table[proto]) +if (!inet_diag_table[proto] &&inet_proto_is_added (proto))request_module ("net-pf-%d-proto-%d-type-%d-%d" ,PF_NETLINK ,NETLINK_SOCK_DIAG ,AF_INET , proto);
net/ipv4/protocol.c +6 -0
@@ -77,3 +77,9 @@ int inet_del_offload(const struct net_offload *prot, unsigned char protocol)return ret; }EXPORT_SYMBOL (inet_del_offload); + +bool inet_proto_is_added (unsigned char protocol) +{ +return !!rcu_access_pointer (inet_protos[protocol]); +} +EXPORT_SYMBOL (inet_proto_is_added);
Signature · 1 line
2.1.0
David Miller
maintainerFrom: Xin Long <[email protected]>
Date: Thu, 19 Oct 2017 15:32:23 +0800
Quoted 9 lines
This patch is to void the potential security issue that the family or protocol modules are autoloaded when requesting
_diagmodule by not requesting_diagmodule if the family or protocol is not added or registered insock_diagandinet_diag.As the repost of the patch '[PATCH net]
sock_diag: request_diagmodule only when the family or proto has been registered', this patchset fixes the compiling errors when INET is not set, and also split into two patches to make it clear to review.
This makes no sense to me.
Any user can just open a socket() in the appropriate protocol family to cause the module to be loaded.
If someone wants modules to not be loaded, block them using traditional module loading infrastructure mechanisms. Or don't load the module at all.
Sorry I am not applying this.
Quoted 34 lines · Xin Long
Quoted 16 lines · David Miller
From: Xin Long <[email protected]>
Date: Thu, 19 Oct 2017 15:32:23 +0800Quoted 9 lines
This patch is to void the potential security issue that the family or protocol modules are autoloaded when requesting
_diagmodule by not requesting_diagmodule if the family or protocol is not added or registered insock_diagandinet_diag.As the repost of the patch '[PATCH net]
sock_diag: request_diagmodule only when the family or proto has been registered', this patchset fixes the compiling errors when INET is not set, and also split into two patches to make it clear to review.This makes no sense to me.
Quoted 8 lines
Any user can just open a
socket()in the appropriate protocol family to cause the module to be loaded.If someone wants modules to not be loaded, block them using traditional module loading infrastructure mechanisms. Or don't load the module at all.
Sorry I am not applying this.
Hi David,
I'm still thinking it's not good after 'ss', sctp, dccp,
af_packet... are just loaded, in which case, no one actually open any socket with these family or proto.
Quoted 7 lines
I talked with Marcelo before, one scenario as he said:
Imagine a customer generates a sosreport on their system, and with that, it loads sctp module. From then on, if their firewall doesn't block incoming packets for sctp, they may be prone to some remotely triggerable issue on sctp code, without even actually using sctp.
For that reason, we have disabled autoloading of SCTP. ( removing the
MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132"); MODULE_ALIAS("net-pf-" __stringify(PF_INET6) "-proto-132");
)
root must modprobe the module before it is accessible.
However inet_diag is a way to have the module loaded anyway.
This is why I like your patch Xin.
David is only saying that your patch alone is not enough to prevent a user to use socket() to autoload SCTP.
Quoted 50 lines · Eric Dumazet
Quoted 34 lines · Xin Long
Quoted 16 lines · David Miller
From: Xin Long <[email protected]>
Date: Thu, 19 Oct 2017 15:32:23 +0800Quoted 9 lines
This patch is to void the potential security issue that the family or protocol modules are autoloaded when requesting
_diagmodule by not requesting_diagmodule if the family or protocol is not added or registered insock_diagandinet_diag.As the repost of the patch '[PATCH net]
sock_diag: request_diagmodule only when the family or proto has been registered', this patchset fixes the compiling errors when INET is not set, and also split into two patches to make it clear to review.This makes no sense to me.
Quoted 8 lines
Any user can just open a
socket()in the appropriate protocol family to cause the module to be loaded.If someone wants modules to not be loaded, block them using traditional module loading infrastructure mechanisms. Or don't load the module at all.
Sorry I am not applying this.
Hi David,
I'm still thinking it's not good after 'ss', sctp, dccp,
af_packet... are just loaded, in which case, no one actually open any socket with these family or proto.Quoted 7 lines
I talked with Marcelo before, one scenario as he said:
Imagine a customer generates a sosreport on their system, and with that, it loads sctp module. From then on, if their firewall doesn't block incoming packets for sctp, they may be prone to some remotely triggerable issue on sctp code, without even actually using sctp.
For that reason, we have disabled autoloading of SCTP. ( removing the
MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132");MODULE_ALIAS("net-pf-" __stringify(PF_INET6) "-proto-132");
)
root must modprobe the module before it is accessible.
Quoted 6 lines
However
inet_diagis a way to have the module loaded anyway.This is why I like your patch Xin.
David is only saying that your patch alone is not enough to prevent a user to use
socket()to autoload SCTP.
Using socket() to autoload SCTP should be fine, cause users would use SCTP, no ?
"ss" doesn't mean users intend to use SCTP, "ss" may make users not aware that SCTP module would be loaded, unlike socket(SCTP).
Quoted 55 lines · Xin Long
Quoted 54 lines · Eric Dumazet
Quoted 34 lines · Xin Long
Quoted 16 lines · David Miller
From: Xin Long <[email protected]>
Date: Thu, 19 Oct 2017 15:32:23 +0800Quoted 9 lines
This patch is to void the potential security issue that the family or protocol modules are autoloaded when requesting
_diagmodule by not requesting_diagmodule if the family or protocol is not added or registered insock_diagandinet_diag.As the repost of the patch '[PATCH net]
sock_diag: request_diagmodule only when the family or proto has been registered', this patchset fixes the compiling errors when INET is not set, and also split into two patches to make it clear to review.This makes no sense to me.
Quoted 8 lines
Any user can just open a
socket()in the appropriate protocol family to cause the module to be loaded.If someone wants modules to not be loaded, block them using traditional module loading infrastructure mechanisms. Or don't load the module at all.
Sorry I am not applying this.
Hi David,
I'm still thinking it's not good after 'ss', sctp, dccp,
af_packet... are just loaded, in which case, no one actually open any socket with these family or proto.Quoted 7 lines
I talked with Marcelo before, one scenario as he said:
Imagine a customer generates a sosreport on their system, and with that, it loads sctp module. From then on, if their firewall doesn't block incoming packets for sctp, they may be prone to some remotely triggerable issue on sctp code, without even actually using sctp.
For that reason, we have disabled autoloading of SCTP. ( removing the
MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132");MODULE_ALIAS("net-pf-" __stringify(PF_INET6) "-proto-132");
)
root must modprobe the module before it is accessible.However
inet_diagis a way to have the module loaded anyway.This is why I like your patch Xin.
Quoted 7 lines
Quoted 2 lines
David is only saying that your patch alone is not enough to prevent a user to use
socket()to autoload SCTP.Using
socket()to autoload SCTP should be fine, cause users would use SCTP, no ?"ss" doesn't mean users intend to use SCTP, "ss" may make users not aware that SCTP module would be loaded, unlike socket(SCTP).
Your changelog mentions a security issue.
How have you prevented user using socket() to bypass your 'security' feature ?
If you have not yet, this security claim is simply false.
Quoted 61 lines · Eric Dumazet
Quoted 60 lines · Xin Long
Quoted 50 lines · Eric Dumazet
Quoted 34 lines · Xin Long
Quoted 16 lines · David Miller
From: Xin Long <[email protected]>
Date: Thu, 19 Oct 2017 15:32:23 +0800Quoted 9 lines
This patch is to void the potential security issue that the family or protocol modules are autoloaded when requesting
_diagmodule by not requesting_diagmodule if the family or protocol is not added or registered insock_diagandinet_diag.As the repost of the patch '[PATCH net]
sock_diag: request_diagmodule only when the family or proto has been registered', this patchset fixes the compiling errors when INET is not set, and also split into two patches to make it clear to review.This makes no sense to me.
Quoted 8 lines
Any user can just open a
socket()in the appropriate protocol family to cause the module to be loaded.If someone wants modules to not be loaded, block them using traditional module loading infrastructure mechanisms. Or don't load the module at all.
Sorry I am not applying this.
Hi David,
I'm still thinking it's not good after 'ss', sctp, dccp,
af_packet... are just loaded, in which case, no one actually open any socket with these family or proto.Quoted 7 lines
I talked with Marcelo before, one scenario as he said:
Imagine a customer generates a sosreport on their system, and with that, it loads sctp module. From then on, if their firewall doesn't block incoming packets for sctp, they may be prone to some remotely triggerable issue on sctp code, without even actually using sctp.
For that reason, we have disabled autoloading of SCTP. ( removing the
MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132");MODULE_ALIAS("net-pf-" __stringify(PF_INET6) "-proto-132");
)
root must modprobe the module before it is accessible.Quoted 6 lines
However
inet_diagis a way to have the module loaded anyway.This is why I like your patch Xin.
David is only saying that your patch alone is not enough to prevent a user to use
socket()to autoload SCTP.Using
socket()to autoload SCTP should be fine, cause users would use SCTP, no ?
Quoted 7 lines
Quoted 2 lines
"ss" doesn't mean users intend to use SCTP, "ss" may make users not aware that SCTP module would be loaded, unlike socket(SCTP).
Your changelog mentions a security issue.
How have you prevented user using
socket()to bypass your 'security' feature ?
I think the hook in __sock_create():
err = security_socket_create(family, type, protocol, kern);
if (err)
return err;could work for this, no ?
like, users add security rules to not allow to create SCTP socket (namely, not allow sctp module to be loaded)
But, 'ss' could bypass it to load SCTP module.
In this way, can this patch be considered a security issue ?
Quoted 2 lines
If you have not yet, this security claim is simply false.
Quoted 69 lines · Xin Long
Quoted 61 lines · Eric Dumazet
Quoted 60 lines · Xin Long
Quoted 50 lines · Eric Dumazet
Quoted 34 lines · Xin Long
Quoted 16 lines · David Miller
From: Xin Long <[email protected]>
Date: Thu, 19 Oct 2017 15:32:23 +0800Quoted 9 lines
This patch is to void the potential security issue that the family or protocol modules are autoloaded when requesting
_diagmodule by not requesting_diagmodule if the family or protocol is not added or registered insock_diagandinet_diag.As the repost of the patch '[PATCH net]
sock_diag: request_diagmodule only when the family or proto has been registered', this patchset fixes the compiling errors when INET is not set, and also split into two patches to make it clear to review.This makes no sense to me.
Quoted 8 lines
Any user can just open a
socket()in the appropriate protocol family to cause the module to be loaded.If someone wants modules to not be loaded, block them using traditional module loading infrastructure mechanisms. Or don't load the module at all.
Sorry I am not applying this.
Hi David,
I'm still thinking it's not good after 'ss', sctp, dccp,
af_packet... are just loaded, in which case, no one actually open any socket with these family or proto.Quoted 7 lines
I talked with Marcelo before, one scenario as he said:
Imagine a customer generates a sosreport on their system, and with that, it loads sctp module. From then on, if their firewall doesn't block incoming packets for sctp, they may be prone to some remotely triggerable issue on sctp code, without even actually using sctp.
For that reason, we have disabled autoloading of SCTP. ( removing the
MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132");MODULE_ALIAS("net-pf-" __stringify(PF_INET6) "-proto-132");
)
root must modprobe the module before it is accessible.Quoted 6 lines
However
inet_diagis a way to have the module loaded anyway.This is why I like your patch Xin.
David is only saying that your patch alone is not enough to prevent a user to use
socket()to autoload SCTP.Using
socket()to autoload SCTP should be fine, cause users would use SCTP, no ?Quoted 7 lines
Quoted 2 lines
"ss" doesn't mean users intend to use SCTP, "ss" may make users not aware that SCTP module would be loaded, unlike socket(SCTP).
Your changelog mentions a security issue.
How have you prevented user using
socket()to bypass your 'security' feature ?
Quoted 7 lines
I think the hook in
__sock_create():err = security_socket_create(family, type, protocol, kern); if (err) return err;could work for this, no ?
Sorry, Eric, this may not be an inappropriate example, after all security_socket_create is not supposed to do these things. thanks for your review.
Let's just see if David could accept the patches if I will remove the "security claim" from changelog, considering it as an improvement of sock diag.
David ?
Quoted 10 lines
like, users add security rules to not allow to create SCTP socket (namely, not allow sctp module to be loaded)
But, 'ss' could bypass it to load SCTP module.
In this way, can this patch be considered a security issue ?
Quoted 2 lines
If you have not yet, this security claim is simply false.
David Miller
maintainerFrom: Xin Long <[email protected]>
Date: Sat, 21 Oct 2017 14:06:27 +0800
Quoted 5 lines
Imagine a customer generates a sosreport on their system, and with that, it loads sctp module. From then on, if their firewall doesn't block incoming packets for sctp, they may be prone to some remotely triggerable issue on sctp code, without even actually using sctp.
Like I said, if the protocol is so unsafe, block it in the modules.conf file.
Block all "I don't use this" protocols in netfilter.
Otherwise, like I said, any user on their system can open a socket of the indicated protocol.
There are many options.
Furthermore, "ss" should not signal an error because the protocol module happens to not be open yet and as I understand it this is what your patch does since it chooses to not load the module in this situation.
David Miller
maintainerFrom: Xin Long <[email protected]>
Date: Sat, 21 Oct 2017 17:45:09 +0800
Quoted 5 lines
Let's just see if David could accept the patches if I will remove the "security claim" from changelog, considering it as an improvement of sock diag.
David ?
No I won't. See my other response.
Use modules.conf or netfilter rules to block "scary networking protocols" if you are so paranoid about this happening.
Thank you.