netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: sched: ensure opts_len <= IP_TUNNEL_OPTS_MAX in act_tunnel_key
@ 2019-11-18  9:39 Xin Long
  2019-11-18 13:02 ` Simon Horman
  2019-11-19  1:18 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Xin Long @ 2019-11-18  9:39 UTC (permalink / raw)
  To: network dev; +Cc: davem, Simon Horman, Jakub Kicinski, Pieter Jansen van Vuuren

info->options_len is 'u8' type, and when opts_len with a value >
IP_TUNNEL_OPTS_MAX, 'info->options_len = opts_len' will cast int
to u8 and set a wrong value to info->options_len.

Kernel crashed in my test when doing:

  # opts="0102:80:00800022"
  # for i in {1..99}; do opts="$opts,0102:80:00800022"; done
  # ip link add name geneve0 type geneve dstport 0 external
  # tc qdisc add dev eth0 ingress
  # tc filter add dev eth0 protocol ip parent ffff: \
       flower indev eth0 ip_proto udp action tunnel_key \
       set src_ip 10.0.99.192 dst_ip 10.0.99.193 \
       dst_port 6081 id 11 geneve_opts $opts \
       action mirred egress redirect dev geneve0

So we should do the similar check as cls_flower does, return error
when opts_len > IP_TUNNEL_OPTS_MAX in tunnel_key_copy_opts().

Fixes: 0ed5269f9e41 ("net/sched: add tunnel option support to act_tunnel_key")
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sched/act_tunnel_key.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index 2f83a79..d55669e 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -135,6 +135,10 @@ static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst,
 			if (opt_len < 0)
 				return opt_len;
 			opts_len += opt_len;
+			if (opts_len > IP_TUNNEL_OPTS_MAX) {
+				NL_SET_ERR_MSG(extack, "Tunnel options exceeds max size");
+				return -EINVAL;
+			}
 			if (dst) {
 				dst_len -= opt_len;
 				dst += opt_len;
-- 
2.1.0


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

* Re: [PATCH net] net: sched: ensure opts_len <= IP_TUNNEL_OPTS_MAX in act_tunnel_key
  2019-11-18  9:39 [PATCH net] net: sched: ensure opts_len <= IP_TUNNEL_OPTS_MAX in act_tunnel_key Xin Long
@ 2019-11-18 13:02 ` Simon Horman
  2019-11-19  1:18 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2019-11-18 13:02 UTC (permalink / raw)
  To: Xin Long; +Cc: network dev, davem, Jakub Kicinski, Pieter Jansen van Vuuren

On Mon, Nov 18, 2019 at 05:39:34PM +0800, Xin Long wrote:
> info->options_len is 'u8' type, and when opts_len with a value >
> IP_TUNNEL_OPTS_MAX, 'info->options_len = opts_len' will cast int
> to u8 and set a wrong value to info->options_len.
> 
> Kernel crashed in my test when doing:
> 
>   # opts="0102:80:00800022"
>   # for i in {1..99}; do opts="$opts,0102:80:00800022"; done
>   # ip link add name geneve0 type geneve dstport 0 external
>   # tc qdisc add dev eth0 ingress
>   # tc filter add dev eth0 protocol ip parent ffff: \
>        flower indev eth0 ip_proto udp action tunnel_key \
>        set src_ip 10.0.99.192 dst_ip 10.0.99.193 \
>        dst_port 6081 id 11 geneve_opts $opts \
>        action mirred egress redirect dev geneve0
> 
> So we should do the similar check as cls_flower does, return error
> when opts_len > IP_TUNNEL_OPTS_MAX in tunnel_key_copy_opts().
> 
> Fixes: 0ed5269f9e41 ("net/sched: add tunnel option support to act_tunnel_key")
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Reviewed-by: Simon Horman <simon.horman@netronome.com>

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

* Re: [PATCH net] net: sched: ensure opts_len <= IP_TUNNEL_OPTS_MAX in act_tunnel_key
  2019-11-18  9:39 [PATCH net] net: sched: ensure opts_len <= IP_TUNNEL_OPTS_MAX in act_tunnel_key Xin Long
  2019-11-18 13:02 ` Simon Horman
@ 2019-11-19  1:18 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-11-19  1:18 UTC (permalink / raw)
  To: lucien.xin; +Cc: netdev, simon.horman, jakub.kicinski, pieter.jansenvanvuuren

From: Xin Long <lucien.xin@gmail.com>
Date: Mon, 18 Nov 2019 17:39:34 +0800

> info->options_len is 'u8' type, and when opts_len with a value >
> IP_TUNNEL_OPTS_MAX, 'info->options_len = opts_len' will cast int
> to u8 and set a wrong value to info->options_len.
> 
> Kernel crashed in my test when doing:
> 
>   # opts="0102:80:00800022"
>   # for i in {1..99}; do opts="$opts,0102:80:00800022"; done
>   # ip link add name geneve0 type geneve dstport 0 external
>   # tc qdisc add dev eth0 ingress
>   # tc filter add dev eth0 protocol ip parent ffff: \
>        flower indev eth0 ip_proto udp action tunnel_key \
>        set src_ip 10.0.99.192 dst_ip 10.0.99.193 \
>        dst_port 6081 id 11 geneve_opts $opts \
>        action mirred egress redirect dev geneve0
> 
> So we should do the similar check as cls_flower does, return error
> when opts_len > IP_TUNNEL_OPTS_MAX in tunnel_key_copy_opts().
> 
> Fixes: 0ed5269f9e41 ("net/sched: add tunnel option support to act_tunnel_key")
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Applied and queued up for -stable.

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

end of thread, other threads:[~2019-11-19  1:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-18  9:39 [PATCH net] net: sched: ensure opts_len <= IP_TUNNEL_OPTS_MAX in act_tunnel_key Xin Long
2019-11-18 13:02 ` Simon Horman
2019-11-19  1:18 ` 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).