Skip to content

Commit 65d30f7

Browse files
mkubecekgregkh
authored andcommitted
tipc: check minimum bearer MTU
commit 3de81b758853f0b29c61e246679d20b513c4cfec upstream. 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> [bwh: Backported to 4.4: - Adjust context - NETDEV_GOING_DOWN and NETDEV_CHANGEMTU cases in net notifier were combined] Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9540baa commit 65d30f7

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

net/tipc/bearer.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b,
381381
dev = dev_get_by_name(net, driver_name);
382382
if (!dev)
383383
return -ENODEV;
384+
if (tipc_mtu_bad(dev, 0)) {
385+
dev_put(dev);
386+
return -EINVAL;
387+
}
384388

385389
/* Associate TIPC bearer with L2 bearer */
386390
rcu_assign_pointer(b->media_ptr, dev);
@@ -570,14 +574,19 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
570574
if (!b_ptr)
571575
return NOTIFY_DONE;
572576

573-
b_ptr->mtu = dev->mtu;
574-
575577
switch (evt) {
576578
case NETDEV_CHANGE:
577579
if (netif_carrier_ok(dev))
578580
break;
579581
case NETDEV_GOING_DOWN:
582+
tipc_reset_bearer(net, b_ptr);
583+
break;
580584
case NETDEV_CHANGEMTU:
585+
if (tipc_mtu_bad(dev, 0)) {
586+
bearer_disable(net, b_ptr);
587+
break;
588+
}
589+
b_ptr->mtu = dev->mtu;
581590
tipc_reset_bearer(net, b_ptr);
582591
break;
583592
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
@@ -61,6 +62,9 @@
6162
#define TIPC_MEDIA_TYPE_IB 2
6263
#define TIPC_MEDIA_TYPE_UDP 3
6364

65+
/* minimum bearer MTU */
66+
#define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + INT_H_SIZE)
67+
6468
/**
6569
* struct tipc_node_map - set of node identifiers
6670
* @count: # of nodes in set
@@ -226,4 +230,13 @@ void tipc_bearer_xmit(struct net *net, u32 bearer_id,
226230
void tipc_bearer_bc_xmit(struct net *net, u32 bearer_id,
227231
struct sk_buff_head *xmitq);
228232

233+
/* check if device MTU is too low for tipc headers */
234+
static inline bool tipc_mtu_bad(struct net_device *dev, unsigned int reserve)
235+
{
236+
if (dev->mtu >= TIPC_MIN_BEARER_MTU + reserve)
237+
return false;
238+
netdev_warn(dev, "MTU too low for tipc bearer\n");
239+
return true;
240+
}
241+
229242
#endif /* _TIPC_BEARER_H */

net/tipc/udp_media.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
376376
udp_conf.local_ip.s_addr = htonl(INADDR_ANY);
377377
udp_conf.use_udp_checksums = false;
378378
ub->ifindex = dev->ifindex;
379+
if (tipc_mtu_bad(dev, sizeof(struct iphdr) +
380+
sizeof(struct udphdr))) {
381+
err = -EINVAL;
382+
goto err;
383+
}
379384
b->mtu = dev->mtu - sizeof(struct iphdr)
380385
- sizeof(struct udphdr);
381386
#if IS_ENABLED(CONFIG_IPV6)

0 commit comments

Comments
 (0)