bnx2i: use strlcpy() instead of memcpy() for strings
PATCH 1/1 bnx2i: use strlcpy() instead of memcpy() for strings
DRV_MODULE_VERSION here is "2.7.2.2" which is only 8 chars but we copy 12 bytes from the stack so it's a small information leak.
---
This was just added to linux-next yesterday, but I'm not sure which tree it came from.
drivers/scsi/bnx2i/bnx2i_init.c +1 -1
@@ -400,7 +400,7 @@ int bnx2i_get_stats(void *handle)if (!stats)return -ENOMEM ; -memcpy (stats->version,DRV_MODULE_VERSION ,sizeof (stats->version)); +strlcpy (stats->version,DRV_MODULE_VERSION ,sizeof (stats->version));memcpy (stats->mac_add1 +2 , hba->cnic->mac_addr,ETH_ALEN ); stats->max_frame_size = hba->netdev->mtu;
Quoted 1 line
Subject: [patch] [SCSI] bnx2i: use
strlcpy()instead ofmemcpy()for
strings
Quoted 15 lines
DRV_MODULE_VERSIONhere is "2.7.2.2" which is only 8 chars but we copy 12 bytes from the stack so it's a small information leak.Signed-off-by Dan Carpenter <[email protected]>---
This was just added to linux-next yesterday, but I'm not sure which tree it came from.drivers/scsi/bnx2i/bnx2i_init.c +0
-0
drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 403
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_init.c +0
-1@@ -400,7 +400,7 @@ int bnx2i_get_stats(void *handle)if (!stats)return -ENOMEM ; - memcpy(stats->version, DRV_MODULE_VERSION,
sizeof(stats->version));
drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 403
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_init.c +1
-0+ strlcpy(stats->version, DRV_MODULE_VERSION,
sizeof(stats->version));
drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 404
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_init.c +0
-0memcpy (stats->mac_add1 +2 , hba->cnic->mac_addr,ETH_ALEN );
Doesn't that leak the original contents of the last bytes of stats->version instead?
David
Quoted 20 lines · David Laight
Quoted 1 line
Subject: [patch] [SCSI] bnx2i: use
strlcpy()instead ofmemcpy()forstrings
Quoted 18 lines
DRV_MODULE_VERSIONhere is "2.7.2.2" which is only 8 chars but we copy 12 bytes from the stack so it's a small information leak.Signed-off-by Dan Carpenter <[email protected]>---
This was just added to linux-next yesterday, but I'm not sure which tree it came from.drivers/scsi/bnx2i/bnx2i_init.c +0
-0@@ -400,7 +400,7 @@ int bnx2i_get_stats(void *handle)if (!stats)return -ENOMEM ;
Quoted 8 lines
drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 403
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_init.c +0
-1- memcpy(stats->version, DRV_MODULE_VERSION,
sizeof(stats->version));drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 403
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_init.c +1
-0+ strlcpy(stats->version, DRV_MODULE_VERSION,
sizeof(stats->version));drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 404
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_init.c +0
-0memcpy (stats->mac_add1 +2 , hba->cnic->mac_addr,ETH_ALEN );Doesn't that leak the original contents of the last bytes of
stats->versioninstead?
I'm pretty sure we set those to zero in bnx2x_handle_drv_info_req().
regards,
dan carpenter
Michael Chan
Acked-byQuoted 23 lines · Dan Carpenter
Quoted 22 lines · David Laight
Quoted 1 line
Subject: [patch] [SCSI] bnx2i: use
strlcpy()instead ofmemcpy()forstrings
Quoted 15 lines
DRV_MODULE_VERSIONhere is "2.7.2.2" which is only 8 chars but we copy 12 bytes from the stack so it's a small information leak.Signed-off-by Dan Carpenter <[email protected]>---
This was just added to linux-next yesterday, but I'm not sure which tree it came from.drivers/scsi/bnx2i/bnx2i_init.c +0
-0drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 403
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_init.c +0
-1@@ -400,7 +400,7 @@ int bnx2i_get_stats(void *handle)if (!stats)return -ENOMEM ; - memcpy(stats->version, DRV_MODULE_VERSION,
sizeof(stats->version));
Quoted 9 lines
Quoted 6 lines
drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 403
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_init.c +1
-0+ strlcpy(stats->version, DRV_MODULE_VERSION,
sizeof(stats->version));drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 404
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_init.c +0
-0memcpy (stats->mac_add1 +2 , hba->cnic->mac_addr,ETH_ALEN );Doesn't that leak the original contents of the last bytes of
stats->versioninstead?I'm pretty sure we set those to zero in
bnx2x_handle_drv_info_req().
Yes, bnx2x zeros the whole stats structure, so strlcpy() is correct.
This came from the net-next tree, so David is the right persion to apply this. Thanks.
Eddie Wai
Acked-byQuoted 34 lines · Michael Chan
Quoted 23 lines · Dan Carpenter
Quoted 22 lines · David Laight
Quoted 1 line
Subject: [patch] [SCSI] bnx2i: use
strlcpy()instead ofmemcpy()forstrings
Quoted 15 lines
DRV_MODULE_VERSIONhere is "2.7.2.2" which is only 8 chars but we copy 12 bytes from the stack so it's a small information leak.Signed-off-by Dan Carpenter <[email protected]>---
This was just added to linux-next yesterday, but I'm not sure which tree it came from.drivers/scsi/bnx2i/bnx2i_init.c +0
-0drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 403
Quoted 4 lines
drivers/scsi/bnx2i/bnx2i_init.c +0
-1@@ -400,7 +400,7 @@ int bnx2i_get_stats(void *handle)if (!stats)return -ENOMEM ; - memcpy(stats->version, DRV_MODULE_VERSION,
sizeof(stats->version));Quoted 9 lines
Quoted 6 lines
drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 403
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_init.c +1
-0+ strlcpy(stats->version, DRV_MODULE_VERSION,
sizeof(stats->version));drivers/scsi/bnx2i/bnx2i_init.c int bnx2i_get_stats(void *handle) · line 404
Quoted 1 line
drivers/scsi/bnx2i/bnx2i_init.c +0
-0memcpy (stats->mac_add1 +2 , hba->cnic->mac_addr,ETH_ALEN );Doesn't that leak the original contents of the last bytes of
stats->versioninstead?I'm pretty sure we set those to zero in
bnx2x_handle_drv_info_req().
Quoted 7 lines
Yes, bnx2x zeros the whole stats structure, so
strlcpy()is correct.This came from the net-next tree, so David is the right persion to apply this. Thanks.
Acked-by Michael Chan <[email protected]>
True. strlcpy() is the correct routine to use (instead of strncpy) as this needs to be NULL terminated. Thanks.
From: "Michael Chan" <[email protected]>
Date: Mon, 2 Jul 2012 08:13:38 -0700
Quoted 4 lines
This came from the net-next tree, so David is the right persion to apply this. Thanks.
Acked-by Michael Chan <[email protected]>
Applied, thanks.