Skip to contentSkip to conversation

use after free in x25_destroy_socket

BUG Stephen Hemminger 1 participant 1 message Aug 4, 2003 X.25 stack

lore
Share & tools
lore
#0 lore raw

Got BUG in spinlock unlock from x25_destroy_socket using 2.6.0-test2. All I did was load X.25 module, then do an ifconfig.

The following looks very suspicious.

void x25_destroy_socket(struct sock *sk)

{
	struct sk_buff *skb;

	sock_hold(sk);
	lock_sock(sk);
	x25_stop_heartbeat(sk);
	x25_stop_timer(sk);

...

	if (atomic_read(&sk->sk_wmem_alloc) ||
	    atomic_read(&sk->sk_rmem_alloc)) {
		/* Defer: outstanding buffers */
		init_timer(&sk->sk_timer);
		sk->sk_timer.expires  = jiffies + 10 * HZ;
		sk->sk_timer.function = x25_destroy_timer;
		sk->sk_timer.data     = (unsigned long)sk;
		add_timer(&sk->sk_timer);
	} else
		sk_free(sk);
	release_sock(sk);		<-- hey, sk was freed in previous line.
	sock_put(sk);			<-- this will BUG because sk has been poisened
}