aboutsummaryrefslogtreecommitdiffstats
path: root/net/atm/mpoa_caches.c
diff options
context:
space:
mode:
authorReshetova, Elena <elena.reshetova@intel.com>2017-07-04 08:53:04 -0400
committerDavid S. Miller <davem@davemloft.net>2017-07-04 17:35:16 -0400
commite00bdbefab731638c0764cf1b9b7398bfbf2bd99 (patch)
tree72bc4d11110dff1ada8d38d27cc671687fd92115 /net/atm/mpoa_caches.c
parent937149125448290c5d60da2816556409287750ea (diff)
net, atm: convert eg_cache_entry.use 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>
Diffstat (limited to 'net/atm/mpoa_caches.c')
-rw-r--r--net/atm/mpoa_caches.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
index 05e89e9930d5..4ccaa16b1eb1 100644
--- a/net/atm/mpoa_caches.c
+++ b/net/atm/mpoa_caches.c
@@ -339,7 +339,7 @@ static eg_cache_entry *eg_cache_get_by_cache_id(__be32 cache_id,
339 entry = mpc->eg_cache; 339 entry = mpc->eg_cache;
340 while (entry != NULL) { 340 while (entry != NULL) {
341 if (entry->ctrl_info.cache_id == cache_id) { 341 if (entry->ctrl_info.cache_id == cache_id) {
342 atomic_inc(&entry->use); 342 refcount_inc(&entry->use);
343 read_unlock_irq(&mpc->egress_lock); 343 read_unlock_irq(&mpc->egress_lock);
344 return entry; 344 return entry;
345 } 345 }
@@ -360,7 +360,7 @@ static eg_cache_entry *eg_cache_get_by_tag(__be32 tag, struct mpoa_client *mpc)
360 entry = mpc->eg_cache; 360 entry = mpc->eg_cache;
361 while (entry != NULL) { 361 while (entry != NULL) {
362 if (entry->ctrl_info.tag == tag) { 362 if (entry->ctrl_info.tag == tag) {
363 atomic_inc(&entry->use); 363 refcount_inc(&entry->use);
364 read_unlock_irqrestore(&mpc->egress_lock, flags); 364 read_unlock_irqrestore(&mpc->egress_lock, flags);
365 return entry; 365 return entry;
366 } 366 }
@@ -382,7 +382,7 @@ static eg_cache_entry *eg_cache_get_by_vcc(struct atm_vcc *vcc,
382 entry = mpc->eg_cache; 382 entry = mpc->eg_cache;
383 while (entry != NULL) { 383 while (entry != NULL) {
384 if (entry->shortcut == vcc) { 384 if (entry->shortcut == vcc) {
385 atomic_inc(&entry->use); 385 refcount_inc(&entry->use);
386 read_unlock_irqrestore(&mpc->egress_lock, flags); 386 read_unlock_irqrestore(&mpc->egress_lock, flags);
387 return entry; 387 return entry;
388 } 388 }
@@ -402,7 +402,7 @@ static eg_cache_entry *eg_cache_get_by_src_ip(__be32 ipaddr,
402 entry = mpc->eg_cache; 402 entry = mpc->eg_cache;
403 while (entry != NULL) { 403 while (entry != NULL) {
404 if (entry->latest_ip_addr == ipaddr) { 404 if (entry->latest_ip_addr == ipaddr) {
405 atomic_inc(&entry->use); 405 refcount_inc(&entry->use);
406 read_unlock_irq(&mpc->egress_lock); 406 read_unlock_irq(&mpc->egress_lock);
407 return entry; 407 return entry;
408 } 408 }
@@ -415,7 +415,7 @@ static eg_cache_entry *eg_cache_get_by_src_ip(__be32 ipaddr,
415 415
416static void eg_cache_put(eg_cache_entry *entry) 416static void eg_cache_put(eg_cache_entry *entry)
417{ 417{
418 if (atomic_dec_and_test(&entry->use)) { 418 if (refcount_dec_and_test(&entry->use)) {
419 memset(entry, 0, sizeof(eg_cache_entry)); 419 memset(entry, 0, sizeof(eg_cache_entry));
420 kfree(entry); 420 kfree(entry);
421 } 421 }
@@ -468,7 +468,7 @@ static eg_cache_entry *eg_cache_add_entry(struct k_message *msg,
468 dprintk("adding an egress entry, ip = %pI4, this should be our IP\n", 468 dprintk("adding an egress entry, ip = %pI4, this should be our IP\n",
469 &msg->content.eg_info.eg_dst_ip); 469 &msg->content.eg_info.eg_dst_ip);
470 470
471 atomic_set(&entry->use, 1); 471 refcount_set(&entry->use, 1);
472 dprintk("new_eg_cache_entry: about to lock\n"); 472 dprintk("new_eg_cache_entry: about to lock\n");
473 write_lock_irq(&client->egress_lock); 473 write_lock_irq(&client->egress_lock);
474 entry->next = client->eg_cache; 474 entry->next = client->eg_cache;
@@ -484,7 +484,7 @@ static eg_cache_entry *eg_cache_add_entry(struct k_message *msg,
484 dprintk("new_eg_cache_entry cache_id %u\n", 484 dprintk("new_eg_cache_entry cache_id %u\n",
485 ntohl(entry->ctrl_info.cache_id)); 485 ntohl(entry->ctrl_info.cache_id));
486 dprintk("mps_ip = %pI4\n", &entry->ctrl_info.mps_ip); 486 dprintk("mps_ip = %pI4\n", &entry->ctrl_info.mps_ip);
487 atomic_inc(&entry->use); 487 refcount_inc(&entry->use);
488 488
489 write_unlock_irq(&client->egress_lock); 489 write_unlock_irq(&client->egress_lock);
490 dprintk("new_eg_cache_entry: unlocked\n"); 490 dprintk("new_eg_cache_entry: unlocked\n");