diff options
author | Michal Kubeček <mkubecek@suse.cz> | 2016-12-02 03:33:41 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-12-02 14:03:20 -0500 |
commit | 3de81b758853f0b29c61e246679d20b513c4cfec (patch) | |
tree | fe4107dc49e976bfeeacd6cae7b18ac8dd179851 /net | |
parent | f0d21e894713b43a75bdf2d1b31e587bd5db5341 (diff) |
tipc: check minimum bearer MTU
Qian Zhang (张谦) reported a potential socket buffer overflow in
tipc_msg_build() which is also known as CVE-2016-8632: due to
insufficient checks, a buffer overflow can occur if MTU is too short for
even tipc headers. As anyone can set device MTU in a user/net namespace,
this issue can be abused by a regular user.
As agreed in the discussion on Ben Hutchings' original patch, we should
check the MTU at the moment a bearer is attached rather than for each
processed packet. We also need to repeat the check when bearer MTU is
adjusted to new device MTU. UDP case also needs a check to avoid
overflow when calculating bearer MTU.
Fixes: b97bf3fd8f6a ("[TIPC] Initial merge")
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
Reported-by: Qian Zhang (张谦) <zhangqian-c@360.cn>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/tipc/bearer.c | 11 | ||||
-rw-r--r-- | net/tipc/bearer.h | 13 | ||||
-rw-r--r-- | net/tipc/udp_media.c | 5 |
3 files changed, 27 insertions, 2 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 975dbeb60ab0..52d74760fb68 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
@@ -421,6 +421,10 @@ int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b, | |||
421 | dev = dev_get_by_name(net, driver_name); | 421 | dev = dev_get_by_name(net, driver_name); |
422 | if (!dev) | 422 | if (!dev) |
423 | return -ENODEV; | 423 | return -ENODEV; |
424 | if (tipc_mtu_bad(dev, 0)) { | ||
425 | dev_put(dev); | ||
426 | return -EINVAL; | ||
427 | } | ||
424 | 428 | ||
425 | /* Associate TIPC bearer with L2 bearer */ | 429 | /* Associate TIPC bearer with L2 bearer */ |
426 | rcu_assign_pointer(b->media_ptr, dev); | 430 | rcu_assign_pointer(b->media_ptr, dev); |
@@ -610,8 +614,6 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, | |||
610 | if (!b) | 614 | if (!b) |
611 | return NOTIFY_DONE; | 615 | return NOTIFY_DONE; |
612 | 616 | ||
613 | b->mtu = dev->mtu; | ||
614 | |||
615 | switch (evt) { | 617 | switch (evt) { |
616 | case NETDEV_CHANGE: | 618 | case NETDEV_CHANGE: |
617 | if (netif_carrier_ok(dev)) | 619 | if (netif_carrier_ok(dev)) |
@@ -624,6 +626,11 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, | |||
624 | tipc_reset_bearer(net, b); | 626 | tipc_reset_bearer(net, b); |
625 | break; | 627 | break; |
626 | case NETDEV_CHANGEMTU: | 628 | case NETDEV_CHANGEMTU: |
629 | if (tipc_mtu_bad(dev, 0)) { | ||
630 | bearer_disable(net, b); | ||
631 | break; | ||
632 | } | ||
633 | b->mtu = dev->mtu; | ||
627 | tipc_reset_bearer(net, b); | 634 | tipc_reset_bearer(net, b); |
628 | break; | 635 | break; |
629 | case NETDEV_CHANGEADDR: | 636 | case NETDEV_CHANGEADDR: |
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 78892e2f53e3..278ff7f616f9 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h | |||
@@ -39,6 +39,7 @@ | |||
39 | 39 | ||
40 | #include "netlink.h" | 40 | #include "netlink.h" |
41 | #include "core.h" | 41 | #include "core.h" |
42 | #include "msg.h" | ||
42 | #include <net/genetlink.h> | 43 | #include <net/genetlink.h> |
43 | 44 | ||
44 | #define MAX_MEDIA 3 | 45 | #define MAX_MEDIA 3 |
@@ -59,6 +60,9 @@ | |||
59 | #define TIPC_MEDIA_TYPE_IB 2 | 60 | #define TIPC_MEDIA_TYPE_IB 2 |
60 | #define TIPC_MEDIA_TYPE_UDP 3 | 61 | #define TIPC_MEDIA_TYPE_UDP 3 |
61 | 62 | ||
63 | /* minimum bearer MTU */ | ||
64 | #define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + INT_H_SIZE) | ||
65 | |||
62 | /** | 66 | /** |
63 | * struct tipc_media_addr - destination address used by TIPC bearers | 67 | * struct tipc_media_addr - destination address used by TIPC bearers |
64 | * @value: address info (format defined by media) | 68 | * @value: address info (format defined by media) |
@@ -215,4 +219,13 @@ void tipc_bearer_xmit(struct net *net, u32 bearer_id, | |||
215 | void tipc_bearer_bc_xmit(struct net *net, u32 bearer_id, | 219 | void tipc_bearer_bc_xmit(struct net *net, u32 bearer_id, |
216 | struct sk_buff_head *xmitq); | 220 | struct sk_buff_head *xmitq); |
217 | 221 | ||
222 | /* check if device MTU is too low for tipc headers */ | ||
223 | static inline bool tipc_mtu_bad(struct net_device *dev, unsigned int reserve) | ||
224 | { | ||
225 | if (dev->mtu >= TIPC_MIN_BEARER_MTU + reserve) | ||
226 | return false; | ||
227 | netdev_warn(dev, "MTU too low for tipc bearer\n"); | ||
228 | return true; | ||
229 | } | ||
230 | |||
218 | #endif /* _TIPC_BEARER_H */ | 231 | #endif /* _TIPC_BEARER_H */ |
diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c index 78cab9c5a445..b58dc95f3d35 100644 --- a/net/tipc/udp_media.c +++ b/net/tipc/udp_media.c | |||
@@ -697,6 +697,11 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, | |||
697 | udp_conf.local_ip.s_addr = htonl(INADDR_ANY); | 697 | udp_conf.local_ip.s_addr = htonl(INADDR_ANY); |
698 | udp_conf.use_udp_checksums = false; | 698 | udp_conf.use_udp_checksums = false; |
699 | ub->ifindex = dev->ifindex; | 699 | ub->ifindex = dev->ifindex; |
700 | if (tipc_mtu_bad(dev, sizeof(struct iphdr) + | ||
701 | sizeof(struct udphdr))) { | ||
702 | err = -EINVAL; | ||
703 | goto err; | ||
704 | } | ||
700 | b->mtu = dev->mtu - sizeof(struct iphdr) | 705 | b->mtu = dev->mtu - sizeof(struct iphdr) |
701 | - sizeof(struct udphdr); | 706 | - sizeof(struct udphdr); |
702 | #if IS_ENABLED(CONFIG_IPV6) | 707 | #if IS_ENABLED(CONFIG_IPV6) |