Re: [PATCH 3/7] net/ncsi: Use struct sockaddr_storage for pending_mac

Gustavo A. R. Silva
2025-05-20T22:48:56Z

On 20/05/25 16:31, Kees Cook wrote:
> To avoid future casting with coming API type changes, switch struct
> ncsi_dev_priv::pending_mac to a full struct sockaddr_storage.
>
> Signed-off-by: Kees Cook <kees@kernel.org>

Acked-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
-Gustavo

> ---
> Cc: Samuel Mendoza-Jonas <sam@mendozajonas.com>
> Cc: Paul Fertser <fercerpav@gmail.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Simon Horman <horms@kernel.org>
> Cc: <netdev@vger.kernel.org>
> ---
> net/ncsi/internal.h | 2 +-
> net/ncsi/ncsi-manage.c | 2 +-
> net/ncsi/ncsi-rsp.c | 18 +++++++++---------
> 3 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
> index 2c260f33b55c..e76c6de0c784 100644
> --- a/net/ncsi/internal.h
> +++ b/net/ncsi/internal.h
> @@ -322,7 +322,7 @@ struct ncsi_dev_priv {
> #define NCSI_DEV_RESHUFFLE 4
> #define NCSI_DEV_RESET 8 /* Reset state of NC */
> unsigned int gma_flag; /* OEM GMA flag */
> - struct sockaddr pending_mac; /* MAC address received from GMA */
> + struct sockaddr_storage pending_mac; /* MAC address received from GMA */
> spinlock_t lock; /* Protect the NCSI device */
> unsigned int package_probe_id;/* Current ID during probe */
> unsigned int package_num; /* Number of packages */
> diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
> index b36947063783..0202db2aea3e 100644
> --- a/net/ncsi/ncsi-manage.c
> +++ b/net/ncsi/ncsi-manage.c
> @@ -1058,7 +1058,7 @@ static void ncsi_configure_channel(struct ncsi_dev_priv *ndp)
> break;
> case ncsi_dev_state_config_apply_mac:
> rtnl_lock();
> - ret = dev_set_mac_address(dev, &ndp->pending_mac, NULL);
> + ret = dev_set_mac_address(dev, (struct sockaddr *)&ndp->pending_mac, NULL);
> rtnl_unlock();
> if (ret < 0)
> netdev_warn(dev, "NCSI: 'Writing MAC address to device failed\n");
> diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
> index 8668888c5a2f..472cc68ad86f 100644
> --- a/net/ncsi/ncsi-rsp.c
> +++ b/net/ncsi/ncsi-rsp.c
> @@ -628,7 +628,7 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
> static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
> {
> struct ncsi_dev_priv *ndp = nr->ndp;
> - struct sockaddr *saddr = &ndp->pending_mac;
> + struct sockaddr_storage *saddr = &ndp->pending_mac;
> struct net_device *ndev = ndp->ndev.dev;
> struct ncsi_rsp_oem_pkt *rsp;
> u32 mac_addr_off = 0;
> @@ -644,11 +644,11 @@ static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
> else if (mfr_id == NCSI_OEM_MFR_INTEL_ID)
> mac_addr_off = INTEL_MAC_ADDR_OFFSET;
>
> - saddr->sa_family = ndev->type;
> - memcpy(saddr->sa_data, &rsp->data[mac_addr_off], ETH_ALEN);
> + saddr->ss_family = ndev->type;
> + memcpy(saddr->__data, &rsp->data[mac_addr_off], ETH_ALEN);
> if (mfr_id == NCSI_OEM_MFR_BCM_ID || mfr_id == NCSI_OEM_MFR_INTEL_ID)
> - eth_addr_inc((u8 *)saddr->sa_data);
> - if (!is_valid_ether_addr((const u8 *)saddr->sa_data))
> + eth_addr_inc(saddr->__data);
> + if (!is_valid_ether_addr(saddr->__data))
> return -ENXIO;
>
> /* Set the flag for GMA command which should only be called once */
> @@ -1088,7 +1088,7 @@ static int ncsi_rsp_handler_netlink(struct ncsi_request *nr)
> static int ncsi_rsp_handler_gmcma(struct ncsi_request *nr)
> {
> struct ncsi_dev_priv *ndp = nr->ndp;
> - struct sockaddr *saddr = &ndp->pending_mac;
> + struct sockaddr_storage *saddr = &ndp->pending_mac;
> struct net_device *ndev = ndp->ndev.dev;
> struct ncsi_rsp_gmcma_pkt *rsp;
> int i;
> @@ -1105,15 +1105,15 @@ static int ncsi_rsp_handler_gmcma(struct ncsi_request *nr)
> rsp->addresses[i][4], rsp->addresses[i][5]);
> }
>
> - saddr->sa_family = ndev->type;
> + saddr->ss_family = ndev->type;
> for (i = 0; i < rsp->address_count; i++) {
> if (!is_valid_ether_addr(rsp->addresses[i])) {
> netdev_warn(ndev, "NCSI: Unable to assign %pM to device\n",
> rsp->addresses[i]);
> continue;
> }
> - memcpy(saddr->sa_data, rsp->addresses[i], ETH_ALEN);
> - netdev_warn(ndev, "NCSI: Will set MAC address to %pM\n", saddr->sa_data);
> + memcpy(saddr->__data, rsp->addresses[i], ETH_ALEN);
> + netdev_warn(ndev, "NCSI: Will set MAC address to %pM\n", saddr->__data);
> break;
> }
>