aboutsummaryrefslogtreecommitdiff
path: root/net/core
diff options
context:
space:
mode:
authorChenbo Feng <fengc@google.com>2017-04-11 10:37:06 -0700
committerMister Oyster <oysterized@gmail.com>2017-05-23 19:48:06 +0200
commit49104f1ff068f94a6644afd28d6e62315d21784e (patch)
treea2129e471c6dbc4821da6a1ad37508625e86f8aa /net/core
parent40dacaaf5628101771dc5bd45bc47bd0ea7842e5 (diff)
BACKPORT [UPSTREAM] net: add real socket cookies
Cherry-pick from upstream commit 33cf7c90fe2f97afb1cadaa0cfb782cb9d1b9ee2. Introduce a unique per netspace identifier for each socket and it is required by xt_qtaguid module to identify the socket without holding the socket reference count. The change is modified to the minimal impact so that it doesn't change other socket networking behavior. Signed-off-by: mydongistiny <jaysonedson@gmail.com> Signed-off-by: Joe Maples <joe@frap129.org>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/sock.c1
-rw-r--r--net/core/sock_diag.c12
2 files changed, 13 insertions, 0 deletions
diff --git a/net/core/sock.c b/net/core/sock.c
index 88900b4d9..ba8394b57 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1521,6 +1521,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
newsk->sk_err = 0;
newsk->sk_err_soft = 0;
newsk->sk_priority = 0;
+ atomic64_set(&newsk->sk_cookie, 0);
/*
* Before updating sk_refcnt, we must commit prior changes to memory
* (Documentation/RCU/rculist_nulls.txt for details)
diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
index 3f78978b2..3bd136463 100644
--- a/net/core/sock_diag.c
+++ b/net/core/sock_diag.c
@@ -13,6 +13,18 @@ static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
static DEFINE_MUTEX(sock_diag_table_mutex);
+static u64 sock_gen_cookie(struct sock *sk)
+{
+ while (1) {
+ u64 res = atomic64_read(&sk->sk_cookie);
+
+ if (res)
+ return res;
+ res = atomic64_inc_return(&sock_net(sk)->cookie_gen);
+ atomic64_cmpxchg(&sk->sk_cookie, 0, res);
+ }
+}
+
int sock_diag_check_cookie(void *sk, __u32 *cookie)
{
if ((cookie[0] != INET_DIAG_NOCOOKIE ||