net: netlink: filter particular protocols from analyzers
Subsystems (2)
PATCH 1/1 net: netlink: filter particular protocols from analyzers
From: Daniel Borkmann <[email protected]>
Fix finer-grained control and let only a whitelist of allowed netlink protocols pass, in our case related to networking. If later on, other subsystems decide they want to add their protocol as well to the list of allowed protocols they shall simply add it. While at it, we also need to tell what protocol is in use otherwise BPF_S_ANC_PROTOCOL can not pick it up (as it's not filled out).
--- net/netlink/af_netlink.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
net/netlink/af_netlink.c +30 -0
@@ -168,16 +168,43 @@ int netlink_remove_tap(struct netlink_tap *nt) }EXPORT_SYMBOL_GPL (netlink_remove_tap); +static bool netlink_filter_tap (const struct sk_buff *skb) +{ +struct sock *sk = skb->sk; +bool pass = false; + +/* We take the more conservative approach and +* whitelist socket protocols that may pass. +*/ +switch (sk->sk_protocol) { +case NETLINK_ROUTE : +case NETLINK_USERSOCK : +case NETLINK_SOCK_DIAG : +case NETLINK_NFLOG : +case NETLINK_XFRM : +case NETLINK_FIB_LOOKUP : +case NETLINK_NETFILTER : +case NETLINK_GENERIC : + pass = true; +break ; + } + +return pass; +} +static int __netlink_deliver_tap_skb (struct sk_buff *skb,struct net_device *dev) {struct sk_buff *nskb; +struct sock *sk = skb->sk;int ret = -ENOMEM ;dev_hold (dev); nskb =skb_clone (skb,GFP_ATOMIC );if (nskb) { nskb->dev = dev; + nskb->protocol =htons ((u16 ) sk->sk_protocol); + ret =dev_queue_xmit (nskb);if (unlikely (ret >0 )) ret =net_xmit_errno (ret);
@@ -192,6 +219,9 @@ static void __netlink_deliver_tap(struct sk_buff *skb)int ret;struct netlink_tap *tmp; +if (!netlink_filter_tap (skb)) +return ; +list_for_each_entry_rcu (tmp, &netlink_tap_all, list) { ret =__netlink_deliver_tap_skb (skb, tmp->dev);if (unlikely (ret))
Signature · 1 line
1.8.3.1
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Thu, 5 Sep 2013 17:48:47 +0200
Quoted 10 lines
From: Daniel Borkmann <[email protected]>
Fix finer-grained control and let only a whitelist of allowed netlink protocols pass, in our case related to networking. If later on, other subsystems decide they want to add their protocol as well to the list of allowed protocols they shall simply add it. While at it, we also need to tell what protocol is in use otherwise
BPF_S_ANC_PROTOCOLcan not pick it up (as it's not filled out).Signed-off-by Daniel Borkmann <[email protected]>
This takes away functionality that I'd be more interesting in using, namely being able to listen to all netlink protocols using one tap.
Seriously, when I first saw this feature, that was the first way I'd imagine myself using it, as a tcpdump for netlink traffic, all of it.
If I just want to hear all netlink traffic, don't make me be forced to know every single NETLINK_* protocol value and have to open that many sockets just to do so.
It also makes it so that I can't listen to userlevel custom netlink protocols, another minus of filtering.
At the very least, allow an sk_protocol of zero or similar to have this meaning of "everything".
I'm not applying this patch, sorry.
Quoted 28 lines · On Thu, 05 Sep 2013 14:44:42 -0400 (EDT) David Miller <[email protected]>…
From: Daniel Borkmann <[email protected]>
Date: Thu, 5 Sep 2013 17:48:47 +0200Quoted 10 lines
From: Daniel Borkmann <[email protected]>
Fix finer-grained control and let only a whitelist of allowed netlink protocols pass, in our case related to networking. If later on, other subsystems decide they want to add their protocol as well to the list of allowed protocols they shall simply add it. While at it, we also need to tell what protocol is in use otherwise
BPF_S_ANC_PROTOCOLcan not pick it up (as it's not filled out).Signed-off-by Daniel Borkmann <[email protected]>This takes away functionality that I'd be more interesting in using, namely being able to listen to all netlink protocols using one tap.
Seriously, when I first saw this feature, that was the first way I'd imagine myself using it, as a tcpdump for netlink traffic, all of it.
If I just want to hear all netlink traffic, don't make me be forced to know every single NETLINK_* protocol value and have to open that many sockets just to do so.
It also makes it so that I can't listen to userlevel custom netlink protocols, another minus of filtering.
Quoted 8 lines
At the very least, allow an
sk_protocolof zero or similar to have this meaning of "everything".I'm not applying this patch, sorry.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
If you want filtering, why not add BPF (sk_filter) support to this?
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Thu, 5 Sep 2013 11:57:55 -0700
Quoted 1 line
If you want filtering, why not add BPF (
sk_filter) support to this?
That's one idea.
But using sk_protocol is at least consistent with how AF_PACKET does things.
Quoted 9 lines · On Thu, 05 Sep 2013 15:03:41 -0400 (EDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Thu, 5 Sep 2013 11:57:55 -0700Quoted 1 line
If you want filtering, why not add BPF (
sk_filter) support to this?That's one idea.
But using
sk_protocolis at least consistent with howAF_PACKETdoes things.
Why not both.
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Thu, 5 Sep 2013 12:44:37 -0700
Quoted 6 lines
Quoted 3 lines · On Thu, 05 Sep 2013 15:03:41 -0400 (EDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Thu, 5 Sep 2013 11:57:55 -0700
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
If you want filtering, why not add BPF (
sk_filter) support to this?That's one idea.
But using
sk_protocolis at least consistent with howAF_PACKETdoes things.Why not both.
That's fine too.
Quoted 13 lines · David Miller
From: Daniel Borkmann <[email protected]>
Date: Thu, 5 Sep 2013 17:48:47 +0200Quoted 10 lines
From: Daniel Borkmann <[email protected]>
Fix finer-grained control and let only a whitelist of allowed netlink protocols pass, in our case related to networking. If later on, other subsystems decide they want to add their protocol as well to the list of allowed protocols they shall simply add it. While at it, we also need to tell what protocol is in use otherwise
BPF_S_ANC_PROTOCOLcan not pick it up (as it's not filled out).Signed-off-by Daniel Borkmann <[email protected]>
To answer Stephen and Dave in one message ... ;-)
Quoted 11 lines
This takes away functionality that I'd be more interesting in using, namely being able to listen to all netlink protocols using one tap.
Seriously, when I first saw this feature, that was the first way I'd imagine myself using it, as a tcpdump for netlink traffic, all of it.
If I just want to hear all netlink traffic, don't make me be forced to know every single NETLINK_* protocol value and have to open that many sockets just to do so.
Quoted 5 lines
It also makes it so that I can't listen to userlevel custom netlink protocols, another minus of filtering.
At the very least, allow an
sk_protocolof zero or similar to have this meaning of "everything".
I agree with you with all the above and I think with having this in tcpdump would be great to debug netlink traffic of course ...
With socket(PF_PACKET, ..., htons(ETH_P_ALL)) you will already get all users from the suggested white-list of the patch, which is the majority of netlink users I believe. Hence, you do not need to have one socket per protocol. skbs from there should get dragged into pf_packet via dev_queue_xmit_nit() which works on ptype_all list.
Plus, with the nskb->protocol addition in this patch, they can then either take all netlink traffic from that, or filter with BPF e.g. for particular protocols via BPF_S_ANC_PROTOCOL or more advanced stuff, for example. Also, they can select particular dissectors with that information that comes in via sll_protocol which is useful, of course.
I think for out-of-tree modules, we never really cared much, and they could use generic netlink probably anyway. The thing why I wanted to do this is to keep security related messages (audit, selinux) generally under the radar, which is "more or less" what's remaining, so we still get main users. This patch would accomplish those things, that's why I think it's useful.
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Thu, 05 Sep 2013 21:48:00 +0200
Quoted 5 lines
With
socket(PF_PACKET, ..., htons(ETH_P_ALL))you will already get all users from the suggested white-list of the patch, which is the majority of netlink users I believe. Hence, you do not need to have one socket per protocol. skbs from there should get dragged intopf_packetviadev_queue_xmit_nit()which works onptype_alllist.
What about user level netlink protocols?
Quoted 10 lines · David Miller
From: Daniel Borkmann <[email protected]>
Date: Thu, 05 Sep 2013 21:48:00 +0200Quoted 5 lines
With
socket(PF_PACKET, ..., htons(ETH_P_ALL))you will already get all users from the suggested white-list of the patch, which is the majority of netlink users I believe. Hence, you do not need to have one socket per protocol. skbs from there should get dragged intopf_packetviadev_queue_xmit_nit()which works onptype_alllist.What about user level netlink protocols?
If you are referring to NETLINK_USERSOCK, then we let this pass here, so nothing changes.
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Thu, 05 Sep 2013 21:59:28 +0200
Quoted 10 lines · David Miller
Quoted 9 lines
From: Daniel Borkmann <[email protected]>
Date: Thu, 05 Sep 2013 21:48:00 +0200Quoted 5 lines
With
socket(PF_PACKET, ..., htons(ETH_P_ALL))you will already get all users from the suggested white-list of the patch, which is the majority of netlink users I believe. Hence, you do not need to have one socket per protocol. skbs from there should get dragged intopf_packetviadev_queue_xmit_nit()which works onptype_alllist.
Quoted 4 lines
Quoted 1 line
What about user level netlink protocols?
If you are referring to
NETLINK_USERSOCK, then we let this pass here, so nothing changes.
Ok I need to think about this some more, I moved your patch back into under review state.
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Thu, 05 Sep 2013 21:59:28 +0200
Quoted 10 lines · David Miller
Quoted 9 lines
From: Daniel Borkmann <[email protected]>
Date: Thu, 05 Sep 2013 21:48:00 +0200Quoted 5 lines
With
socket(PF_PACKET, ..., htons(ETH_P_ALL))you will already get all users from the suggested white-list of the patch, which is the majority of netlink users I believe. Hence, you do not need to have one socket per protocol. skbs from there should get dragged intopf_packetviadev_queue_xmit_nit()which works onptype_alllist.
Quoted 4 lines
Quoted 1 line
What about user level netlink protocols?
If you are referring to
NETLINK_USERSOCK, then we let this pass here, so nothing changes.
Ok, I've applied this, thanks Daniel.