Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c9814b9 authored by Reshetova, Elena's avatar Reshetova, Elena Committed by David S. Miller
Browse files

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: 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 433cea4d
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@
#include <linux/socket.h>
#include <linux/socket.h>
#include <linux/un.h>
#include <linux/un.h>
#include <linux/mutex.h>
#include <linux/mutex.h>
#include <linux/refcount.h>
#include <net/sock.h>
#include <net/sock.h>


void unix_inflight(struct user_struct *user, struct file *fp);
void unix_inflight(struct user_struct *user, struct file *fp);
@@ -21,7 +22,7 @@ extern spinlock_t unix_table_lock;
extern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
extern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];


struct unix_address {
struct unix_address {
	atomic_t	refcnt;
	refcount_t	refcnt;
	int		len;
	int		len;
	unsigned int	hash;
	unsigned int	hash;
	struct sockaddr_un name[0];
	struct sockaddr_un name[0];
+4 −4
Original line number Original line Diff line number Diff line
@@ -212,7 +212,7 @@ EXPORT_SYMBOL_GPL(unix_peer_get);


static inline void unix_release_addr(struct unix_address *addr)
static inline void unix_release_addr(struct unix_address *addr)
{
{
	if (atomic_dec_and_test(&addr->refcnt))
	if (refcount_dec_and_test(&addr->refcnt))
		kfree(addr);
		kfree(addr);
}
}


@@ -864,7 +864,7 @@ static int unix_autobind(struct socket *sock)
		goto out;
		goto out;


	addr->name->sun_family = AF_UNIX;
	addr->name->sun_family = AF_UNIX;
	atomic_set(&addr->refcnt, 1);
	refcount_set(&addr->refcnt, 1);


retry:
retry:
	addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short);
	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)
	memcpy(addr->name, sunaddr, addr_len);
	memcpy(addr->name, sunaddr, addr_len);
	addr->len = addr_len;
	addr->len = addr_len;
	addr->hash = hash ^ sk->sk_type;
	addr->hash = hash ^ sk->sk_type;
	atomic_set(&addr->refcnt, 1);
	refcount_set(&addr->refcnt, 1);


	if (sun_path[0]) {
	if (sun_path[0]) {
		addr->hash = UNIX_HASH_SIZE;
		addr->hash = UNIX_HASH_SIZE;
@@ -1335,7 +1335,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,


	/* copy address information from listening to new sock*/
	/* copy address information from listening to new sock*/
	if (otheru->addr) {
	if (otheru->addr) {
		atomic_inc(&otheru->addr->refcnt);
		refcount_inc(&otheru->addr->refcnt);
		newu->addr = otheru->addr;
		newu->addr = otheru->addr;
	}
	}
	if (otheru->path.dentry) {
	if (otheru->path.dentry) {