Skip to content

Commit 3de81b7

Browse files
mkubecekdavem330
authored andcommitted
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: b97bf3f ("[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>
1 parent f0d21e8 commit 3de81b7

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

net/tipc/bearer.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b,
421421
dev = dev_get_by_name(net, driver_name);
422422
if (!dev)
423423
return -ENODEV;
424+
if (tipc_mtu_bad(dev, 0)) {
425+
dev_put(dev);
426+
return -EINVAL;
427+
}
424428

425429
/* Associate TIPC bearer with L2 bearer */
426430
rcu_assign_pointer(b->media_ptr, dev);
@@ -610,8 +614,6 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
610614
if (!b)
611615
return NOTIFY_DONE;
612616

613-
b->mtu = dev->mtu;
614-
615617
switch (evt) {
616618
case NETDEV_CHANGE:
617619
if (netif_carrier_ok(dev))
@@ -624,6 +626,11 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
624626
tipc_reset_bearer(net, b);
625627
break;
626628
case NETDEV_CHANGEMTU:
629+
if (tipc_mtu_bad(dev, 0)) {
630+
bearer_disable(net, b);
631+
break;
632+
}
633+
b->mtu = dev->mtu;
627634
tipc_reset_bearer(net, b);
628635
break;
629636
case NETDEV_CHANGEADDR:

net/tipc/bearer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include "netlink.h"
4141
#include "core.h"
42+
#include "msg.h"
4243
#include <net/genetlink.h>
4344

4445
#define MAX_MEDIA 3
@@ -59,6 +60,9 @@
5960
#define TIPC_MEDIA_TYPE_IB 2
6061
#define TIPC_MEDIA_TYPE_UDP 3
6162

63+
/* minimum bearer MTU */
64+
#define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + INT_H_SIZE)
65+
6266
/**
6367
* struct tipc_media_addr - destination address used by TIPC bearers
6468
* @value: address info (format defined by media)
@@ -215,4 +219,13 @@ void tipc_bearer_xmit(struct net *net, u32 bearer_id,
215219
void tipc_bearer_bc_xmit(struct net *net, u32 bearer_id,
216220
struct sk_buff_head *xmitq);
217221

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+
218231
#endif /* _TIPC_BEARER_H */

net/tipc/udp_media.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,11 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
697697
udp_conf.local_ip.s_addr = htonl(INADDR_ANY);
698698
udp_conf.use_udp_checksums = false;
699699
ub->ifindex = dev->ifindex;
700+
if (tipc_mtu_bad(dev, sizeof(struct iphdr) +
701+
sizeof(struct udphdr))) {
702+
err = -EINVAL;
703+
goto err;
704+
}
700705
b->mtu = dev->mtu - sizeof(struct iphdr)
701706
- sizeof(struct udphdr);
702707
#if IS_ENABLED(CONFIG_IPV6)

0 commit comments

Comments
 (0)