nvmet: fixup buffer overrun in nvmet_subsys_attr_serial()
Subsystems (2)
PATCH 1/1 nvmet: fixup buffer overrun in nvmet_subsys_attr_serial()
The serial number is copied into the buffer via memcpy_and_pad() with the length NVMET_SN_MAX_SIZE. So when printing out we also need to take just that length as anything beyond that will be uninitialized.
--- drivers/nvme/target/configfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/configfs.c +1 -1
@@ -1113,7 +1113,7 @@ static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item, {struct nvmet_subsys *subsys =to_subsys (item); -return snprintf (page,PAGE_SIZE ,"%s\n" , subsys->serial); +return snprintf (page,NVMET_SN_MAX_SIZE ,"%s\n" , subsys->serial); } static ssize_t
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerQuoted 6 lines · Hannes Reinecke
The serial number is copied into the buffer via
memcpy_and_pad()with the lengthNVMET_SN_MAX_SIZE. So when printing out we also need to take just that length as anything beyond that will be uninitialized.Signed-off-by Hannes Reinecke <[email protected]>
The normal way to print a potentially unterminated fixed length string would be something like:
drivers/nvme/target/configfs.c +2 -1
@@ -1067,7 +1067,8 @@ static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item, {struct nvmet_subsys *subsys =to_subsys (item); -return snprintf (page,PAGE_SIZE ,"%s\n" , subsys->serial); +return snprintf (page,PAGE_SIZE ,"%*s\n" , +NVMET_SN_MAX_SIZE , subsys->serial); } static ssize_t
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 6 lines · Hannes Reinecke
The serial number is copied into the buffer via
memcpy_and_pad()with the lengthNVMET_SN_MAX_SIZE. So when printing out we also need to take just that length as anything beyond that will be uninitialized.Signed-off-by Hannes Reinecke <[email protected]>The normal way to print a potentially unterminated fixed length string would be something like:
Does this version still look ok to you?
Quoted 6 lines
drivers/nvme/target/configfs.c +0
-0
drivers/nvme/target/configfs.c static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item, · line 1074
Quoted 9 lines
drivers/nvme/target/configfs.c +2
-1@@ -1067,7 +1067,8 @@ static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item, {struct nvmet_subsys *subsys =to_subsys (item); -return snprintf (page,PAGE_SIZE ,"%s\n" , subsys->serial); +return snprintf (page,PAGE_SIZE ,"%*s\n" , +NVMET_SN_MAX_SIZE , subsys->serial); } static ssize_t
---end quoted text---
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 23 lines · Christoph Hellwig
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Hannes Reinecke
The serial number is copied into the buffer via
memcpy_and_pad()with the lengthNVMET_SN_MAX_SIZE. So when printing out we also need to take just that length as anything beyond that will be uninitialized.Signed-off-by Hannes Reinecke <[email protected]>The normal way to print a potentially unterminated fixed length string would be something like:
Does this version still look ok to you?
Quoted 9 lines
drivers/nvme/target/configfs.c +0
-0@@ -1067,7 +1067,8 @@ static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item, {struct nvmet_subsys *subsys =to_subsys (item);
Quoted 8 lines
drivers/nvme/target/configfs.c static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item, · line 1074
Quoted 6 lines
drivers/nvme/target/configfs.c +2
-1-return snprintf (page,PAGE_SIZE ,"%s\n" , subsys->serial); +return snprintf (page,PAGE_SIZE ,"%*s\n" , +NVMET_SN_MAX_SIZE , subsys->serial); } static ssize_t---end quoted text---
Yes, it does; will be sending an updated patch.
Cheers,
Hannes
Signature · 9 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme