* [PATCH] net: ethtool: fix unheld rtnl lock
@ 2024-08-26 13:06 Diogo Jahchan Koike
2024-08-26 13:30 ` Przemek Kitszel
0 siblings, 1 reply; 2+ messages in thread
From: Diogo Jahchan Koike @ 2024-08-26 13:06 UTC (permalink / raw)
To: davem
Cc: edumazet, kuba, pabeni, kory.maincent, o.rempel,
maxime.chevallier, andrew, christophe.leroy, netdev, linux-kernel,
linux-kernel-mentees, syzkaller-bugs, Diogo Jahchan Koike,
syzbot+ec369e6d58e210135f71
ethnl_req_get_phydev should be called with rtnl lock
held.
Reported-by: syzbot+ec369e6d58e210135f71@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ec369e6d58e210135f71
Fixes: 31748765bed3 ("net: ethtool: pse-pd: Target the command to the requested PHY")
Signed-off-by: Diogo Jahchan Koike <djahchankoike@gmail.com>
---
net/ethtool/pse-pd.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/net/ethtool/pse-pd.c b/net/ethtool/pse-pd.c
index 507cb21d6bf0..290edbfd47d2 100644
--- a/net/ethtool/pse-pd.c
+++ b/net/ethtool/pse-pd.c
@@ -226,17 +226,21 @@ ethnl_set_pse_validate(struct ethnl_req_info *req_info, struct genl_info *info)
{
struct nlattr **tb = info->attrs;
struct phy_device *phydev;
+ int ret = 1;
+ rtnl_lock();
phydev = ethnl_req_get_phydev(req_info, tb[ETHTOOL_A_PSE_HEADER],
info->extack);
if (IS_ERR_OR_NULL(phydev)) {
NL_SET_ERR_MSG(info->extack, "No PHY is attached");
- return -EOPNOTSUPP;
+ ret = -EOPNOTSUPP;
+ goto out;
}
if (!phydev->psec) {
NL_SET_ERR_MSG(info->extack, "No PSE is attached");
- return -EOPNOTSUPP;
+ ret = -EOPNOTSUPP;
+ goto out;
}
if (tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL] &&
@@ -244,17 +248,21 @@ ethnl_set_pse_validate(struct ethnl_req_info *req_info, struct genl_info *info)
NL_SET_ERR_MSG_ATTR(info->extack,
tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL],
"setting PoDL PSE admin control not supported");
- return -EOPNOTSUPP;
+ ret = -EOPNOTSUPP;
+ goto out;
}
if (tb[ETHTOOL_A_C33_PSE_ADMIN_CONTROL] &&
!pse_has_c33(phydev->psec)) {
NL_SET_ERR_MSG_ATTR(info->extack,
tb[ETHTOOL_A_C33_PSE_ADMIN_CONTROL],
"setting C33 PSE admin control not supported");
- return -EOPNOTSUPP;
+ ret = -EOPNOTSUPP;
+ goto out;
}
- return 1;
+out:
+ rtnl_unlock();
+ return ret;
}
static int
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: ethtool: fix unheld rtnl lock
2024-08-26 13:06 [PATCH] net: ethtool: fix unheld rtnl lock Diogo Jahchan Koike
@ 2024-08-26 13:30 ` Przemek Kitszel
0 siblings, 0 replies; 2+ messages in thread
From: Przemek Kitszel @ 2024-08-26 13:30 UTC (permalink / raw)
To: Diogo Jahchan Koike
Cc: edumazet, kuba, davem, pabeni, kory.maincent, o.rempel,
maxime.chevallier, andrew, christophe.leroy, netdev, linux-kernel,
linux-kernel-mentees, syzkaller-bugs, syzbot+ec369e6d58e210135f71
On 8/26/24 15:06, Diogo Jahchan Koike wrote:
> ethnl_req_get_phydev should be called with rtnl lock
> held.
Next time please make use of more columns in commit message (75).
>
> Reported-by: syzbot+ec369e6d58e210135f71@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=ec369e6d58e210135f71
> Fixes: 31748765bed3 ("net: ethtool: pse-pd: Target the command to the requested PHY")
> Signed-off-by: Diogo Jahchan Koike <djahchankoike@gmail.com>
> ---
> net/ethtool/pse-pd.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/net/ethtool/pse-pd.c b/net/ethtool/pse-pd.c
> index 507cb21d6bf0..290edbfd47d2 100644
> --- a/net/ethtool/pse-pd.c
> +++ b/net/ethtool/pse-pd.c
> @@ -226,17 +226,21 @@ ethnl_set_pse_validate(struct ethnl_req_info *req_info, struct genl_info *info)
> {
> struct nlattr **tb = info->attrs;
> struct phy_device *phydev;
> + int ret = 1;
>
> + rtnl_lock();
> phydev = ethnl_req_get_phydev(req_info, tb[ETHTOOL_A_PSE_HEADER],
> info->extack);
Fix looks fine, thanks, I will however unlock just after
ethnl_req_get_phydev() call.
Then all ret code logic touches could be omitted.
> if (IS_ERR_OR_NULL(phydev)) {
> NL_SET_ERR_MSG(info->extack, "No PHY is attached");
> - return -EOPNOTSUPP;
> + ret = -EOPNOTSUPP;
> + goto out;
> }
>
> if (!phydev->psec) {
> NL_SET_ERR_MSG(info->extack, "No PSE is attached");
> - return -EOPNOTSUPP;
> + ret = -EOPNOTSUPP;
> + goto out;
> }
>
> if (tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL] &&
> @@ -244,17 +248,21 @@ ethnl_set_pse_validate(struct ethnl_req_info *req_info, struct genl_info *info)
> NL_SET_ERR_MSG_ATTR(info->extack,
> tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL],
> "setting PoDL PSE admin control not supported");
> - return -EOPNOTSUPP;
> + ret = -EOPNOTSUPP;
> + goto out;
> }
> if (tb[ETHTOOL_A_C33_PSE_ADMIN_CONTROL] &&
> !pse_has_c33(phydev->psec)) {
> NL_SET_ERR_MSG_ATTR(info->extack,
> tb[ETHTOOL_A_C33_PSE_ADMIN_CONTROL],
> "setting C33 PSE admin control not supported");
> - return -EOPNOTSUPP;
> + ret = -EOPNOTSUPP;
> + goto out;
> }
>
> - return 1;
> +out:
> + rtnl_unlock();
> + return ret;
> }
>
> static int
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-26 13:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-26 13:06 [PATCH] net: ethtool: fix unheld rtnl lock Diogo Jahchan Koike
2024-08-26 13:30 ` Przemek Kitszel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox