invalid socket structure with ip_early_demux
Subsystems (3)
Recently I've struggled with crashes in the xt_qtaguid netfilter module. This module is written by Google and used with Android. The match function in xt_qtaguid eventually tries to access
skb->sk->sk_socket->file
What I find is that the sk->sk_socket pointer is sometimes 0xAAAAAAAA, or PAGE_POISON. In fact everything after the first 16 bytes of the struct sock sk is PAGE_POISON. I've confirmed that if I change PAGE_POISON, the values I see in the sk structure change as well.
I was curious how this structure was being allocated/initialized and instrumented the sk_alloc, sk_free, and sk_clone_lock functions. When xt_qtaguid encounters a bad struct sock, that sock does not show up as ever having been allocated (or freed).
The struct sock is being assigned to the skb in tcb_v4_early_demux(). I modified that function immediately after the sk is assigned from __inet_lookup_established() to panic if the sk has a sk_socket pointer of PAGE_POISON. I can reproduce that condition on my target by simply attempting to mount an NFS volume. Initiating *and* aborting wget operations also reproduces the issue - simply initiating a bunch of wgets is not enough to trigger it.
I have not yet been able to reproduce the bad condition when disabling ip_early_demux via the sysctl. Any possibility this is an actual issue with that feature? My target is an MSM using the ks8851 ethernet module.
thanks,
Steve
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 24 lines · Steve Muckle
Recently I've struggled with crashes in the
xt_qtaguidnetfilter module. This module is written by Google and used with Android. The match function inxt_qtaguideventually tries to access
skb->sk->sk_socket->fileWhat I find is that the
sk->sk_socketpointer is sometimes0xAAAAAAAA, orPAGE_POISON. In fact everything after the first 16 bytes of the struct sock sk isPAGE_POISON. I've confirmed that if I changePAGE_POISON, the values I see in the sk structure change as well.I was curious how this structure was being allocated/initialized and instrumented the
sk_alloc,sk_free, andsk_clone_lockfunctions. Whenxt_qtaguidencounters a bad struct sock, that sock does not show up as ever having been allocated (or freed).The struct sock is being assigned to the skb in
tcb_v4_early_demux(). I modified that function immediately after the sk is assigned from__inet_lookup_established()to panic if the sk has ask_socketpointer ofPAGE_POISON. I can reproduce that condition on my target by simply attempting to mount an NFS volume. Initiating *and* aborting wget operations also reproduces the issue - simply initiating a bunch of wgets is not enough to trigger it.
Quoted 3 lines
I have not yet been able to reproduce the bad condition when disabling
ip_early_demuxvia the sysctl. Any possibility this is an actual issue with that feature? My target is an MSM using the ks8851 ethernet module.
skb->sk might be a TIMEWAIT socket.
Therefore, you cant blindly use skb->sk->sk_socket
Quoted 4 lines · Eric Dumazet
skb->skmight be a TIMEWAIT socket.Therefore, you cant blindly use
skb->sk->sk_socket
A fix would be to add after :
sk = skb->sk;
the following code :
if (sk && sk->sk_state == TCP_TIME_WAIT)
sk = NULL;
Quoted 8 lines · Eric Dumazet
A fix would be to add after :
sk =
skb->sk;the following code :
if (sk &&
sk->sk_state==TCP_TIME_WAIT)sk = NULL;
Thanks. I assumed the xt_qtaguid code was ok because xt_owner does a similar thing - does that also need this fix?
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 5 lines · Steve Muckle
Quoted 4 lines · Eric Dumazet
A fix would be to add after :
sk =
skb->sk;
Quoted 8 lines
Quoted 4 lines
the following code :
if (sk &&
sk->sk_state==TCP_TIME_WAIT)sk = NULL;Thanks. I assumed the
xt_qtaguidcode was ok becausext_ownerdoes a similar thing - does that also need this fix?
I believe xt_owner only is valid on the OUT path (LOCAL_OUT and POST_ROUTING), so it shouldnt be an issue.
I fixed netfilter modules in
commit 0626af3139572610b56376580d11eb65d45d9dd7
Author: Eric Dumazet <[email protected]> Date: Tue Sep 4 07:49:03 2012 +0000
netfilter: take care of timewait sockets
Sami Farin reported crashes in xt_LOG because it assumes skb->sk is a full blown socket.
Since (41063e9 ipv4: Early TCP socket demux), we can have skb->sk pointing to a timewait socket.
Same fix is needed in nfnetlink_log.