Re: [BUG] NULL pointer dereference in skb_dequeue

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Jarek Poplawski <jarkao2@...>
Cc: David Miller <davem@...>, <emil.s.tantilov@...>, <jeffrey.t.kirsher@...>, <netdev@...>
Date: Tuesday, August 12, 2008 - 4:18 pm

On Tue, Aug 12, 2008 at 08:09:27PM +0200, Jarek Poplawski wrote:

The usual problem with re-reading in a separate read-side critical section
is that someone might have removed/destroyed it in the meantime.
Consider the following example:

Task 0:

	rcu_read_lock();
	p = rcu_dereference(global_pointer);
	if (p == NULL) {
		rcu_read_unlock();
		goto somewhere_else;
	}
	do_something_with(p);
	rcu_read_unlock();

	do_some_unrelated_stuff();

	rcu_read_lock();
	do_something_else_with(p);	/* BUG!!! */
	rcu_read_unlock();

	somewhere_else:

Task 1:

	spin_lock(&mylock);
	p = global_pointer;
	global_pointer = NULL;
	spin_unlock(&mylock);
	synchronize_rcu();
	kfree(p);

Suppose task 0 picks up the global_pointer just before task 1 NULLs it.
Then Task 1's synchronize_rcu() is within its rights to return as soon
as task 0 executes its first rcu_read_unlock().  This means that task
1's kfree(p) might happen before task 0's do_something_else_with(p),
which could cause general death and destruction.


It looks to me like Dave believes that there is in fact a problem:
http://marc.info/?l=linux-netdev&m=121851965707714&w=2

	But if it gets postponed into ksoftirqd... the RCU will pass
	too early.

	I'm still thinking about how to fix this without avoiding RCU
	and without adding new synchronization primitives.

The only change to Dave's comment that I would make is to his first
paragraph:

	But if it gets postponed into ksoftirqd or if the kernel has
	been built with CONFIG_PREEMPT_RCU... the RCU will pass too early.

My thought would be to use a reference count as noted earlier, on the
grounds that postponing to softirq should be relatively rare.  But again
I really cannot claim to understand this code.

Or am I missing something here?

							Thanx, Paul

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[BUG] NULL pointer dereference in skb_dequeue, Jeff Kirsher, (Fri Aug 1, 7:40 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, David Miller, (Fri Aug 1, 9:03 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, David Miller, (Fri Aug 1, 9:20 pm)
RE: [BUG] NULL pointer dereference in skb_dequeue, Tantilov, Emil S, (Sat Aug 2, 5:36 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Sat Aug 2, 9:37 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Sat Aug 2, 12:27 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, David Miller, (Sat Aug 2, 3:18 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Sat Aug 2, 4:19 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Sun Aug 3, 5:29 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, David Miller, (Sun Aug 3, 5:56 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Sun Aug 3, 6:08 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Sun Aug 3, 5:50 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, David Miller, (Sat Aug 2, 3:22 pm)
RE: [BUG] NULL pointer dereference in skb_dequeue, Tantilov, Emil S, (Sat Aug 2, 3:45 pm)
RE: [BUG] NULL pointer dereference in skb_dequeue, Tantilov, Emil S, (Sat Aug 2, 5:46 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, David Miller, (Sat Aug 2, 10:26 pm)
RE: [BUG] NULL pointer dereference in skb_dequeue, Tantilov, Emil S, (Fri Aug 8, 3:38 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, David Miller, (Sat Aug 9, 3:29 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Sat Aug 9, 6:32 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Sun Aug 10, 3:04 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Mon Aug 11, 6:01 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, Paul E. McKenney, (Mon Aug 11, 7:26 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Tue Aug 12, 2:36 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, Paul E. McKenney, (Tue Aug 12, 9:42 am)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Tue Aug 12, 2:09 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, Paul E. McKenney, (Tue Aug 12, 4:18 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, Jarek Poplawski, (Tue Aug 12, 5:15 pm)
Re: [BUG] NULL pointer dereference in skb_dequeue, Paul E. McKenney, (Tue Aug 12, 6:33 pm)