Message ID | 1309788494-2307-6-git-send-email-paolo.pisati@canonical.com |
---|---|
State | New |
Headers | show |
On 04.07.2011 16:08, paolo.pisati@canonical.com wrote: > From: Vasiliy Kulikov <segoon@openwall.com> > > BugLink: http://bugs.launchpad.net/bugs/801480 > > commit upstream 42eab94fff18cb1091d3501cd284d6bd6cc9c143 > > Structures ipt_replace, compat_ipt_replace, and xt_get_revision are > copied from userspace. Fields of these structs that are > zero-terminated strings are not checked. When they are used as argument > to a format string containing "%s" in request_module(), some sensitive > information is leaked to userspace via argument of spawned modprobe > process. > > The first bug was introduced before the git epoch; the second is > introduced by 6b7d31fc (v2.6.15-rc1); the third is introduced by > 6b7d31fc (v2.6.15-rc1). To trigger the bug one should have > CAP_NET_ADMIN. > > Signed-off-by: Vasiliy Kulikov <segoon@openwall.com> > Signed-off-by: Patrick McHardy <kaber@trash.net> > Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com> > --- > net/ipv4/netfilter/arp_tables.c | 3 +++ > 1 files changed, 3 insertions(+), 0 deletions(-) > > diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c > index 2909c92..da85e92 100644 > --- a/net/ipv4/netfilter/arp_tables.c > +++ b/net/ipv4/netfilter/arp_tables.c > @@ -816,6 +816,7 @@ static int do_replace(void __user *user, unsigned int len) > return -ENOMEM; > if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) > return -ENOMEM; > + tmp.name[sizeof(tmp.name)-1] = 0; > > newinfo = xt_alloc_table_info(tmp.size); > if (!newinfo) Comparing the second hunk against upstream there may be a misplacement. In upstream code the change was in compat_do_replace(). > @@ -930,6 +931,7 @@ static int do_add_counters(void __user *user, unsigned int len) > paddc = vmalloc(len); > if (!paddc) > return -ENOMEM; > + tmp.name[sizeof(tmp.name)-1] = 0; > > if (copy_from_user(paddc, user, len) != 0) { > ret = -EFAULT; > @@ -1070,6 +1072,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len > ret = -EFAULT; > break; > } > + rev.name[sizeof(rev.name)-1] = 0; > > try_then_request_module(xt_find_revision(NF_ARP, rev.name, > rev.revision, 1, &ret),
On 07/04/2011 04:47 PM, Stefan Bader wrote: >> >> diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c >> index 2909c92..da85e92 100644 >> --- a/net/ipv4/netfilter/arp_tables.c >> +++ b/net/ipv4/netfilter/arp_tables.c >> @@ -816,6 +816,7 @@ static int do_replace(void __user *user, unsigned int len) >> return -ENOMEM; >> if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) >> return -ENOMEM; >> + tmp.name[sizeof(tmp.name)-1] = 0; >> >> newinfo = xt_alloc_table_info(tmp.size); >> if (!newinfo) > > Comparing the second hunk against upstream there may be a misplacement. In > upstream code the change was in compat_do_replace(). Actually i did it on purpose because i was sure there was some code printk-ing tmp.name later, but it's clearly not the case: it doesn't hurt since i'm just enforcing the array to be correctly terminated, but doesn't belong to this security fix. The same rationale applies for net/ipv6/netfilter/ip6_tables.c::do_add_counters(). Please hold on.
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c index 2909c92..da85e92 100644 --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c @@ -816,6 +816,7 @@ static int do_replace(void __user *user, unsigned int len) return -ENOMEM; if (tmp.num_counters >= INT_MAX / sizeof(struct xt_counters)) return -ENOMEM; + tmp.name[sizeof(tmp.name)-1] = 0; newinfo = xt_alloc_table_info(tmp.size); if (!newinfo) @@ -930,6 +931,7 @@ static int do_add_counters(void __user *user, unsigned int len) paddc = vmalloc(len); if (!paddc) return -ENOMEM; + tmp.name[sizeof(tmp.name)-1] = 0; if (copy_from_user(paddc, user, len) != 0) { ret = -EFAULT; @@ -1070,6 +1072,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len ret = -EFAULT; break; } + rev.name[sizeof(rev.name)-1] = 0; try_then_request_module(xt_find_revision(NF_ARP, rev.name, rev.revision, 1, &ret),