Skip to content

Commit f3b4a00

Browse files
Emeel Hakimkuba-moo
authored andcommitted
net: macsec: fix net device access prior to holding a lock
Currently macsec offload selection update routine accesses the net device prior to holding the relevant lock. Fix by holding the lock prior to the device access. Fixes: dcb780f ("net: macsec: add nla support for changing the offloading selection") Reviewed-by: Raed Salem <raeds@nvidia.com> Signed-off-by: Emeel Hakim <ehakim@nvidia.com> Link: https://lore.kernel.org/r/20221211075532.28099-1-ehakim@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7e68dd7 commit f3b4a00

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

drivers/net/macsec.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,7 +2593,7 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
25932593
const struct macsec_ops *ops;
25942594
struct macsec_context ctx;
25952595
struct macsec_dev *macsec;
2596-
int ret;
2596+
int ret = 0;
25972597

25982598
if (!attrs[MACSEC_ATTR_IFINDEX])
25992599
return -EINVAL;
@@ -2606,28 +2606,36 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
26062606
macsec_genl_offload_policy, NULL))
26072607
return -EINVAL;
26082608

2609+
rtnl_lock();
2610+
26092611
dev = get_dev_from_nl(genl_info_net(info), attrs);
2610-
if (IS_ERR(dev))
2611-
return PTR_ERR(dev);
2612+
if (IS_ERR(dev)) {
2613+
ret = PTR_ERR(dev);
2614+
goto out;
2615+
}
26122616
macsec = macsec_priv(dev);
26132617

2614-
if (!tb_offload[MACSEC_OFFLOAD_ATTR_TYPE])
2615-
return -EINVAL;
2618+
if (!tb_offload[MACSEC_OFFLOAD_ATTR_TYPE]) {
2619+
ret = -EINVAL;
2620+
goto out;
2621+
}
26162622

26172623
offload = nla_get_u8(tb_offload[MACSEC_OFFLOAD_ATTR_TYPE]);
26182624
if (macsec->offload == offload)
2619-
return 0;
2625+
goto out;
26202626

26212627
/* Check if the offloading mode is supported by the underlying layers */
26222628
if (offload != MACSEC_OFFLOAD_OFF &&
2623-
!macsec_check_offload(offload, macsec))
2624-
return -EOPNOTSUPP;
2629+
!macsec_check_offload(offload, macsec)) {
2630+
ret = -EOPNOTSUPP;
2631+
goto out;
2632+
}
26252633

26262634
/* Check if the net device is busy. */
2627-
if (netif_running(dev))
2628-
return -EBUSY;
2629-
2630-
rtnl_lock();
2635+
if (netif_running(dev)) {
2636+
ret = -EBUSY;
2637+
goto out;
2638+
}
26312639

26322640
prev_offload = macsec->offload;
26332641
macsec->offload = offload;
@@ -2662,7 +2670,7 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
26622670

26632671
rollback:
26642672
macsec->offload = prev_offload;
2665-
2673+
out:
26662674
rtnl_unlock();
26672675
return ret;
26682676
}

0 commit comments

Comments
 (0)