Skip to content

Commit f040648

Browse files
hreineckeChristoph Hellwig
authored andcommitted
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. Signed-off-by: Hannes Reinecke <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent ab7a273 commit f040648

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/nvme/target/configfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,8 @@ static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item,
10671067
{
10681068
struct nvmet_subsys *subsys = to_subsys(item);
10691069

1070-
return snprintf(page, PAGE_SIZE, "%s\n", subsys->serial);
1070+
return snprintf(page, PAGE_SIZE, "%*s\n",
1071+
NVMET_SN_MAX_SIZE, subsys->serial);
10711072
}
10721073

10731074
static ssize_t

0 commit comments

Comments
 (0)