aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/inet_diag.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/inet_diag.c')
-rw-r--r--net/ipv4/inet_diag.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index bd3f661803a7..ba3ae1f73abf 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -246,6 +246,18 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
246 return inet_csk_diag_fill(sk, skb, r, pid, seq, nlmsg_flags, unlh); 246 return inet_csk_diag_fill(sk, skb, r, pid, seq, nlmsg_flags, unlh);
247} 247}
248 248
249int inet_diag_check_cookie(struct sock *sk, struct inet_diag_req *req)
250{
251 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
252 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
253 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
254 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
255 return -ESTALE;
256 else
257 return 0;
258}
259EXPORT_SYMBOL_GPL(inet_diag_check_cookie);
260
249static int inet_diag_get_exact(struct sk_buff *in_skb, 261static int inet_diag_get_exact(struct sk_buff *in_skb,
250 const struct nlmsghdr *nlh, 262 const struct nlmsghdr *nlh,
251 struct inet_diag_req *req) 263 struct inet_diag_req *req)
@@ -288,11 +300,8 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
288 if (sk == NULL) 300 if (sk == NULL)
289 goto unlock; 301 goto unlock;
290 302
291 err = -ESTALE; 303 err = inet_diag_check_cookie(sk, req);
292 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE || 304 if (err)
293 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
294 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
295 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
296 goto out; 305 goto out;
297 306
298 err = -ENOMEM; 307 err = -ENOMEM;