Re: [PATCH] af_key: fix netns ops ordering on module load/unload

From: Luca Tettamanti
Date: Mon Feb 01 2010 - 08:50:20 EST


On Sat, Jan 30, 2010 at 1:53 PM, Alexey Dobriyan <adobriyan@xxxxxxxxx> wrote:
> On Fri, Jan 29, 2010 at 05:33:26PM +0100, Eric Dumazet wrote:
>> @@ -3807,21 +3807,24 @@ static int __init ipsec_pfkey_init(void)
>> Â Â Â if (err != 0)
>> Â Â Â Â Â Â Â goto out;
>>
>> - Â Â err = sock_register(&pfkey_family_ops);
>> - Â Â if (err != 0)
>> - Â Â Â Â Â Â goto out_unregister_key_proto;
>> Â Â Â err = xfrm_register_km(&pfkeyv2_mgr);
>> Â Â Â if (err != 0)
>> - Â Â Â Â Â Â goto out_sock_unregister;
>> + Â Â Â Â Â Â goto out_unregister_key_proto;
>> +
>> Â Â Â err = register_pernet_subsys(&pfkey_net_ops);
>> Â Â Â if (err != 0)
>> Â Â Â Â Â Â Â goto out_xfrm_unregister_km;
>> +
>> + Â Â err = sock_register(&pfkey_family_ops);
>> + Â Â if (err != 0)
>> + Â Â Â Â Â Â goto out_unregister_pernet;
>> Âout:
>> Â Â Â return err;
>> +
>> +out_unregister_pernet:
>> + Â Â unregister_pernet_subsys(&pfkey_net_ops);
>> Âout_xfrm_unregister_km:
>> Â Â Â xfrm_unregister_km(&pfkeyv2_mgr);
>> -out_sock_unregister:
>> - Â Â sock_unregister(PF_KEY);
>> Âout_unregister_key_proto:
>> Â Â Â proto_unregister(&key_proto);
>> Â Â Â goto out;
>
> ACK analysis, except this is not enough.
>
> Here is patch which survived netns start/stop/modprobe/rmmod cycles.
>
> Â Â Â ÂAlexey, who still doesn't get why bug reproduces so easily for bug reporter.
>
> Luca, please confirm.

Seems to work fine.

> [PATCH] af_key: fix netns ops ordering on module load/unload
>
> 1. After sock_register() returns, it's possible to create sockets,
> Â even if module still not initialized fully (blame generic module code
> Â for that!)
> 2. Consequently, pfkey_create() can be called with pfkey_net_id still not
> Â initialized which will BUG_ON in net_generic():
> Â Â Â Âkernel BUG at include/net/netns/generic.h:43!
> 3. During netns shutdown, netns ops should be unregistered after
> Â key manager unregistered because key manager calls can be triggered
> Â from xfrm_user module:
>
> Â Â Â Âgeneral protection fault: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
> Â Â Â Âpfkey_broadcast+0x111/0x210 [af_key]
> Â Â Â Âpfkey_send_notify+0x16a/0x300 [af_key]
> Â Â Â Âkm_state_notify+0x41/0x70
> Â Â Â Âxfrm_flush_sa+0x75/0x90 [xfrm_user]
> 4. Unregister netns ops after socket ops just in case and for symmetry.
>
> Reported by Luca Tettamanti.
>
> Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>

Tested-by: Luca Tettamanti <kronos.it@xxxxxxxxx>

thanks,
Luca
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/