[SRU,T,X,A,B,1/1] netfilter: xt_osf: Add missing permission checks

Message ID 20180131130451.22182-2-kleber.souza@canonical.com
State New
Headers show
Series
  • [SRU,T,X,A,B,1/1] netfilter: xt_osf: Add missing permission checks
Related show

Commit Message

Kleber Souza Jan. 31, 2018, 1:04 p.m.
From: Kevin Cernekee <cernekee@chromium.org>

The capability check in nfnetlink_rcv() verifies that the caller
has CAP_NET_ADMIN in the namespace that "owns" the netlink socket.
However, xt_osf_fingers is shared by all net namespaces on the
system.  An unprivileged user can create user and net namespaces
in which he holds CAP_NET_ADMIN to bypass the netlink_net_capable()
check:

    vpnns -- nfnl_osf -f /tmp/pf.os

    vpnns -- nfnl_osf -f /tmp/pf.os -d

These non-root operations successfully modify the systemwide OS
fingerprint list.  Add new capable() checks so that they can't.

Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

CVE-2017-17450
(cherry picked from commit 916a27901de01446bcf57ecca4783f6cff493309)
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
---
 net/netfilter/xt_osf.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Stefan Bader Feb. 2, 2018, 9:55 a.m. | #1
On 31.01.2018 14:04, Kleber Sacilotto de Souza wrote:
> From: Kevin Cernekee <cernekee@chromium.org>
> 
> The capability check in nfnetlink_rcv() verifies that the caller
> has CAP_NET_ADMIN in the namespace that "owns" the netlink socket.
> However, xt_osf_fingers is shared by all net namespaces on the
> system.  An unprivileged user can create user and net namespaces
> in which he holds CAP_NET_ADMIN to bypass the netlink_net_capable()
> check:
> 
>     vpnns -- nfnl_osf -f /tmp/pf.os
> 
>     vpnns -- nfnl_osf -f /tmp/pf.os -d
> 
> These non-root operations successfully modify the systemwide OS
> fingerprint list.  Add new capable() checks so that they can't.
> 
> Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> 
> CVE-2017-17450
> (cherry picked from commit 916a27901de01446bcf57ecca4783f6cff493309)
> Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
> ---
>  net/netfilter/xt_osf.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/net/netfilter/xt_osf.c b/net/netfilter/xt_osf.c
> index 647d989a01e6..de49ff18963a 100644
> --- a/net/netfilter/xt_osf.c
> +++ b/net/netfilter/xt_osf.c
> @@ -20,6 +20,7 @@
>  #include <linux/module.h>
>  #include <linux/kernel.h>
>  
> +#include <linux/capability.h>
>  #include <linux/if.h>
>  #include <linux/inetdevice.h>
>  #include <linux/ip.h>
> @@ -70,6 +71,9 @@ static int xt_osf_add_callback(struct sock *ctnl, struct sk_buff *skb,
>  	struct xt_osf_finger *kf = NULL, *sf;
>  	int err = 0;
>  
> +	if (!capable(CAP_NET_ADMIN))
> +		return -EPERM;
> +
>  	if (!osf_attrs[OSF_ATTR_FINGER])
>  		return -EINVAL;
>  
> @@ -113,6 +117,9 @@ static int xt_osf_remove_callback(struct sock *ctnl, struct sk_buff *skb,
>  	struct xt_osf_finger *sf;
>  	int err = -ENOENT;
>  
> +	if (!capable(CAP_NET_ADMIN))
> +		return -EPERM;
> +
>  	if (!osf_attrs[OSF_ATTR_FINGER])
>  		return -EINVAL;
>  
>

Patch

diff --git a/net/netfilter/xt_osf.c b/net/netfilter/xt_osf.c
index 647d989a01e6..de49ff18963a 100644
--- a/net/netfilter/xt_osf.c
+++ b/net/netfilter/xt_osf.c
@@ -20,6 +20,7 @@ 
 #include <linux/module.h>
 #include <linux/kernel.h>
 
+#include <linux/capability.h>
 #include <linux/if.h>
 #include <linux/inetdevice.h>
 #include <linux/ip.h>
@@ -70,6 +71,9 @@  static int xt_osf_add_callback(struct sock *ctnl, struct sk_buff *skb,
 	struct xt_osf_finger *kf = NULL, *sf;
 	int err = 0;
 
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
 	if (!osf_attrs[OSF_ATTR_FINGER])
 		return -EINVAL;
 
@@ -113,6 +117,9 @@  static int xt_osf_remove_callback(struct sock *ctnl, struct sk_buff *skb,
 	struct xt_osf_finger *sf;
 	int err = -ENOENT;
 
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
 	if (!osf_attrs[OSF_ATTR_FINGER])
 		return -EINVAL;