Re: [PATCH net] net: ethtool: pse-pd: Fix possible null-deref

From: Kory Maincent
Date: Tue Jul 09 2024 - 10:43:31 EST


On Tue, 9 Jul 2024 07:18:46 -0700
Jakub Kicinski <kuba@xxxxxxxxxx> wrote:

> > - if (pse_has_podl(phydev->psec))
> > + if (tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL])
> > config.podl_admin_control =
> > nla_get_u32(tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL]);
> > - if (pse_has_c33(phydev->psec))
> > + if (tb[ETHTOOL_A_C33_PSE_ADMIN_CONTROL])
> > config.c33_admin_control =
> > nla_get_u32(tb[ETHTOOL_A_C33_PSE_ADMIN_CONTROL]);
> > /* Return errno directly - PSE has no notification */
>
> At a glance this doesn't follow usual ethtool flow.
> If user doesn't specify a value the previous configuration should be
> kept. We init config to 0. Is 0 a special value for both those params
> which tells drivers "don't change" ?

Mmh in case of a PSE controller supporting PoE or PoDL on its ports, a 0 config
value will return a ENOTSUPP error from the PSE core. We might have an issue in
that case which doesn't exist for now as there is no such controller.

As a PSE port can't be PoE and PoDL maybe the PSE type should be related to the
PSE port and not the full PSE driver.

> Normal ethtool flow is to first fill in the data with a ->get() then
> modify what user wants to change.
>
> Either we need:
> - an explanation in the commit message how this keeps old config; or
> - a ->get() to keep the previous values; or
> - just reject setting one value but not the other in
> ethnl_set_pse_validate() (assuming it never worked, anyway).

In fact it is the contrary we can't set both value at the same time because a
PSE port can't be a PoE and a PoDL power interface at the same time.

Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com