Commit 6ed46d12 authored by Nicolas Dichtel's avatar Nicolas Dichtel Committed by David S. Miller

sock_diag: align nlattr properly when needed

I also fix the value of INET_DIAG_MAX. It's wrong since commit 8f840e47
which is only in net-next right now, thus I didn't make a separate patch.

Fixes: 8f840e47 ("sctp: add the sctp_diag.c file")
Signed-off-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3c6f3714
...@@ -115,9 +115,11 @@ enum { ...@@ -115,9 +115,11 @@ enum {
INET_DIAG_SKV6ONLY, INET_DIAG_SKV6ONLY,
INET_DIAG_LOCALS, INET_DIAG_LOCALS,
INET_DIAG_PEERS, INET_DIAG_PEERS,
INET_DIAG_PAD,
__INET_DIAG_MAX,
}; };
#define INET_DIAG_MAX INET_DIAG_SKV6ONLY #define INET_DIAG_MAX (__INET_DIAG_MAX - 1)
/* INET_DIAG_MEM */ /* INET_DIAG_MEM */
......
...@@ -120,7 +120,7 @@ static size_t sock_diag_nlmsg_size(void) ...@@ -120,7 +120,7 @@ static size_t sock_diag_nlmsg_size(void)
{ {
return NLMSG_ALIGN(sizeof(struct inet_diag_msg) return NLMSG_ALIGN(sizeof(struct inet_diag_msg)
+ nla_total_size(sizeof(u8)) /* INET_DIAG_PROTOCOL */ + nla_total_size(sizeof(u8)) /* INET_DIAG_PROTOCOL */
+ nla_total_size(sizeof(struct tcp_info))); /* INET_DIAG_INFO */ + nla_total_size_64bit(sizeof(struct tcp_info))); /* INET_DIAG_INFO */
} }
static void sock_diag_broadcast_destroy_work(struct work_struct *work) static void sock_diag_broadcast_destroy_work(struct work_struct *work)
......
...@@ -220,8 +220,9 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk, ...@@ -220,8 +220,9 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
} }
if ((ext & (1 << (INET_DIAG_INFO - 1))) && handler->idiag_info_size) { if ((ext & (1 << (INET_DIAG_INFO - 1))) && handler->idiag_info_size) {
attr = nla_reserve(skb, INET_DIAG_INFO, attr = nla_reserve_64bit(skb, INET_DIAG_INFO,
handler->idiag_info_size); handler->idiag_info_size,
INET_DIAG_PAD);
if (!attr) if (!attr)
goto errout; goto errout;
...@@ -1078,7 +1079,9 @@ int inet_diag_handler_get_info(struct sk_buff *skb, struct sock *sk) ...@@ -1078,7 +1079,9 @@ int inet_diag_handler_get_info(struct sk_buff *skb, struct sock *sk)
} }
attr = handler->idiag_info_size attr = handler->idiag_info_size
? nla_reserve(skb, INET_DIAG_INFO, handler->idiag_info_size) ? nla_reserve_64bit(skb, INET_DIAG_INFO,
handler->idiag_info_size,
INET_DIAG_PAD)
: NULL; : NULL;
if (attr) if (attr)
info = nla_data(attr); info = nla_data(attr);
......
...@@ -161,8 +161,9 @@ static int inet_sctp_diag_fill(struct sock *sk, struct sctp_association *asoc, ...@@ -161,8 +161,9 @@ static int inet_sctp_diag_fill(struct sock *sk, struct sctp_association *asoc,
if (ext & (1 << (INET_DIAG_INFO - 1))) { if (ext & (1 << (INET_DIAG_INFO - 1))) {
struct nlattr *attr; struct nlattr *attr;
attr = nla_reserve(skb, INET_DIAG_INFO, attr = nla_reserve_64bit(skb, INET_DIAG_INFO,
sizeof(struct sctp_info)); sizeof(struct sctp_info),
INET_DIAG_PAD);
if (!attr) if (!attr)
goto errout; goto errout;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment