diff mbox series

[v2] scsi: fcoe: Statically initialize flogi_maddr

Message ID 20210602180000.3326448-1-keescook@chromium.org (mailing list archive)
State Accepted
Headers show
Series [v2] scsi: fcoe: Statically initialize flogi_maddr | expand

Commit Message

Kees Cook June 2, 2021, 6 p.m. UTC
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memcpy() avoid using an inline const buffer
argument and instead just statically initialize the destination array
directly.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
v2:
 - use "static const" (Joe)
v1: https://lore.kernel.org/lkml/20210528181337.792268-2-keescook@chromium.org/
---
 drivers/scsi/fcoe/fcoe.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Gustavo A. R. Silva June 2, 2021, 6:41 p.m. UTC | #1
On 6/2/21 13:00, Kees Cook wrote:
> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memcpy() avoid using an inline const buffer
> argument and instead just statically initialize the destination array
> directly.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>

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

Thanks
--
Gustavo

> ---
> v2:
>  - use "static const" (Joe)
> v1: https://lore.kernel.org/lkml/20210528181337.792268-2-keescook@chromium.org/
> ---
>  drivers/scsi/fcoe/fcoe.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
> index 89ec735929c3..5ae6c207d3ac 100644
> --- a/drivers/scsi/fcoe/fcoe.c
> +++ b/drivers/scsi/fcoe/fcoe.c
> @@ -293,7 +293,7 @@ static int fcoe_interface_setup(struct fcoe_interface *fcoe,
>  	struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
>  	struct netdev_hw_addr *ha;
>  	struct net_device *real_dev;
> -	u8 flogi_maddr[ETH_ALEN];
> +	static const u8 flogi_maddr[ETH_ALEN] = FC_FCOE_FLOGI_MAC;
>  	const struct net_device_ops *ops;
>  
>  	fcoe->netdev = netdev;
> @@ -336,7 +336,6 @@ static int fcoe_interface_setup(struct fcoe_interface *fcoe,
>  	 * or enter promiscuous mode if not capable of listening
>  	 * for multiple unicast MACs.
>  	 */
> -	memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
>  	dev_uc_add(netdev, flogi_maddr);
>  	if (fip->spma)
>  		dev_uc_add(netdev, fip->ctl_src_addr);
> @@ -442,7 +441,7 @@ static void fcoe_interface_remove(struct fcoe_interface *fcoe)
>  {
>  	struct net_device *netdev = fcoe->netdev;
>  	struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
> -	u8 flogi_maddr[ETH_ALEN];
> +	static const u8 flogi_maddr[ETH_ALEN] = FC_FCOE_FLOGI_MAC;
>  	const struct net_device_ops *ops;
>  
>  	/*
> @@ -458,7 +457,6 @@ static void fcoe_interface_remove(struct fcoe_interface *fcoe)
>  	synchronize_net();
>  
>  	/* Delete secondary MAC addresses */
> -	memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
>  	dev_uc_del(netdev, flogi_maddr);
>  	if (fip->spma)
>  		dev_uc_del(netdev, fip->ctl_src_addr);
>
Martin K. Petersen June 8, 2021, 1:30 a.m. UTC | #2
Kees,

> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memcpy() avoid using an inline const buffer
> argument and instead just statically initialize the destination array
> directly.

Applied to 5.14/scsi-staging, thanks!
Martin K. Petersen June 16, 2021, 3:49 a.m. UTC | #3
On Wed, 2 Jun 2021 11:00:00 -0700, Kees Cook wrote:

> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memcpy() avoid using an inline const buffer
> argument and instead just statically initialize the destination array
> directly.

Applied to 5.14/scsi-queue, thanks!

[1/1] scsi: fcoe: Statically initialize flogi_maddr
      https://git.kernel.org/mkp/scsi/c/ebab8e09a07f
diff mbox series

Patch

diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 89ec735929c3..5ae6c207d3ac 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -293,7 +293,7 @@  static int fcoe_interface_setup(struct fcoe_interface *fcoe,
 	struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
 	struct netdev_hw_addr *ha;
 	struct net_device *real_dev;
-	u8 flogi_maddr[ETH_ALEN];
+	static const u8 flogi_maddr[ETH_ALEN] = FC_FCOE_FLOGI_MAC;
 	const struct net_device_ops *ops;
 
 	fcoe->netdev = netdev;
@@ -336,7 +336,6 @@  static int fcoe_interface_setup(struct fcoe_interface *fcoe,
 	 * or enter promiscuous mode if not capable of listening
 	 * for multiple unicast MACs.
 	 */
-	memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
 	dev_uc_add(netdev, flogi_maddr);
 	if (fip->spma)
 		dev_uc_add(netdev, fip->ctl_src_addr);
@@ -442,7 +441,7 @@  static void fcoe_interface_remove(struct fcoe_interface *fcoe)
 {
 	struct net_device *netdev = fcoe->netdev;
 	struct fcoe_ctlr *fip = fcoe_to_ctlr(fcoe);
-	u8 flogi_maddr[ETH_ALEN];
+	static const u8 flogi_maddr[ETH_ALEN] = FC_FCOE_FLOGI_MAC;
 	const struct net_device_ops *ops;
 
 	/*
@@ -458,7 +457,6 @@  static void fcoe_interface_remove(struct fcoe_interface *fcoe)
 	synchronize_net();
 
 	/* Delete secondary MAC addresses */
-	memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
 	dev_uc_del(netdev, flogi_maddr);
 	if (fip->spma)
 		dev_uc_del(netdev, fip->ctl_src_addr);