Skip to content

Commit

Permalink
net, bonding: Disallow vlan+srcmac with XDP
Browse files Browse the repository at this point in the history
The new vlan+srcmac xmit policy is not implementable with XDP since
in many cases the 802.1Q payload is not present in the packet. This
can be for example due to hardware offload or in the case of veth
due to use of skbuffs internally.

This also fixes the NULL deref with the vlan+srcmac xmit policy
reported by Jonathan Toppins by additionally checking the skb
pointer.

Fixes: a815bde ("net, bonding: Refactor bond_xmit_hash for use with xdp_buff")
Reported-by: Jonathan Toppins <jtoppins@redhat.com>
Signed-off-by: Jussi Maki <joamaki@gmail.com>
Reviewed-by: Jonathan Toppins <jtoppins@redhat.com>
Link: https://lore.kernel.org/r/20210812145241.12449-1-joamaki@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jussi Maki authored and Jakub Kicinski committed Aug 13, 2021
1 parent 876c14a commit 39a0876
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,15 @@ static bool bond_xdp_check(struct bonding *bond)
switch (BOND_MODE(bond)) {
case BOND_MODE_ROUNDROBIN:
case BOND_MODE_ACTIVEBACKUP:
return true;
case BOND_MODE_8023AD:
case BOND_MODE_XOR:
return true;
/* vlan+srcmac is not supported with XDP as in most cases the 802.1q
* payload is not in the packet due to hardware offload.
*/
if (bond->params.xmit_policy != BOND_XMIT_POLICY_VLAN_SRCMAC)
return true;
fallthrough;
default:
return false;
}
Expand Down Expand Up @@ -3744,9 +3750,9 @@ static bool bond_flow_ip(struct sk_buff *skb, struct flow_keys *fk, const void *

static u32 bond_vlan_srcmac_hash(struct sk_buff *skb, const void *data, int mhoff, int hlen)
{
struct ethhdr *mac_hdr;
u32 srcmac_vendor = 0, srcmac_dev = 0;
u16 vlan;
struct ethhdr *mac_hdr;
u16 vlan = 0;
int i;

data = bond_pull_data(skb, data, hlen, mhoff + sizeof(struct ethhdr));
Expand All @@ -3760,10 +3766,8 @@ static u32 bond_vlan_srcmac_hash(struct sk_buff *skb, const void *data, int mhof
for (i = 3; i < ETH_ALEN; i++)
srcmac_dev = (srcmac_dev << 8) | mac_hdr->h_source[i];

if (!skb_vlan_tag_present(skb))
return srcmac_vendor ^ srcmac_dev;

vlan = skb_vlan_tag_get(skb);
if (skb && skb_vlan_tag_present(skb))
vlan = skb_vlan_tag_get(skb);

return vlan ^ srcmac_vendor ^ srcmac_dev;
}
Expand Down

0 comments on commit 39a0876

Please sign in to comment.