2021-10-27 21:27:35

by Ivan Vecera

[permalink] [raw]
Subject: Re: [PATCH net] net: bridge: fix uninitialized variables when BRIDGE_CFM is disabled

On Wed, 27 Oct 2021 16:54:39 +0300
Nikolay Aleksandrov <[email protected]> wrote:

> On 27/10/2021 16:49, Ivan Vecera wrote:
> > Function br_get_link_af_size_filtered() calls br_cfm_{,peer}_mep_count()
> > but does not check their return value. When BRIDGE_CFM is not enabled
> > these functions return -EOPNOTSUPP but do not modify count parameter.
> > Calling function then works with uninitialized variables.
> >
> > Fixes: b6d0425b816e ("bridge: cfm: Netlink Notifications.")
> > Signed-off-by: Ivan Vecera <[email protected]>
> > ---
> > net/bridge/br_netlink.c | 6 ++++--
> > 1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
> > index 5c6c4305ed23..12d602495ea0 100644
> > --- a/net/bridge/br_netlink.c
> > +++ b/net/bridge/br_netlink.c
> > @@ -126,8 +126,10 @@ static size_t br_get_link_af_size_filtered(const struct net_device *dev,
> > return vinfo_sz;
> >
> > /* CFM status info must be added */
> > - br_cfm_mep_count(br, &num_cfm_mep_infos);
> > - br_cfm_peer_mep_count(br, &num_cfm_peer_mep_infos);
> > + if (br_cfm_mep_count(br, &num_cfm_mep_infos) < 0)
> > + num_cfm_mep_infos = 0;
> > + if (br_cfm_peer_mep_count(br, &num_cfm_peer_mep_infos) < 0)
> > + num_cfm_peer_mep_infos = 0;
> >
> > vinfo_sz += nla_total_size(0); /* IFLA_BRIDGE_CFM */
> > /* For each status struct the MEP instance (u32) is added */
> >
>
> Hi,
> Could you please rather update the EOPNOTSUPP helpers to set these infos to 0 before
> returning? Someone else might decide to use them and hit the same bug.
>
> E.g.
> static inline int br_cfm_mep_count(struct net_bridge *br, u32 *count)
> {
> *count = 0;
> return -EOPNOTSUPP;
> }
>
> We already do the same for br_allowed_ingress, nbp_vlan_add() etc.
>
> Thanks,
> Nik
>

Ok, Nik... works for me.

Thanks,
Ivan