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

net: convert netlbl_lsm_cache.refcount 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: default avatarElena Reshetova <elena.reshetova@intel.com>
Signed-off-by: default avatarHans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid Windsor <dwindsor@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c122e14d
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include <linux/in6.h> #include <linux/in6.h>
#include <net/netlink.h> #include <net/netlink.h>
#include <net/request_sock.h> #include <net/request_sock.h>
#include <linux/atomic.h> #include <linux/refcount.h>
struct cipso_v4_doi; struct cipso_v4_doi;
struct calipso_doi; struct calipso_doi;
...@@ -136,7 +136,7 @@ struct netlbl_audit { ...@@ -136,7 +136,7 @@ struct netlbl_audit {
* *
*/ */
struct netlbl_lsm_cache { struct netlbl_lsm_cache {
atomic_t refcount; refcount_t refcount;
void (*free) (const void *data); void (*free) (const void *data);
void *data; void *data;
}; };
...@@ -295,7 +295,7 @@ static inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags) ...@@ -295,7 +295,7 @@ static inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags)
cache = kzalloc(sizeof(*cache), flags); cache = kzalloc(sizeof(*cache), flags);
if (cache) if (cache)
atomic_set(&cache->refcount, 1); refcount_set(&cache->refcount, 1);
return cache; return cache;
} }
...@@ -309,7 +309,7 @@ static inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags) ...@@ -309,7 +309,7 @@ static inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags)
*/ */
static inline void netlbl_secattr_cache_free(struct netlbl_lsm_cache *cache) static inline void netlbl_secattr_cache_free(struct netlbl_lsm_cache *cache)
{ {
if (!atomic_dec_and_test(&cache->refcount)) if (!refcount_dec_and_test(&cache->refcount))
return; return;
if (cache->free) if (cache->free)
......
...@@ -265,7 +265,7 @@ static int cipso_v4_cache_check(const unsigned char *key, ...@@ -265,7 +265,7 @@ static int cipso_v4_cache_check(const unsigned char *key,
entry->key_len == key_len && entry->key_len == key_len &&
memcmp(entry->key, key, key_len) == 0) { memcmp(entry->key, key, key_len) == 0) {
entry->activity += 1; entry->activity += 1;
atomic_inc(&entry->lsm_data->refcount); refcount_inc(&entry->lsm_data->refcount);
secattr->cache = entry->lsm_data; secattr->cache = entry->lsm_data;
secattr->flags |= NETLBL_SECATTR_CACHE; secattr->flags |= NETLBL_SECATTR_CACHE;
secattr->type = NETLBL_NLTYPE_CIPSOV4; secattr->type = NETLBL_NLTYPE_CIPSOV4;
...@@ -332,7 +332,7 @@ int cipso_v4_cache_add(const unsigned char *cipso_ptr, ...@@ -332,7 +332,7 @@ int cipso_v4_cache_add(const unsigned char *cipso_ptr,
} }
entry->key_len = cipso_ptr_len; entry->key_len = cipso_ptr_len;
entry->hash = cipso_v4_map_cache_hash(cipso_ptr, cipso_ptr_len); entry->hash = cipso_v4_map_cache_hash(cipso_ptr, cipso_ptr_len);
atomic_inc(&secattr->cache->refcount); refcount_inc(&secattr->cache->refcount);
entry->lsm_data = secattr->cache; entry->lsm_data = secattr->cache;
bkt = entry->hash & (CIPSO_V4_CACHE_BUCKETS - 1); bkt = entry->hash & (CIPSO_V4_CACHE_BUCKETS - 1);
......
...@@ -227,7 +227,7 @@ static int calipso_cache_check(const unsigned char *key, ...@@ -227,7 +227,7 @@ static int calipso_cache_check(const unsigned char *key,
entry->key_len == key_len && entry->key_len == key_len &&
memcmp(entry->key, key, key_len) == 0) { memcmp(entry->key, key, key_len) == 0) {
entry->activity += 1; entry->activity += 1;
atomic_inc(&entry->lsm_data->refcount); refcount_inc(&entry->lsm_data->refcount);
secattr->cache = entry->lsm_data; secattr->cache = entry->lsm_data;
secattr->flags |= NETLBL_SECATTR_CACHE; secattr->flags |= NETLBL_SECATTR_CACHE;
secattr->type = NETLBL_NLTYPE_CALIPSO; secattr->type = NETLBL_NLTYPE_CALIPSO;
...@@ -296,7 +296,7 @@ static int calipso_cache_add(const unsigned char *calipso_ptr, ...@@ -296,7 +296,7 @@ static int calipso_cache_add(const unsigned char *calipso_ptr,
} }
entry->key_len = calipso_ptr_len; entry->key_len = calipso_ptr_len;
entry->hash = calipso_map_cache_hash(calipso_ptr, calipso_ptr_len); entry->hash = calipso_map_cache_hash(calipso_ptr, calipso_ptr_len);
atomic_inc(&secattr->cache->refcount); refcount_inc(&secattr->cache->refcount);
entry->lsm_data = secattr->cache; entry->lsm_data = secattr->cache;
bkt = entry->hash & (CALIPSO_CACHE_BUCKETS - 1); bkt = entry->hash & (CALIPSO_CACHE_BUCKETS - 1);
......
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