netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -nf] netfilter: x_tables: fix cgroup matching on non-full sks
@ 2015-03-27 18:37 Daniel Borkmann
  2015-04-02  8:52 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2015-03-27 18:37 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, Daniel Borkmann, Alexey Perevalov

While originally only being intended for outgoing traffic, commit
a00e76349f35 ("netfilter: x_tables: allow to use cgroup match for
LOCAL_IN nf hooks") enabled xt_cgroups for the NF_INET_LOCAL_IN hook
as well, in order to allow for nfacct accounting.

Besides being currently limited to early demuxes only, commit
a00e76349f35 forgot to add a check if we deal with full sockets,
i.e. in this case not with time wait sockets. TCP time wait sockets
do not have the same memory layout as full sockets, a lower memory
footprint and consequently also don't have a sk_classid member;
probing for sk_classid member there could potentially lead to a
crash.

Fixes: a00e76349f35 ("netfilter: x_tables: allow to use cgroup match for LOCAL_IN nf hooks")
Cc: Alexey Perevalov <a.perevalov@samsung.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
 (As discussed the fix for xt_cgroups, so it can be queued for
  -stable. In nf-next speak that would be !sk_fullsock(skb->sk).)

 net/netfilter/xt_cgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/xt_cgroup.c b/net/netfilter/xt_cgroup.c
index 7198d66..d64aca0 100644
--- a/net/netfilter/xt_cgroup.c
+++ b/net/netfilter/xt_cgroup.c
@@ -16,6 +16,7 @@
 #include <linux/module.h>
 #include <linux/netfilter/x_tables.h>
 #include <linux/netfilter/xt_cgroup.h>
+#include <net/tcp_states.h> /* for TCP_TIME_WAIT */
 #include <net/sock.h>
 
 MODULE_LICENSE("GPL");
@@ -39,7 +40,7 @@ cgroup_mt(const struct sk_buff *skb, struct xt_action_param *par)
 {
 	const struct xt_cgroup_info *info = par->matchinfo;
 
-	if (skb->sk == NULL)
+	if (skb->sk == NULL || skb->sk->sk_state == TCP_TIME_WAIT)
 		return false;
 
 	return (info->id == skb->sk->sk_classid) ^ info->invert;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH -nf] netfilter: x_tables: fix cgroup matching on non-full sks
  2015-03-27 18:37 [PATCH -nf] netfilter: x_tables: fix cgroup matching on non-full sks Daniel Borkmann
@ 2015-04-02  8:52 ` Pablo Neira Ayuso
  2015-04-02  8:52   ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2015-04-02  8:52 UTC (permalink / raw)
  To: Daniel Borkmann; +Cc: netfilter-devel, Alexey Perevalov

On Fri, Mar 27, 2015 at 07:37:41PM +0100, Daniel Borkmann wrote:
> While originally only being intended for outgoing traffic, commit
> a00e76349f35 ("netfilter: x_tables: allow to use cgroup match for
> LOCAL_IN nf hooks") enabled xt_cgroups for the NF_INET_LOCAL_IN hook
> as well, in order to allow for nfacct accounting.
> 
> Besides being currently limited to early demuxes only, commit
> a00e76349f35 forgot to add a check if we deal with full sockets,
> i.e. in this case not with time wait sockets. TCP time wait sockets
> do not have the same memory layout as full sockets, a lower memory
> footprint and consequently also don't have a sk_classid member;
> probing for sk_classid member there could potentially lead to a
> crash.

Mangled this patch and applied to nf-next. I'll pass this to -stable
using this as backport. Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH -nf] netfilter: x_tables: fix cgroup matching on non-full sks
  2015-04-02  8:52 ` Pablo Neira Ayuso
@ 2015-04-02  8:52   ` Daniel Borkmann
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2015-04-02  8:52 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, Alexey Perevalov

On 04/02/2015 10:52 AM, Pablo Neira Ayuso wrote:
...
> Mangled this patch and applied to nf-next. I'll pass this to -stable
> using this as backport. Thanks.

Ok, that's fine too. Thanks, Pablo!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-02  8:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-27 18:37 [PATCH -nf] netfilter: x_tables: fix cgroup matching on non-full sks Daniel Borkmann
2015-04-02  8:52 ` Pablo Neira Ayuso
2015-04-02  8:52   ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).