Skip to content

Commit 36e56b1

Browse files
stonezdmkuba-moo
authored andcommitted
ax25: Fix reference count leak issue of net_device
There is a reference count leak issue of the object "net_device" in ax25_dev_device_down(). When the ax25 device is shutting down, the ax25_dev_device_down() drops the reference count of net_device one or zero times depending on if we goto unlock_put or not, which will cause memory leak. In order to solve the above issue, decrease the reference count of net_device after dev->ax25_ptr is set to null. Fixes: d01ffb9 ("ax25: add refcount in ax25_dev to avoid UAF bugs") Suggested-by: Dan Carpenter <[email protected]> Signed-off-by: Duoming Zhou <[email protected]> Reviewed-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/7ce3b23a40d9084657ba1125432f0ecc380cbc80.1715247018.git.duoming@zju.edu.cn Signed-off-by: Jakub Kicinski <[email protected]>
1 parent b505e03 commit 36e56b1

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

net/ax25/ax25_dev.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,10 @@ void ax25_dev_device_down(struct net_device *dev)
118118
list_for_each_entry(s, &ax25_dev_list, list) {
119119
if (s == ax25_dev) {
120120
list_del(&s->list);
121-
goto unlock_put;
121+
break;
122122
}
123123
}
124-
dev->ax25_ptr = NULL;
125-
spin_unlock_bh(&ax25_dev_lock);
126-
ax25_dev_put(ax25_dev);
127-
return;
128124

129-
unlock_put:
130125
dev->ax25_ptr = NULL;
131126
spin_unlock_bh(&ax25_dev_lock);
132127
netdev_put(dev, &ax25_dev->dev_tracker);

0 commit comments

Comments
 (0)