diff options
| author | Reshetova, Elena <elena.reshetova@intel.com> | 2017-06-30 06:08:05 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2017-07-01 10:39:08 -0400 |
| commit | 8c9814b97002f61846ebf3048e8df5aae52f7828 (patch) | |
| tree | cc555b6c6c8542b6ef5ffe213ecb76f55c62630c /net/unix | |
| parent | 433cea4d9bbb83cc848b80c51bb849a2ceb49379 (diff) | |
net: convert unix_address.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>
Diffstat (limited to 'net/unix')
| -rw-r--r-- | net/unix/af_unix.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index c88525403d2e..b9ee766054f6 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
| @@ -212,7 +212,7 @@ EXPORT_SYMBOL_GPL(unix_peer_get); | |||
| 212 | 212 | ||
| 213 | static inline void unix_release_addr(struct unix_address *addr) | 213 | static inline void unix_release_addr(struct unix_address *addr) |
| 214 | { | 214 | { |
| 215 | if (atomic_dec_and_test(&addr->refcnt)) | 215 | if (refcount_dec_and_test(&addr->refcnt)) |
| 216 | kfree(addr); | 216 | kfree(addr); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| @@ -864,7 +864,7 @@ static int unix_autobind(struct socket *sock) | |||
| 864 | goto out; | 864 | goto out; |
| 865 | 865 | ||
| 866 | addr->name->sun_family = AF_UNIX; | 866 | addr->name->sun_family = AF_UNIX; |
| 867 | atomic_set(&addr->refcnt, 1); | 867 | refcount_set(&addr->refcnt, 1); |
| 868 | 868 | ||
| 869 | retry: | 869 | retry: |
| 870 | addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short); | 870 | addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short); |
| @@ -1040,7 +1040,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) | |||
| 1040 | memcpy(addr->name, sunaddr, addr_len); | 1040 | memcpy(addr->name, sunaddr, addr_len); |
| 1041 | addr->len = addr_len; | 1041 | addr->len = addr_len; |
| 1042 | addr->hash = hash ^ sk->sk_type; | 1042 | addr->hash = hash ^ sk->sk_type; |
| 1043 | atomic_set(&addr->refcnt, 1); | 1043 | refcount_set(&addr->refcnt, 1); |
| 1044 | 1044 | ||
| 1045 | if (sun_path[0]) { | 1045 | if (sun_path[0]) { |
| 1046 | addr->hash = UNIX_HASH_SIZE; | 1046 | addr->hash = UNIX_HASH_SIZE; |
| @@ -1335,7 +1335,7 @@ restart: | |||
| 1335 | 1335 | ||
| 1336 | /* copy address information from listening to new sock*/ | 1336 | /* copy address information from listening to new sock*/ |
| 1337 | if (otheru->addr) { | 1337 | if (otheru->addr) { |
| 1338 | atomic_inc(&otheru->addr->refcnt); | 1338 | refcount_inc(&otheru->addr->refcnt); |
| 1339 | newu->addr = otheru->addr; | 1339 | newu->addr = otheru->addr; |
| 1340 | } | 1340 | } |
| 1341 | if (otheru->path.dentry) { | 1341 | if (otheru->path.dentry) { |
