lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 13 Jun 2021 13:20:43 +0100
From:   "Russell King (Oracle)" <linux@...linux.org.uk>
To:     Reto Schneider <code@...o-schneider.ch>
Cc:     devicetree@...r.kernel.org, linux-mediatek@...ts.infradead.org,
        netdev@...r.kernel.org, Stefan Roese <sr@...x.de>,
        Reto Schneider <reto.schneider@...qvarnagroup.com>,
        "David S. Miller" <davem@...emloft.net>,
        Felix Fietkau <nbd@....name>, Jakub Kicinski <kuba@...nel.org>,
        John Crispin <john@...ozen.org>,
        Mark Lee <Mark-MC.Lee@...iatek.com>,
        Matthias Brugger <matthias.bgg@...il.com>,
        Sean Wang <sean.wang@...iatek.com>,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname

On Sun, Jun 13, 2021 at 01:58:19PM +0200, Reto Schneider wrote:
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 64adfd24e134..8bb09801918f 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2948,6 +2948,7 @@ static const struct net_device_ops mtk_netdev_ops = {
>  static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
>  {
>  	const __be32 *_id = of_get_property(np, "reg", NULL);
> +	const char *const name = of_get_property(np, "label", NULL);
>  	phy_interface_t phy_mode;
>  	struct phylink *phylink;
>  	struct mtk_mac *mac;
> @@ -3020,6 +3021,9 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
>  
>  	mac->phylink = phylink;
>  
> +	if (name)
> +		strncpy(eth->netdev[id]->name, name, IFNAMSIZ);

Please don't use strncpy() - this is a good example why strncpy() is bad
news.

 * strncpy - Copy a length-limited, C-string
 * @dest: Where to copy the string to
 * @src: Where to copy the string from
 * @count: The maximum number of bytes to copy
 *
 * The result is not %NUL-terminated if the source exceeds
 * @count bytes.

Consequently, if "name" is IFNAMSIZ bytes or longer,
eth->netdev[id]->name will not be NUL terminated, and subsequent use
will run off the end of the string. strscpy() is safer to use here.

Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ