Re: Possible netfilter-related memory corruption in 2.6.37

Eric Dumazet
2011-02-18T19:14:55Z

Le vendredi 18 février 2011 à 19:37 +0100, Patrick McHardy a écrit :
> Am 14.02.2011 17:52, schrieb Patrick McHardy:
> > Am 14.02.2011 17:48, schrieb Eric Dumazet:
> >> I am not sure, but I guess nf_reinject() needs a fix too ;)
> >
> > I agree. That one looks uglier though, I guess we'll have to
> > iterate through all hooks to note the previous one.
>
> How about this? Unfortunately I don't think we can avoid
> iterating through all hooks without violating RCU rules.
>
>

/* Continue traversal iff userspace said ok... */
if (verdict == NF_REPEAT) {
- elem = elem->prev;
- verdict = NF_ACCEPT;
+ prev = NULL;
+ list_for_each_entry_rcu(i,
&nf_hooks[entry->pf][entry->hook],
+ list) {
+ if (&i->list == elem)
+ break;
+ prev = i;

Hmm... what happens if "elem" was the first elem in list ?

We exit with prev = NULL --> NF_DROP ?

I must miss something...

+ }
+
+ if (prev == NULL ||
+ &i->list == &nf_hooks[entry->pf][entry->hook])
+ verdict = NF_DROP;
+ else {
+ elem = &prev->list;
+ verdict = NF_ACCEPT;
+ }
}