diff options
author | Reshetova, Elena <elena.reshetova@intel.com> | 2017-07-04 08:53:01 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-07-04 17:35:16 -0400 |
commit | 458bc30cec26c2716746ae215ed23773257e417d (patch) | |
tree | 692d00b3c0b0af34c20fdfe31b7a9cf6fa33e3be | |
parent | e0542dd5185e68247b08c3418bdba14644b4c414 (diff) |
net, atm: convert atm_dev.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
situations.
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David Windsor <dwindsor@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/linux/atmdev.h | 7 | ||||
-rw-r--r-- | net/atm/proc.c | 2 | ||||
-rw-r--r-- | net/atm/resources.c | 2 |
3 files changed, 6 insertions, 5 deletions
diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h index 4d97a89da066..0ec9bdb1cc9f 100644 --- a/include/linux/atmdev.h +++ b/include/linux/atmdev.h | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/uio.h> | 11 | #include <linux/uio.h> |
12 | #include <net/sock.h> | 12 | #include <net/sock.h> |
13 | #include <linux/atomic.h> | 13 | #include <linux/atomic.h> |
14 | #include <linux/refcount.h> | ||
14 | #include <uapi/linux/atmdev.h> | 15 | #include <uapi/linux/atmdev.h> |
15 | 16 | ||
16 | #ifdef CONFIG_PROC_FS | 17 | #ifdef CONFIG_PROC_FS |
@@ -158,7 +159,7 @@ struct atm_dev { | |||
158 | struct k_atm_dev_stats stats; /* statistics */ | 159 | struct k_atm_dev_stats stats; /* statistics */ |
159 | char signal; /* signal status (ATM_PHY_SIG_*) */ | 160 | char signal; /* signal status (ATM_PHY_SIG_*) */ |
160 | int link_rate; /* link rate (default: OC3) */ | 161 | int link_rate; /* link rate (default: OC3) */ |
161 | atomic_t refcnt; /* reference count */ | 162 | refcount_t refcnt; /* reference count */ |
162 | spinlock_t lock; /* protect internal members */ | 163 | spinlock_t lock; /* protect internal members */ |
163 | #ifdef CONFIG_PROC_FS | 164 | #ifdef CONFIG_PROC_FS |
164 | struct proc_dir_entry *proc_entry; /* proc entry */ | 165 | struct proc_dir_entry *proc_entry; /* proc entry */ |
@@ -261,13 +262,13 @@ static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size) | |||
261 | 262 | ||
262 | static inline void atm_dev_hold(struct atm_dev *dev) | 263 | static inline void atm_dev_hold(struct atm_dev *dev) |
263 | { | 264 | { |
264 | atomic_inc(&dev->refcnt); | 265 | refcount_inc(&dev->refcnt); |
265 | } | 266 | } |
266 | 267 | ||
267 | 268 | ||
268 | static inline void atm_dev_put(struct atm_dev *dev) | 269 | static inline void atm_dev_put(struct atm_dev *dev) |
269 | { | 270 | { |
270 | if (atomic_dec_and_test(&dev->refcnt)) { | 271 | if (refcount_dec_and_test(&dev->refcnt)) { |
271 | BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags)); | 272 | BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags)); |
272 | if (dev->ops->dev_close) | 273 | if (dev->ops->dev_close) |
273 | dev->ops->dev_close(dev); | 274 | dev->ops->dev_close(dev); |
diff --git a/net/atm/proc.c b/net/atm/proc.c index 27c9c01c537d..4caca2a90ec4 100644 --- a/net/atm/proc.c +++ b/net/atm/proc.c | |||
@@ -61,7 +61,7 @@ static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev) | |||
61 | add_stats(seq, "0", &dev->stats.aal0); | 61 | add_stats(seq, "0", &dev->stats.aal0); |
62 | seq_puts(seq, " "); | 62 | seq_puts(seq, " "); |
63 | add_stats(seq, "5", &dev->stats.aal5); | 63 | add_stats(seq, "5", &dev->stats.aal5); |
64 | seq_printf(seq, "\t[%d]", atomic_read(&dev->refcnt)); | 64 | seq_printf(seq, "\t[%d]", refcount_read(&dev->refcnt)); |
65 | seq_putc(seq, '\n'); | 65 | seq_putc(seq, '\n'); |
66 | } | 66 | } |
67 | 67 | ||
diff --git a/net/atm/resources.c b/net/atm/resources.c index 0447d5d0b639..918244757b7d 100644 --- a/net/atm/resources.c +++ b/net/atm/resources.c | |||
@@ -109,7 +109,7 @@ struct atm_dev *atm_dev_register(const char *type, struct device *parent, | |||
109 | else | 109 | else |
110 | memset(&dev->flags, 0, sizeof(dev->flags)); | 110 | memset(&dev->flags, 0, sizeof(dev->flags)); |
111 | memset(&dev->stats, 0, sizeof(dev->stats)); | 111 | memset(&dev->stats, 0, sizeof(dev->stats)); |
112 | atomic_set(&dev->refcnt, 1); | 112 | refcount_set(&dev->refcnt, 1); |
113 | 113 | ||
114 | if (atm_proc_dev_register(dev) < 0) { | 114 | if (atm_proc_dev_register(dev) < 0) { |
115 | pr_err("atm_proc_dev_register failed for dev %s\n", type); | 115 | pr_err("atm_proc_dev_register failed for dev %s\n", type); |