Commit 7658b36f authored by Reshetova, Elena's avatar Reshetova, Elena Committed by David S. Miller

net: convert in_device.refcnt from atomic_t to refcount_t

refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
Signed-off-by: default avatarElena Reshetova <>
Signed-off-by: default avatarHans Liljestrand <>
Signed-off-by: default avatarKees Cook <>
Signed-off-by: default avatarDavid Windsor <>
Signed-off-by: default avatarDavid S. Miller <>
parent 8851ab52
......@@ -11,6 +11,7 @@
#include <linux/timer.h>
#include <linux/sysctl.h>
#include <linux/rtnetlink.h>
#include <linux/refcount.h>
struct ipv4_devconf {
void *sysctl;
......@@ -22,7 +23,7 @@ struct ipv4_devconf {
struct in_device {
struct net_device *dev;
atomic_t refcnt;
refcount_t refcnt;
int dead;
struct in_ifaddr *ifa_list; /* IP ifaddr chain */
......@@ -219,7 +220,7 @@ static inline struct in_device *in_dev_get(const struct net_device *dev)
in_dev = __in_dev_get_rcu(dev);
if (in_dev)
return in_dev;
......@@ -240,12 +241,12 @@ void in_dev_finish_destroy(struct in_device *idev);
static inline void in_dev_put(struct in_device *idev)
if (atomic_dec_and_test(&idev->refcnt))
if (refcount_dec_and_test(&idev->refcnt))
#define __in_dev_put(idev) atomic_dec(&(idev)->refcnt)
#define in_dev_hold(idev) atomic_inc(&(idev)->refcnt)
#define __in_dev_put(idev) refcount_dec(&(idev)->refcnt)
#define in_dev_hold(idev) refcount_inc(&(idev)->refcnt)
#endif /* __KERNEL__ */
......@@ -252,7 +252,7 @@ static struct in_device *inetdev_init(struct net_device *dev)
/* Reference in_dev->dev */
/* Account for reference dev->ip_ptr (below) */
refcount_set(&in_dev->refcnt, 1);
err = devinet_sysctl_register(in_dev);
if (err) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment