Skip to content

Commit e1f2092

Browse files
edumazetsashalevin
authored andcommitted
inet_diag: fix possible overflow in inet_diag_dump_one_icsk()
[ Upstream commit c8e2c80 ] inet_diag_dump_one_icsk() allocates too small skb. Add inet_sk_attr_size() helper right before inet_sk_diag_fill() so that it can be updated if/when new attributes are added. iproute2/ss currently does not use this dump_one() interface, this might explain nobody noticed this problem yet. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent b9befa4 commit e1f2092

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎net/ipv4/inet_diag.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ static inline void inet_diag_unlock_handler(
7171
mutex_unlock(&inet_diag_table_mutex);
7272
}
7373

74+
static size_t inet_sk_attr_size(void)
75+
{
76+
return nla_total_size(sizeof(struct tcp_info))
77+
+ nla_total_size(1) /* INET_DIAG_SHUTDOWN */
78+
+ nla_total_size(1) /* INET_DIAG_TOS */
79+
+ nla_total_size(1) /* INET_DIAG_TCLASS */
80+
+ nla_total_size(sizeof(struct inet_diag_meminfo))
81+
+ nla_total_size(sizeof(struct inet_diag_msg))
82+
+ nla_total_size(SK_MEMINFO_VARS * sizeof(u32))
83+
+ nla_total_size(TCP_CA_NAME_MAX)
84+
+ nla_total_size(sizeof(struct tcpvegas_info))
85+
+ 64;
86+
}
87+
7488
int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
7589
struct sk_buff *skb, struct inet_diag_req_v2 *req,
7690
struct user_namespace *user_ns,
@@ -324,9 +338,7 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *in_s
324338
if (err)
325339
goto out;
326340

327-
rep = nlmsg_new(sizeof(struct inet_diag_msg) +
328-
sizeof(struct inet_diag_meminfo) +
329-
sizeof(struct tcp_info) + 64, GFP_KERNEL);
341+
rep = nlmsg_new(inet_sk_attr_size(), GFP_KERNEL);
330342
if (!rep) {
331343
err = -ENOMEM;
332344
goto out;

0 commit comments

Comments
 (0)