Re: [PATCH net] net: qed: prevent buffer overflow when collecting debug data

From: Alexander Lobakin
Date: Fri Jul 03 2020 - 19:58:09 EST


From: David Miller <davem@xxxxxxxxxxxxx>
Date: Fri, 03 Jul 2020 12:59:33 -0700 (PDT)

> From: Alexander Lobakin <alobakin@xxxxxxxxxxx>
> Date: Fri, 3 Jul 2020 12:02:58 +0300
>
> > When generating debug dump, driver firstly collects all data in binary
> > form, and then performs per-feature formatting to human-readable if it
> > is supported.
> > The size of the new formatted data is often larger than the raw's. This
> > becomes critical when user requests dump via ethtool (-d/-w), as output
> > buffer size is strictly determined (by ethtool_ops::get_regs_len() etc),
> > as it may lead to out-of-bounds writes and memory corruption.
> >
> > To not go past initial lengths, add a flag to return original,
> > non-formatted debug data, and set it in such cases. Also set data type
> > in regdump headers, so userland parsers could handle it.
> >
> > Fixes: c965db444629 ("qed: Add support for debug data collection")
> > Signed-off-by: Alexander Lobakin <alobakin@xxxxxxxxxxx>
> > Signed-off-by: Igor Russkikh <irusskikh@xxxxxxxxxxx>
>
> This is now how ethtool register dumps work.
>
> It does not provide "human readable" versions of register data. Instead
> it is supposed to be purely raw data and then userland utilities interpret
> that data and can make it human readable based upon the driver name and
> reg dump version.
>
> Please fix your ethtool -d implementation to comply with this.

This is exactly what this patch does: forces driver to dump raw binary
data. Current mainline version tries to perform formatting before passing
data up to ethtool infra.

> Thank you.

Thanks,
Al