Skip to contentSkip to conversation

bnx2i: use strlcpy() instead of memcpy() for strings

PATCH Applied Dan Carpenter 5 participants 6 messages Jun 30, 2012 – Jul 9, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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
index 7729a52..b17637a 100644
@@ -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;
#1 lore raw
Quoted 1 line

Subject: [patch] [SCSI] bnx2i: use strlcpy() instead of memcpy() for

strings

Quoted 15 lines

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 +0 -0
index 7729a52..b17637a 100644

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 -0
 	memcpy(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

#2 lore raw
Quoted 20 lines · David Laight
Quoted 1 line

Subject: [patch] [SCSI] bnx2i: use strlcpy() instead of memcpy() for

strings

Quoted 18 lines

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 +0 -0
index 7729a52..b17637a 100644
@@ -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 -0
 	memcpy(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?

I'm pretty sure we set those to zero in bnx2x_handle_drv_info_req().

regards,
dan carpenter

Acked-by
#3 lore raw
Quoted 23 lines · Dan Carpenter
Quoted 22 lines · David Laight
Quoted 1 line

Subject: [patch] [SCSI] bnx2i: use strlcpy() instead of memcpy() for

strings

Quoted 15 lines

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 +0 -0
index 7729a52..b17637a 100644

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));

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 -0
 	memcpy(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?

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.

Acked-by
#4 lore raw
Quoted 34 lines · Michael Chan
Quoted 23 lines · Dan Carpenter
Quoted 22 lines · David Laight
Quoted 1 line

Subject: [patch] [SCSI] bnx2i: use strlcpy() instead of memcpy() for

strings

Quoted 15 lines

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 +0 -0
index 7729a52..b17637a 100644

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));

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 -0
 	memcpy(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?

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.

True. strlcpy() is the correct routine to use (instead of strncpy) as this needs to be NULL terminated. Thanks.