Skip to content

Commit f87fda0

Browse files
edumazetdavem330
authored andcommitted
bonding: prevent out of bound accesses
ether_addr_equal_64bits() requires some care about its arguments, namely that 8 bytes might be read, even if last 2 byte values are not used. KASan detected a violation with null_mac_addr and lacpdu_mcast_addr in bond_3ad.c Same problem with mac_bcast[] and mac_v6_allmcast[] in bond_alb.c : Although the 8-byte alignment was there, KASan would detect out of bound accesses. Fixes: 815117a ("bonding: use ether_addr_equal_unaligned for bond addr compare") Fixes: bb54e58 ("bonding: Verify RX LACPDU has proper dest mac-addr") Fixes: 885a136 ("bonding: use compare_ether_addr_64bits() in ALB") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Dmitry Vyukov <dvyukov@google.com> Acked-by: Dmitry Vyukov <dvyukov@google.com> Acked-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> Acked-by: Ding Tianhong <dingtianhong@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3d8c453 commit f87fda0

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎drivers/net/bonding/bond_3ad.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ enum ad_link_speed_type {
101101
#define MAC_ADDRESS_EQUAL(A, B) \
102102
ether_addr_equal_64bits((const u8 *)A, (const u8 *)B)
103103

104-
static struct mac_addr null_mac_addr = { { 0, 0, 0, 0, 0, 0 } };
104+
static const u8 null_mac_addr[ETH_ALEN + 2] __long_aligned = {
105+
0, 0, 0, 0, 0, 0
106+
};
105107
static u16 ad_ticks_per_sec;
106108
static const int ad_delta_in_ticks = (AD_TIMER_INTERVAL * HZ) / 1000;
107109

108-
static const u8 lacpdu_mcast_addr[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
110+
static const u8 lacpdu_mcast_addr[ETH_ALEN + 2] __long_aligned =
111+
MULTICAST_LACPDU_ADDR;
109112

110113
/* ================= main 802.3ad protocol functions ================== */
111114
static int ad_lacpdu_send(struct port *port);
@@ -1739,7 +1742,7 @@ static void ad_clear_agg(struct aggregator *aggregator)
17391742
aggregator->is_individual = false;
17401743
aggregator->actor_admin_aggregator_key = 0;
17411744
aggregator->actor_oper_aggregator_key = 0;
1742-
aggregator->partner_system = null_mac_addr;
1745+
eth_zero_addr(aggregator->partner_system.mac_addr_value);
17431746
aggregator->partner_system_priority = 0;
17441747
aggregator->partner_oper_aggregator_key = 0;
17451748
aggregator->receive_state = 0;
@@ -1761,7 +1764,7 @@ static void ad_initialize_agg(struct aggregator *aggregator)
17611764
if (aggregator) {
17621765
ad_clear_agg(aggregator);
17631766

1764-
aggregator->aggregator_mac_address = null_mac_addr;
1767+
eth_zero_addr(aggregator->aggregator_mac_address.mac_addr_value);
17651768
aggregator->aggregator_identifier = 0;
17661769
aggregator->slave = NULL;
17671770
}

‎drivers/net/bonding/bond_alb.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@
4242

4343

4444

45-
#ifndef __long_aligned
46-
#define __long_aligned __attribute__((aligned((sizeof(long)))))
47-
#endif
48-
static const u8 mac_bcast[ETH_ALEN] __long_aligned = {
45+
static const u8 mac_bcast[ETH_ALEN + 2] __long_aligned = {
4946
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
5047
};
51-
static const u8 mac_v6_allmcast[ETH_ALEN] __long_aligned = {
48+
static const u8 mac_v6_allmcast[ETH_ALEN + 2] __long_aligned = {
5249
0x33, 0x33, 0x00, 0x00, 0x00, 0x01
5350
};
5451
static const int alb_delta_in_ticks = HZ / ALB_TIMER_TICKS_PER_SEC;

‎include/net/bonding.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
#define BOND_DEFAULT_MIIMON 100
3636

37+
#ifndef __long_aligned
38+
#define __long_aligned __attribute__((aligned((sizeof(long)))))
39+
#endif
3740
/*
3841
* Less bad way to call ioctl from within the kernel; this needs to be
3942
* done some other way to get the call out of interrupt context.
@@ -138,7 +141,9 @@ struct bond_params {
138141
struct reciprocal_value reciprocal_packets_per_slave;
139142
u16 ad_actor_sys_prio;
140143
u16 ad_user_port_key;
141-
u8 ad_actor_system[ETH_ALEN];
144+
145+
/* 2 bytes of padding : see ether_addr_equal_64bits() */
146+
u8 ad_actor_system[ETH_ALEN + 2];
142147
};
143148

144149
struct bond_parm_tbl {

0 commit comments

Comments
 (0)