Thread (3 messages) flat view 3 messages, 2 authors, 2017-07-12

Re: netconsole refcount warning

From: Cong Wang <hidden>
Date: 2017-07-12 22:36:13
Subsystem: networking [general], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

On Wed, Jul 12, 2017 at 3:30 PM, Cong Wang [off-list ref] wrote:
On Sun, Jul 9, 2017 at 4:57 PM, Dave Jones [off-list ref] wrote:
quoted
The new refcount debugging code spews this twice during boot on my router..


refcount_t: increment on 0; use-after-free.
------------[ cut here ]------------
WARNING: CPU: 1 PID: 17 at lib/refcount.c:152 refcount_inc+0x2b/0x30
CPU: 1 PID: 17 Comm: ksoftirqd/1 Not tainted 4.12.0-firewall+ #8
task: ffff8801d4441ac0 task.stack: ffff8801d4450000
RIP: 0010:refcount_inc+0x2b/0x30
RSP: 0018:ffff8801d4456da8 EFLAGS: 00010046
RAX: 000000000000002c RBX: ffff8801d4c3cf40 RCX: 0000000000000000
RDX: 000000000000002c RSI: 0000000000000003 RDI: ffffed003a88adab
RBP: ffff8801d4456da8 R08: 0000000000000003 R09: fffffbfff4afcb57
R10: 0000000000000000 R11: fffffbfff4afcb58 R12: ffff8801d4c3c540
R13: 0000000000000082 R14: ffff8801ce9c7ff8 R15: ffff8801ce9c8aa0
FS:  0000000000000000(0000) GS:ffff8801d6a00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fa2b803156e CR3: 00000001c405d000 CR4: 00000000000406e0
Call Trace:
 zap_completion_queue+0xad/0x1a0

Sigh... it is on purpose:

commit 8a455b087c9629b3ae3b521b4f1ed16672f978cc
Author: Jarek Poplawski [off-list ref]
Date:   Thu Mar 20 16:07:27 2008 -0700

    netpoll: zap_completion_queue: adjust skb->users counter

    zap_completion_queue() retrieves skbs from completion_queue where they have
    zero skb->users counter.  Before dev_kfree_skb_any() it should be non-zero
    yet, so it's increased now.

    Reported-and-tested-by: Andrew Morton [off-list ref]
    Signed-off-by: Jarek Poplawski [off-list ref]
    Signed-off-by: Andrew Morton [off-list ref]
    Signed-off-by: David S. Miller [off-list ref]

We need to review it now. :-/
I think we should explicitly set it to 1 with refcount_set() since
we know it was 0 for sure.
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index d3408a6..8357f16 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -277,7 +277,7 @@ static void zap_completion_queue(void)
                        struct sk_buff *skb = clist;
                        clist = clist->next;
                        if (!skb_irq_freeable(skb)) {
-                               refcount_inc(&skb->users);
+                               refcount_set(&skb->users, 1);
                                dev_kfree_skb_any(skb); /* put this one back */
                        } else {
                                __kfree_skb(skb);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help