netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] inet_diag: fix possible overflow in inet_diag_dump_one_icsk()
@ 2015-03-13 16:09 Eric Dumazet
  2015-03-13 16:47 ` Eric Dumazet
  2015-03-13 16:49 ` [PATCH v2 " Eric Dumazet
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2015-03-13 16:09 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

From: Eric Dumazet <edumazet@google.com>

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>
---
 net/ipv4/inet_diag.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 81751f12645f..3ad64c8e4079 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -71,6 +71,20 @@ static inline void inet_diag_unlock_handler(
 	mutex_unlock(&inet_diag_table_mutex);
 }
 
+size_t inet_sk_attr_size(void)
+{
+	return	  nla_total_size(sizeof(struct tcp_info))
+		+ nla_total_size(1) /* INET_DIAG_SHUTDOWN */
+		+ nla_total_size(1) /* INET_DIAG_TOS */
+		+ nla_total_size(1) /* INET_DIAG_TCLASS */
+		+ nla_total_size(sizeof(struct inet_diag_meminfo))
+		+ nla_total_size(sizeof(struct inet_diag_msg))
+		+ nla_total_size(SK_MEMINFO_VARS * sizeof(u32))
+		+ nla_total_size(TCP_CA_NAME_MAX)
+		+ nla_total_size(sizeof(struct tcpvegas_info))
+		+ 64;
+}
+
 int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 			      struct sk_buff *skb, struct inet_diag_req_v2 *req,
 			      struct user_namespace *user_ns,		      	
@@ -326,9 +340,7 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *in_s
 	if (err)
 		goto out;
 
-	rep = nlmsg_new(sizeof(struct inet_diag_msg) +
-			sizeof(struct inet_diag_meminfo) +
-			sizeof(struct tcp_info) + 64, GFP_KERNEL);
+	rep = nlmsg_new(inet_sk_attr_size(), GFP_KERNEL);
 	if (!rep) {
 		err = -ENOMEM;
 		goto out;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] inet_diag: fix possible overflow in inet_diag_dump_one_icsk()
  2015-03-13 16:09 [PATCH net] inet_diag: fix possible overflow in inet_diag_dump_one_icsk() Eric Dumazet
@ 2015-03-13 16:47 ` Eric Dumazet
  2015-03-13 16:49 ` [PATCH v2 " Eric Dumazet
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2015-03-13 16:47 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

On Fri, 2015-03-13 at 09:09 -0700, Eric Dumazet wrote:


> 
> diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
> index 81751f12645f..3ad64c8e4079 100644
> --- a/net/ipv4/inet_diag.c
> +++ b/net/ipv4/inet_diag.c
> @@ -71,6 +71,20 @@ static inline void inet_diag_unlock_handler(
>  	mutex_unlock(&inet_diag_table_mutex);
>  }
>  
> +size_t inet_sk_attr_size(void)

Arg, I forgot static here, will send a v2

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 net] inet_diag: fix possible overflow in inet_diag_dump_one_icsk()
  2015-03-13 16:09 [PATCH net] inet_diag: fix possible overflow in inet_diag_dump_one_icsk() Eric Dumazet
  2015-03-13 16:47 ` Eric Dumazet
@ 2015-03-13 16:49 ` Eric Dumazet
  2015-03-13 19:55   ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2015-03-13 16:49 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

From: Eric Dumazet <edumazet@google.com>

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>
---
v2: added missing 'static' qualifier

 net/ipv4/inet_diag.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 81751f12645f..592aff37366b 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -71,6 +71,20 @@ static inline void inet_diag_unlock_handler(
 	mutex_unlock(&inet_diag_table_mutex);
 }
 
+static size_t inet_sk_attr_size(void)
+{
+	return	  nla_total_size(sizeof(struct tcp_info))
+		+ nla_total_size(1) /* INET_DIAG_SHUTDOWN */
+		+ nla_total_size(1) /* INET_DIAG_TOS */
+		+ nla_total_size(1) /* INET_DIAG_TCLASS */
+		+ nla_total_size(sizeof(struct inet_diag_meminfo))
+		+ nla_total_size(sizeof(struct inet_diag_msg))
+		+ nla_total_size(SK_MEMINFO_VARS * sizeof(u32))
+		+ nla_total_size(TCP_CA_NAME_MAX)
+		+ nla_total_size(sizeof(struct tcpvegas_info))
+		+ 64;
+}
+
 int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
 			      struct sk_buff *skb, struct inet_diag_req_v2 *req,
 			      struct user_namespace *user_ns,		      	
@@ -326,9 +340,7 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *in_s
 	if (err)
 		goto out;
 
-	rep = nlmsg_new(sizeof(struct inet_diag_msg) +
-			sizeof(struct inet_diag_meminfo) +
-			sizeof(struct tcp_info) + 64, GFP_KERNEL);
+	rep = nlmsg_new(inet_sk_attr_size(), GFP_KERNEL);
 	if (!rep) {
 		err = -ENOMEM;
 		goto out;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 net] inet_diag: fix possible overflow in inet_diag_dump_one_icsk()
  2015-03-13 16:49 ` [PATCH v2 " Eric Dumazet
@ 2015-03-13 19:55   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2015-03-13 19:55 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 13 Mar 2015 09:49:59 -0700

> From: Eric Dumazet <edumazet@google.com>
> 
> 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>
> ---
> v2: added missing 'static' qualifier

Applied and queued up for -stable, thanks Eric.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-03-13 19:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-13 16:09 [PATCH net] inet_diag: fix possible overflow in inet_diag_dump_one_icsk() Eric Dumazet
2015-03-13 16:47 ` Eric Dumazet
2015-03-13 16:49 ` [PATCH v2 " Eric Dumazet
2015-03-13 19:55   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).