Skip to content

Commit

Permalink
net: macsec: fix net device access prior to holding a lock
Browse files Browse the repository at this point in the history
[ Upstream commit f3b4a00 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Emeel Hakim authored and gregkh committed Dec 31, 2022
1 parent a472f06 commit 0578f99
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions drivers/net/macsec.c
Expand Up @@ -2580,7 +2580,7 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
const struct macsec_ops *ops;
struct macsec_context ctx;
struct macsec_dev *macsec;
int ret;
int ret = 0;

if (!attrs[MACSEC_ATTR_IFINDEX])
return -EINVAL;
Expand All @@ -2593,28 +2593,36 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
macsec_genl_offload_policy, NULL))
return -EINVAL;

rtnl_lock();

dev = get_dev_from_nl(genl_info_net(info), attrs);
if (IS_ERR(dev))
return PTR_ERR(dev);
if (IS_ERR(dev)) {
ret = PTR_ERR(dev);
goto out;
}
macsec = macsec_priv(dev);

if (!tb_offload[MACSEC_OFFLOAD_ATTR_TYPE])
return -EINVAL;
if (!tb_offload[MACSEC_OFFLOAD_ATTR_TYPE]) {
ret = -EINVAL;
goto out;
}

offload = nla_get_u8(tb_offload[MACSEC_OFFLOAD_ATTR_TYPE]);
if (macsec->offload == offload)
return 0;
goto out;

/* Check if the offloading mode is supported by the underlying layers */
if (offload != MACSEC_OFFLOAD_OFF &&
!macsec_check_offload(offload, macsec))
return -EOPNOTSUPP;
!macsec_check_offload(offload, macsec)) {
ret = -EOPNOTSUPP;
goto out;
}

/* Check if the net device is busy. */
if (netif_running(dev))
return -EBUSY;

rtnl_lock();
if (netif_running(dev)) {
ret = -EBUSY;
goto out;
}

prev_offload = macsec->offload;
macsec->offload = offload;
Expand Down Expand Up @@ -2649,7 +2657,7 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)

rollback:
macsec->offload = prev_offload;

out:
rtnl_unlock();
return ret;
}
Expand Down

0 comments on commit 0578f99

Please sign in to comment.