]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
net: set initial device refcount to 1
authorEric Dumazet <edumazet@google.com>
Mon, 22 Mar 2021 18:21:45 +0000 (11:21 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 Mar 2021 23:57:36 +0000 (16:57 -0700)
commitadd2d73631070c951b0de81a01d1463a15cfbd47
tree17f432ad418341482f02ec52ef9daacc01e0ee77
parent0ca99c84df6b589b4673460c48ac4064181098cc
net: set initial device refcount to 1

When adding CONFIG_PCPU_DEV_REFCNT, I forgot that the
initial net device refcount was 0.

When CONFIG_PCPU_DEV_REFCNT is not set, this means
the first dev_hold() triggers an illegal refcount
operation (addition on 0)

refcount_t: addition on 0; use-after-free.
WARNING: CPU: 0 PID: 1 at lib/refcount.c:25 refcount_warn_saturate+0x128/0x1a4

Fix is to change initial (and final) refcount to be 1.

Also add a missing kerneldoc piece, as reported by
Stephen Rothwell.

Fixes: 919067cc845f ("net: add CONFIG_PCPU_DEV_REFCNT")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Guenter Roeck <groeck@google.com>
Tested-by: Guenter Roeck <groeck@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h
net/core/dev.c