Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1679072 > unrolled thread
| Started by | Richard Weinberger <richard@nod.at> |
|---|---|
| First post | 2017-06-30 21:30 +0200 |
| Last post | 2017-07-01 12:40 +0200 |
| Articles | 7 — 3 participants |
Back to article view | Back to linux.kernel
nf_conntrack: Infoleak via CTA_ID and CTA_EXPECT_ID Richard Weinberger <richard@nod.at> - 2017-06-30 21:30 +0200
Re: nf_conntrack: Infoleak via CTA_ID and CTA_EXPECT_ID Florian Westphal <fw@strlen.de> - 2017-06-30 21:40 +0200
Re: nf_conntrack: Infoleak via CTA_ID and CTA_EXPECT_ID Richard Weinberger <richard@nod.at> - 2017-06-30 21:50 +0200
Re: nf_conntrack: Infoleak via CTA_ID and CTA_EXPECT_ID Florian Westphal <fw@strlen.de> - 2017-06-30 22:00 +0200
Re: nf_conntrack: Infoleak via CTA_ID and CTA_EXPECT_ID Richard Weinberger <richard@nod.at> - 2017-06-30 22:30 +0200
Re: nf_conntrack: Infoleak via CTA_ID and CTA_EXPECT_ID Pablo Neira Ayuso <pablo@netfilter.org> - 2017-07-01 11:50 +0200
Re: nf_conntrack: Infoleak via CTA_ID and CTA_EXPECT_ID Florian Westphal <fw@strlen.de> - 2017-07-01 12:40 +0200
| From | Richard Weinberger <richard@nod.at> |
|---|---|
| Date | 2017-06-30 21:30 +0200 |
| Subject | nf_conntrack: Infoleak via CTA_ID and CTA_EXPECT_ID |
| Message-ID | <tY9M6-13z-3@gated-at.bofh.it> |
Hi!
I noticed that nf_conntrack leaks kernel addresses, it uses the memory address
as identifier used for generating conntrack and expect ids..
Since these ids are also visible to unprivileged users via network namespaces
I suggest reverting these commits:
commit 7f85f914721ffcef382a57995182916bd43d8a65
Author: Patrick McHardy <kaber@trash.net>
Date: Fri Sep 28 14:41:27 2007 -0700
[NETFILTER]: nf_conntrack: kill unique ID
Remove the per-conntrack ID, its not necessary anymore for dumping.
For compatiblity reasons we send the address of the conntrack to
userspace as ID.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
commit 3583240249ef354760e04ae49bd7b462a638f40c
Author: Patrick McHardy <kaber@trash.net>
Date: Fri Sep 28 14:41:50 2007 -0700
[NETFILTER]: nf_conntrack_expect: kill unique ID
Similar to the conntrack ID, the per-expectation ID is not needed
anymore, kill it.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Thanks,
//richard
[toc] | [next] | [standalone]
| From | Florian Westphal <fw@strlen.de> |
|---|---|
| Date | 2017-06-30 21:40 +0200 |
| Message-ID | <tY9VL-16Y-3@gated-at.bofh.it> |
| In reply to | #1679072 |
Richard Weinberger <richard@nod.at> wrote: > Hi! > > I noticed that nf_conntrack leaks kernel addresses, it uses the memory address > as identifier used for generating conntrack and expect ids.. > Since these ids are also visible to unprivileged users via network namespaces > I suggest reverting these commits: Why not use a hash of the address?
[toc] | [prev] | [next] | [standalone]
| From | Richard Weinberger <richard@nod.at> |
|---|---|
| Date | 2017-06-30 21:50 +0200 |
| Message-ID | <tYa5r-1ah-3@gated-at.bofh.it> |
| In reply to | #1679079 |
Florian, Am 30.06.2017 um 21:35 schrieb Florian Westphal: > Richard Weinberger <richard@nod.at> wrote: >> Hi! >> >> I noticed that nf_conntrack leaks kernel addresses, it uses the memory address >> as identifier used for generating conntrack and expect ids.. >> Since these ids are also visible to unprivileged users via network namespaces >> I suggest reverting these commits: > > Why not use a hash of the address? Would also work. Or xor it with a random number. On the other hand, for user space it would be more useful when the conntrack id does not repeat that often. That's why I favor the good old counter method. Currently the conntrack id is reused very fast. e.g. in one of our applications we use the conntack id via NFQUEUE and watch the destroy events via conntrack. It happens regularly that a new connection has the same id than a different connection we saw some moments before, before we receive the destroy event from the conntrack socket. Thanks, //richard
[toc] | [prev] | [next] | [standalone]
| From | Florian Westphal <fw@strlen.de> |
|---|---|
| Date | 2017-06-30 22:00 +0200 |
| Message-ID | <tYaf7-1dM-5@gated-at.bofh.it> |
| In reply to | #1679085 |
Richard Weinberger <richard@nod.at> wrote: > Florian, > > Am 30.06.2017 um 21:35 schrieb Florian Westphal: > > Richard Weinberger <richard@nod.at> wrote: > >> Hi! > >> > >> I noticed that nf_conntrack leaks kernel addresses, it uses the memory address > >> as identifier used for generating conntrack and expect ids.. > >> Since these ids are also visible to unprivileged users via network namespaces > >> I suggest reverting these commits: > > > > Why not use a hash of the address? > > Would also work. Or xor it with a random number. > > On the other hand, for user space it would be more useful when the conntrack id > does not repeat that often. That's why I favor the good old counter method. > Currently the conntrack id is reused very fast. > e.g. in one of our applications we use the conntack id via NFQUEUE and watch the > destroy events via conntrack. It happens regularly that a new connection has the > same id than a different connection we saw some moments before, before we receive > the destroy event from the conntrack socket. Perhaps we can place that in a new extension (its not needed in any fastpath ops)?
[toc] | [prev] | [next] | [standalone]
| From | Richard Weinberger <richard@nod.at> |
|---|---|
| Date | 2017-06-30 22:30 +0200 |
| Message-ID | <tYaI9-1Ck-11@gated-at.bofh.it> |
| In reply to | #1679095 |
Florian, Am 30.06.2017 um 21:55 schrieb Florian Westphal: >>> Why not use a hash of the address? >> >> Would also work. Or xor it with a random number. >> >> On the other hand, for user space it would be more useful when the conntrack id >> does not repeat that often. That's why I favor the good old counter method. >> Currently the conntrack id is reused very fast. >> e.g. in one of our applications we use the conntack id via NFQUEUE and watch the >> destroy events via conntrack. It happens regularly that a new connection has the >> same id than a different connection we saw some moments before, before we receive >> the destroy event from the conntrack socket. > > Perhaps we can place that in a new extension (its not needed in any > fastpath ops)? To get rid of the infoleak we have to re-introduce the id field in struct nf_conn and struct nf_conntrack_expect. Otherwise have nothing to compare against in the conntrack/expect remove case. So the only question is what to store, IMHO a counter that can wrap around is the cheapest method and would also not harm the fast-path. Thanks, //richard
[toc] | [prev] | [next] | [standalone]
| From | Pablo Neira Ayuso <pablo@netfilter.org> |
|---|---|
| Date | 2017-07-01 11:50 +0200 |
| Message-ID | <tYncl-1jW-17@gated-at.bofh.it> |
| In reply to | #1679116 |
On Fri, Jun 30, 2017 at 10:23:24PM +0200, Richard Weinberger wrote: > Florian, > > Am 30.06.2017 um 21:55 schrieb Florian Westphal: > >>> Why not use a hash of the address? > >> > >> Would also work. Or xor it with a random number. > >> > >> On the other hand, for user space it would be more useful when the conntrack id > >> does not repeat that often. That's why I favor the good old counter method. > >> Currently the conntrack id is reused very fast. > >> e.g. in one of our applications we use the conntack id via NFQUEUE and watch the > >> destroy events via conntrack. It happens regularly that a new connection has the > >> same id than a different connection we saw some moments before, before we receive > >> the destroy event from the conntrack socket. > > > > Perhaps we can place that in a new extension (its not needed in any > > fastpath ops)? > > To get rid of the infoleak we have to re-introduce the id field in struct nf_conn > and struct nf_conntrack_expect. > Otherwise have nothing to compare against in the conntrack/expect remove case. > > So the only question is what to store, IMHO a counter that can wrap around is the > cheapest method and would also not harm the fast-path. I have a patch to assign ids through percpu approach that I can recover. It's dividing the u64 id space between the existing num_cpus.
[toc] | [prev] | [next] | [standalone]
| From | Florian Westphal <fw@strlen.de> |
|---|---|
| Date | 2017-07-01 12:40 +0200 |
| Message-ID | <tYnYJ-1T5-5@gated-at.bofh.it> |
| In reply to | #1679116 |
Richard Weinberger <richard@nod.at> wrote:
> Florian,
>
> Am 30.06.2017 um 21:55 schrieb Florian Westphal:
> >>> Why not use a hash of the address?
> >>
> >> Would also work. Or xor it with a random number.
> >>
> >> On the other hand, for user space it would be more useful when the conntrack id
> >> does not repeat that often. That's why I favor the good old counter method.
> >> Currently the conntrack id is reused very fast.
> >> e.g. in one of our applications we use the conntack id via NFQUEUE and watch the
> >> destroy events via conntrack. It happens regularly that a new connection has the
> >> same id than a different connection we saw some moments before, before we receive
> >> the destroy event from the conntrack socket.
> >
> > Perhaps we can place that in a new extension (its not needed in any
> > fastpath ops)?
>
> To get rid of the infoleak we have to re-introduce the id field in struct nf_conn
> and struct nf_conntrack_expect.
Why will this not work?
> Otherwise have nothing to compare against in the conntrack/expect remove case.
Not following, sorry. The id is not used anywhere except when we send
info to userspace.
The compare on removal is not needed afaics, and its also not used when
doing lookup to begin with, so we can just recompute it?
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -25,6 +25,7 @@
#include <linux/security.h>
#include <linux/skbuff.h>
#include <linux/errno.h>
+#include <linux/hash.h>
#include <linux/netlink.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
@@ -443,9 +444,44 @@ static int ctnetlink_dump_ct_seq_adj(struct sk_buff *skb, struct nf_conn *ct)
return -1;
}
+static __be32 ct_to_id(const struct nf_conn *ct)
+{
+ static u32 seed __read_mostly;
+ u32 a, b, c;
+
+ if (!ct)
+ return 0;
+
+ if (!seed)
+ seed = get_random_u32();
+
+ a = jhash2((u32 *)ct->tuplehash, sizeof(ct->tuplehash) / sizeof(u32),
+ hash32_ptr(ct));
+ b = ct_to_id(ct->master) ^ net_hash_mix(nf_ct_net(ct));
+ c = hash32_ptr(ct->ext);
+
+ return (__force __be32)jhash_3words(a, b, c, seed);
+}
+
+static __be32 ctexp_to_id(const struct nf_conntrack_expect *exp)
+{
+ static u32 seed __read_mostly;
+ u32 a, b, c;
+
+ if (!seed)
+ seed = get_random_u32();
+
+ a = ct_to_id(exp->master);
+ b = hash32_ptr(exp->helper);
+ c = jhash2((u32 *)&exp->tuple, sizeof(exp->tuple) / sizeof(u32),
+ hash32_ptr(exp));
+
+ return (__force __be32)jhash_3words(a, b, c, seed);
+}
+
static int ctnetlink_dump_id(struct sk_buff *skb, const struct nf_conn *ct)
{
- if (nla_put_be32(skb, CTA_ID, htonl((unsigned long)ct)))
+ if (nla_put_be32(skb, CTA_ID, ct_to_id(ct)))
goto nla_put_failure;
return 0;
@@ -1164,8 +1200,8 @@ static int ctnetlink_del_conntrack(struct net *net, struct sock *ctnl,
ct = nf_ct_tuplehash_to_ctrack(h);
if (cda[CTA_ID]) {
- u_int32_t id = ntohl(nla_get_be32(cda[CTA_ID]));
- if (id != (u32)(unsigned long)ct) {
+ __be32 id = nla_get_be32(cda[CTA_ID]);
+ if (id != ct_to_id(ct)) {
nf_ct_put(ct);
return -ENOENT;
}
@@ -2563,7 +2599,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,
}
#endif
if (nla_put_be32(skb, CTA_EXPECT_TIMEOUT, htonl(timeout)) ||
- nla_put_be32(skb, CTA_EXPECT_ID, htonl((unsigned long)exp)) ||
+ nla_put_be32(skb, CTA_EXPECT_ID, ctexp_to_id(exp)) ||
nla_put_be32(skb, CTA_EXPECT_FLAGS, htonl(exp->flags)) ||
nla_put_be32(skb, CTA_EXPECT_CLASS, htonl(exp->class)))
goto nla_put_failure;
@@ -2871,7 +2907,7 @@ static int ctnetlink_get_expect(struct net *net, struct sock *ctnl,
if (cda[CTA_EXPECT_ID]) {
__be32 id = nla_get_be32(cda[CTA_EXPECT_ID]);
- if (ntohl(id) != (u32)(unsigned long)exp) {
+ if (id != ctexp_to_id(exp)) {
nf_ct_expect_put(exp);
return -ENOENT;
}
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web