提交 b005ab4e 编写于 作者: P Pavel Emelyanov 提交者: David S. Miller

inet_diag: Export inet diag cookie checking routine

The netlink diag susbsys stores sk address bits in the nl message
as a "cookie" and uses one when dumps details about particular
socket.

The same will be required for udp diag module, so introduce a heler
in inet_diag module
Signed-off-by: NPavel Emelyanov <xemul@parallels.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 87c22ea5
...@@ -144,6 +144,8 @@ struct inet_diag_handler { ...@@ -144,6 +144,8 @@ struct inet_diag_handler {
__u16 idiag_type; __u16 idiag_type;
}; };
int inet_diag_check_cookie(struct sock *sk, struct inet_diag_req *req);
extern int inet_diag_register(const struct inet_diag_handler *handler); extern int inet_diag_register(const struct inet_diag_handler *handler);
extern void inet_diag_unregister(const struct inet_diag_handler *handler); extern void inet_diag_unregister(const struct inet_diag_handler *handler);
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
......
...@@ -246,6 +246,18 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, ...@@ -246,6 +246,18 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
return inet_csk_diag_fill(sk, skb, r, pid, seq, nlmsg_flags, unlh); return inet_csk_diag_fill(sk, skb, r, pid, seq, nlmsg_flags, unlh);
} }
int inet_diag_check_cookie(struct sock *sk, struct inet_diag_req *req)
{
if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
(u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
return -ESTALE;
else
return 0;
}
EXPORT_SYMBOL_GPL(inet_diag_check_cookie);
static int inet_diag_get_exact(struct sk_buff *in_skb, static int inet_diag_get_exact(struct sk_buff *in_skb,
const struct nlmsghdr *nlh, const struct nlmsghdr *nlh,
struct inet_diag_req *req) struct inet_diag_req *req)
...@@ -288,11 +300,8 @@ static int inet_diag_get_exact(struct sk_buff *in_skb, ...@@ -288,11 +300,8 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
if (sk == NULL) if (sk == NULL)
goto unlock; goto unlock;
err = -ESTALE; err = inet_diag_check_cookie(sk, req);
if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE || if (err)
req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
(u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
goto out; goto out;
err = -ENOMEM; err = -ENOMEM;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册