Skip to content

Commit

Permalink
nvmet: fixup buffer overrun in nvmet_subsys_attr_serial()
Browse files Browse the repository at this point in the history
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 <hare@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Hannes Reinecke authored and Christoph Hellwig committed Sep 6, 2021
1 parent ab7a273 commit f040648
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/nvme/target/configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f040648

Please sign in to comment.