[PATCH nf-next v2] netfilter: allow logging from non-init namespaces

2017-01-31 Thread Michal Kubecek
Commit 69b34fb996b2 ("netfilter: xt_LOG: add net namespace support for
xt_LOG") disabled logging packets using the LOG target from non-init
namespaces. The motivation was to prevent containers from flooding
kernel log of the host. The plan was to keep it that way until syslog
namespace implementation allows containers to log in a safe way.

However, the work on syslog namespace seems to have hit a dead end
somewhere in 2013 and there are users who want to use xt_LOG in all
network namespaces. This patch allows to do so by setting

  /proc/sys/net/netfilter/nf_log_all_netns

to a nonzero value. This sysctl is only accessible from init_net so that
one cannot switch the behaviour from inside a container.

Signed-off-by: Michal Kubecek <mkube...@suse.cz>
---
v2: fix leak on net/netfilter/nf_log registration failure
---
 Documentation/networking/netfilter-sysctl.txt | 10 ++
 include/net/netfilter/nf_log.h|  3 +++
 net/bridge/netfilter/ebt_log.c|  2 +-
 net/ipv4/netfilter/nf_log_arp.c   |  2 +-
 net/ipv4/netfilter/nf_log_ipv4.c  |  2 +-
 net/ipv6/netfilter/nf_log_ipv6.c  |  2 +-
 net/netfilter/nf_log.c| 24 
 7 files changed, 41 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/networking/netfilter-sysctl.txt

diff --git a/Documentation/networking/netfilter-sysctl.txt 
b/Documentation/networking/netfilter-sysctl.txt
new file mode 100644
index ..55791e50e169
--- /dev/null
+++ b/Documentation/networking/netfilter-sysctl.txt
@@ -0,0 +1,10 @@
+/proc/sys/net/netfilter/* Variables:
+
+nf_log_all_netns - BOOLEAN
+   0 - disabled (default)
+   not 0 - enabled
+
+   By default, only init_net namespace can log packets into kernel log
+   with LOG target; this aims to prevent containers from flooding host
+   kernel log. If enabled, this target also works in other network
+   namespaces. This variable is only accessible from init_net.
diff --git a/include/net/netfilter/nf_log.h b/include/net/netfilter/nf_log.h
index 450f87f95415..42e0696f38d8 100644
--- a/include/net/netfilter/nf_log.h
+++ b/include/net/netfilter/nf_log.h
@@ -51,6 +51,9 @@ struct nf_logger {
struct module   *me;
 };
 
+/* sysctl_nf_log_all_netns - allow LOG target in all network namespaces */
+extern int sysctl_nf_log_all_netns;
+
 /* Function to register/unregister log function. */
 int nf_log_register(u_int8_t pf, struct nf_logger *logger);
 void nf_log_unregister(struct nf_logger *logger);
diff --git a/net/bridge/netfilter/ebt_log.c b/net/bridge/netfilter/ebt_log.c
index e88bd4827ac1..98b9c8e8615e 100644
--- a/net/bridge/netfilter/ebt_log.c
+++ b/net/bridge/netfilter/ebt_log.c
@@ -78,7 +78,7 @@ ebt_log_packet(struct net *net, u_int8_t pf, unsigned int 
hooknum,
unsigned int bitmask;
 
/* FIXME: Disabled from containers until syslog ns is supported */
-   if (!net_eq(net, _net))
+   if (!net_eq(net, _net) && !sysctl_nf_log_all_netns)
return;
 
spin_lock_bh(_log_lock);
diff --git a/net/ipv4/netfilter/nf_log_arp.c b/net/ipv4/netfilter/nf_log_arp.c
index b24795e2ee6d..f6f713376e6e 100644
--- a/net/ipv4/netfilter/nf_log_arp.c
+++ b/net/ipv4/netfilter/nf_log_arp.c
@@ -87,7 +87,7 @@ static void nf_log_arp_packet(struct net *net, u_int8_t pf,
struct nf_log_buf *m;
 
/* FIXME: Disabled from containers until syslog ns is supported */
-   if (!net_eq(net, _net))
+   if (!net_eq(net, _net) && !sysctl_nf_log_all_netns)
return;
 
m = nf_log_buf_open();
diff --git a/net/ipv4/netfilter/nf_log_ipv4.c b/net/ipv4/netfilter/nf_log_ipv4.c
index 856648966f4c..c83a9963269b 100644
--- a/net/ipv4/netfilter/nf_log_ipv4.c
+++ b/net/ipv4/netfilter/nf_log_ipv4.c
@@ -319,7 +319,7 @@ static void nf_log_ip_packet(struct net *net, u_int8_t pf,
struct nf_log_buf *m;
 
/* FIXME: Disabled from containers until syslog ns is supported */
-   if (!net_eq(net, _net))
+   if (!net_eq(net, _net) && !sysctl_nf_log_all_netns)
return;
 
m = nf_log_buf_open();
diff --git a/net/ipv6/netfilter/nf_log_ipv6.c b/net/ipv6/netfilter/nf_log_ipv6.c
index 57d86066a13b..055c51b80f5d 100644
--- a/net/ipv6/netfilter/nf_log_ipv6.c
+++ b/net/ipv6/netfilter/nf_log_ipv6.c
@@ -351,7 +351,7 @@ static void nf_log_ip6_packet(struct net *net, u_int8_t pf,
struct nf_log_buf *m;
 
/* FIXME: Disabled from containers until syslog ns is supported */
-   if (!net_eq(net, _net))
+   if (!net_eq(net, _net) && !sysctl_nf_log_all_netns)
return;
 
m = nf_log_buf_open();
diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
index 3dca90dc24ad..0a034f52b912 100644
--- a/net/netfilter/nf_log.c
+++ b/net/netfilter/nf_log.c
@@ -16,6 +16,9 @@
 #define NF_LOG_PREFIXLEN   128
 

Re: [PATCH nf-next] netfilter: allow logging from non-init namespaces

2016-08-16 Thread Michal Kubecek
On Mon, May 16, 2016 at 08:43:16AM +0200, Michal Kubecek wrote:
> On Thu, May 12, 2016 at 11:57:26AM +0200, Pablo Neira Ayuso wrote:
> > On Wed, Apr 27, 2016 at 02:48:02PM +0200, Michal Kubecek wrote:
> > > Commit 69b34fb996b2 ("netfilter: xt_LOG: add net namespace support for
> > > xt_LOG") disabled logging packets using the LOG target from non-init
> > > namespaces. The motivation was to prevent containers from flooding
> > > kernel log of the host. The plan was to keep it that way until syslog
> > > namespace implementation allows containers to log in a safe way.
> > > 
> > > However, the work on syslog namespace seems to have hit a dead end
> > > somewhere in 2013 and there are users who want to use xt_LOG in all
> > > network namespaces. This patch allows to do so by setting
> > 
> > I understand this stuff is tricky. Did you contact already namespace
> > folks to see if they plan any move on this?
> 
> Not yet. I'll contact the people involved in the discussion about the
> serires submitted in 2013 to check what their plans are (and if there
> are any).

Sorry for the delay, there were some security bugs so that this lost my
attention.

I did some asking around and the syslog namespace work is dead. There
were some design issues that turned out to be hard to address and the
overall consensus was that use cases like netfilter logging can be
handled in a different way (e.g. using NFLOG target).

Would the patch be acceptable? (It still applies cleanly to current
nf-next tree but I can resend a rebased version if needed.)

 Michal Kubecek
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH nf-next] netfilter: allow logging from non-init namespaces

2016-05-16 Thread Michal Kubecek
On Thu, May 12, 2016 at 11:57:26AM +0200, Pablo Neira Ayuso wrote:
> Hi Michal,
> 
> On Wed, Apr 27, 2016 at 02:48:02PM +0200, Michal Kubecek wrote:
> > Commit 69b34fb996b2 ("netfilter: xt_LOG: add net namespace support for
> > xt_LOG") disabled logging packets using the LOG target from non-init
> > namespaces. The motivation was to prevent containers from flooding
> > kernel log of the host. The plan was to keep it that way until syslog
> > namespace implementation allows containers to log in a safe way.
> > 
> > However, the work on syslog namespace seems to have hit a dead end
> > somewhere in 2013 and there are users who want to use xt_LOG in all
> > network namespaces. This patch allows to do so by setting
> 
> I understand this stuff is tricky. Did you contact already namespace
> folks to see if they plan any move on this?

Not yet. I'll contact the people involved in the discussion about the
serires submitted in 2013 to check what their plans are (and if there
are any).

> >   /proc/sys/net/netfilter/nf_log_all_netns
> 
> My only concern with this is that I don't see how users know what log
> message has triggered from what container.

IMHO this is a more generic issue with containers: there is no (known to
me) link between userspace "containers" and kernel namespaces that could
be used in kernel log messages. In this case, --log-prefix can be used
in netfilter logging rules to identify the container messages belong to.

  Michal Kubecek
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH nf-next] netfilter: allow logging from non-init namespaces

2016-04-28 Thread Michal Kubecek
Commit 69b34fb996b2 ("netfilter: xt_LOG: add net namespace support for
xt_LOG") disabled logging packets using the LOG target from non-init
namespaces. The motivation was to prevent containers from flooding
kernel log of the host. The plan was to keep it that way until syslog
namespace implementation allows containers to log in a safe way.

However, the work on syslog namespace seems to have hit a dead end
somewhere in 2013 and there are users who want to use xt_LOG in all
network namespaces. This patch allows to do so by setting

  /proc/sys/net/netfilter/nf_log_all_netns

to a nonzero value. This sysctl is only accessible from init_net so that
one cannot switch the behaviour from inside a container.

Signed-off-by: Michal Kubecek <mkube...@suse.cz>
---
 Documentation/networking/netfilter-sysctl.txt | 10 ++
 include/net/netfilter/nf_log.h|  3 +++
 net/bridge/netfilter/ebt_log.c|  2 +-
 net/ipv4/netfilter/nf_log_arp.c   |  2 +-
 net/ipv4/netfilter/nf_log_ipv4.c  |  2 +-
 net/ipv6/netfilter/nf_log_ipv6.c  |  2 +-
 net/netfilter/nf_log.c| 22 ++
 7 files changed, 39 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/networking/netfilter-sysctl.txt

diff --git a/Documentation/networking/netfilter-sysctl.txt 
b/Documentation/networking/netfilter-sysctl.txt
new file mode 100644
index ..55791e50e169
--- /dev/null
+++ b/Documentation/networking/netfilter-sysctl.txt
@@ -0,0 +1,10 @@
+/proc/sys/net/netfilter/* Variables:
+
+nf_log_all_netns - BOOLEAN
+   0 - disabled (default)
+   not 0 - enabled
+
+   By default, only init_net namespace can log packets into kernel log
+   with LOG target; this aims to prevent containers from flooding host
+   kernel log. If enabled, this target also works in other network
+   namespaces. This variable is only accessible from init_net.
diff --git a/include/net/netfilter/nf_log.h b/include/net/netfilter/nf_log.h
index 57639fca223a..8c4b018eef72 100644
--- a/include/net/netfilter/nf_log.h
+++ b/include/net/netfilter/nf_log.h
@@ -49,6 +49,9 @@ struct nf_logger {
struct module   *me;
 };
 
+/* sysctl_nf_log_all_netns - allow LOG target in all network namespaces */
+extern int sysctl_nf_log_all_netns;
+
 /* Function to register/unregister log function. */
 int nf_log_register(u_int8_t pf, struct nf_logger *logger);
 void nf_log_unregister(struct nf_logger *logger);
diff --git a/net/bridge/netfilter/ebt_log.c b/net/bridge/netfilter/ebt_log.c
index 152300d164ac..735230ec0e49 100644
--- a/net/bridge/netfilter/ebt_log.c
+++ b/net/bridge/netfilter/ebt_log.c
@@ -78,7 +78,7 @@ ebt_log_packet(struct net *net, u_int8_t pf, unsigned int 
hooknum,
unsigned int bitmask;
 
/* FIXME: Disabled from containers until syslog ns is supported */
-   if (!net_eq(net, _net))
+   if (!net_eq(net, _net) && !sysctl_nf_log_all_netns)
return;
 
spin_lock_bh(_log_lock);
diff --git a/net/ipv4/netfilter/nf_log_arp.c b/net/ipv4/netfilter/nf_log_arp.c
index e7ad950cf9ef..39e1348dfe45 100644
--- a/net/ipv4/netfilter/nf_log_arp.c
+++ b/net/ipv4/netfilter/nf_log_arp.c
@@ -87,7 +87,7 @@ static void nf_log_arp_packet(struct net *net, u_int8_t pf,
struct nf_log_buf *m;
 
/* FIXME: Disabled from containers until syslog ns is supported */
-   if (!net_eq(net, _net))
+   if (!net_eq(net, _net) && !sysctl_nf_log_all_netns)
return;
 
m = nf_log_buf_open();
diff --git a/net/ipv4/netfilter/nf_log_ipv4.c b/net/ipv4/netfilter/nf_log_ipv4.c
index 076aadda0473..2b0083112ed8 100644
--- a/net/ipv4/netfilter/nf_log_ipv4.c
+++ b/net/ipv4/netfilter/nf_log_ipv4.c
@@ -319,7 +319,7 @@ static void nf_log_ip_packet(struct net *net, u_int8_t pf,
struct nf_log_buf *m;
 
/* FIXME: Disabled from containers until syslog ns is supported */
-   if (!net_eq(net, _net))
+   if (!net_eq(net, _net) && !sysctl_nf_log_all_netns)
return;
 
m = nf_log_buf_open();
diff --git a/net/ipv6/netfilter/nf_log_ipv6.c b/net/ipv6/netfilter/nf_log_ipv6.c
index 8dd869642f45..04960486d0e2 100644
--- a/net/ipv6/netfilter/nf_log_ipv6.c
+++ b/net/ipv6/netfilter/nf_log_ipv6.c
@@ -351,7 +351,7 @@ static void nf_log_ip6_packet(struct net *net, u_int8_t pf,
struct nf_log_buf *m;
 
/* FIXME: Disabled from containers until syslog ns is supported */
-   if (!net_eq(net, _net))
+   if (!net_eq(net, _net) && !sysctl_nf_log_all_netns)
return;
 
m = nf_log_buf_open();
diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
index a5d41dfa9f05..a5f4c57b14c5 100644
--- a/net/netfilter/nf_log.c
+++ b/net/netfilter/nf_log.c
@@ -16,6 +16,9 @@
 #define NF_LOG_PREFIXLEN   128
 #define NFLOGGER_NAME_LEN  64
 
+int sysctl_nf_log_all_netns __rea