[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20161013204314.GA32753@breakpoint.cc>
Date: Thu, 13 Oct 2016 22:43:14 +0200
From: Florian Westphal <fw@...len.de>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Markus Trippelsdorf <markus@...ppelsdorf.de>,
Christoph Lameter <cl@...ux.com>, Jens Axboe <axboe@...com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Aaron Conole <aconole@...hat.com>,
David Miller <davem@...emloft.net>,
Pablo Neira Ayuso <pablo@...filter.org>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Al Viro <viro@...iv.linux.org.uk>,
NetFilter <netfilter-devel@...r.kernel.org>,
Network Development <netdev@...r.kernel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Florian Westphal <fw@...len.de>, Theodore Ts'o <tytso@....edu>
Subject: Re: slab corruption with current -git
Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> On Wed, Oct 12, 2016 at 11:27 PM, Markus Trippelsdorf
> <markus@...ppelsdorf.de> wrote:
> >
> > Yeah.
> >
> > 105 entry->orig_ops = reg;
> > 106 entry->ops = *reg;
> > 107 entry->next = NULL;
>
> So ipt_register_table() does:
>
> ret = nf_register_net_hooks(net, ops, hweight32(table->valid_hooks));
>
> and then nf_register_net_hooks() just does
>
> for (i = 0; i < n; i++) {
> err = nf_register_net_hook(net, ®[i]);
>
> so if the *reg is uninitialized, it means that it's the 'ops[]' array
> that isn't actually really valid in "valid_hooks". Odd. They should
> all be initialized by xt_hook_ops_alloc(), no?
Its only partially initialized. Looking at Markus' splat
its complaining about first 16 bytes (list_head), whose contents are indeed
undefined when it gets copied to entry->ops.
For the time being this seems like the most simple "fix", until we
disentangle the hook description (which should be const) from run-time
allocated data.
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index e0aa7c1d0224..fc4977456c30 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -1513,7 +1513,7 @@ xt_hook_ops_alloc(const struct xt_table *table,
nf_hookfn *fn)
if (!num_hooks)
return ERR_PTR(-EINVAL);
- ops = kmalloc(sizeof(*ops) * num_hooks, GFP_KERNEL);
+ ops = kcalloc(num_hooks, sizeof(*ops), GFP_KERNEL);
if (ops == NULL)
return ERR_PTR(-ENOMEM);
I'll pass such a patch to Pablo.
> That said, xt_hook_ops_alloc() itself is odd. Lookie here, this is the
> loop that initializes things:
>
> for (i = 0, hooknum = 0; i < num_hooks && hook_mask != 0;
> hook_mask >>= 1, ++hooknum) {
>
> and it makes no sense to me how that tests *both* "i < num_hools" and
> "hook_mask != 0".
Right, one of these is enough.
Powered by blists - more mailing lists