linux/drivers/nvme/target
Arnd Bergmann 6038aa532a nvme: target: fix buffer overflow
nvmet_execute_get_disc_log_page() passes a fixed-length string into
nvmet_format_discovery_entry(), which then does a longer memcpy() on
it, as pointed out by gcc-8:

In function 'nvmet_format_discovery_entry',
    inlined from 'nvmet_execute_get_disc_log_page' at drivers/nvme/target/discovery.c:126:4:
drivers/nvme/target/discovery.c:62:2: error: 'memcpy' forming offset [38, 223] is out of the bounds [0, 37] [-Werror=array-bounds]
  memcpy(e->subnqn, subsys_nqn, NVMF_NQN_SIZE);

Using strncpy() will make this well-defined, filling the rest of the
buffer with zeroes, under the assumption that the input is either
a NUL-terminated string, or a byte sequence containing no zeroes.
If the input is a string that is longer than NVMF_NQN_SIZE, we
continue to have no NUL-termination in the output.

Fixes: a07b4970f4 ("nvmet: add a generic NVMe target")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-04-12 09:58:27 -06:00
..
admin-cmd.c nvmet: remove redundant local variable 2017-11-10 19:53:25 -07:00
configfs.c nvmet: refactor configfs transport type handling 2018-03-26 08:53:43 -06:00
core.c nvmet: constify struct nvmet_fabrics_ops 2018-03-26 08:53:43 -06:00
discovery.c nvme: target: fix buffer overflow 2018-04-12 09:58:27 -06:00
fabrics-cmd.c nvmet: lower log level for each queue creation 2018-01-08 11:01:52 +01:00
fc.c nvmet: constify struct nvmet_fabrics_ops 2018-03-26 08:53:43 -06:00
fcloop.c Merge branch 'for-4.16/block' of git://git.kernel.dk/linux-block 2018-01-29 11:51:49 -08:00
io-cmd.c nvmet: Change return code of discard command if not supported 2018-02-14 15:38:59 +02:00
Kconfig nvmet/rdma: Use sgl_alloc() and sgl_free() 2018-01-06 09:18:00 -07:00
loop.c nvme-loop: fix kernel oops in case of unhandled command 2018-04-12 09:58:27 -06:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
nvmet.h nvmet: constify struct nvmet_fabrics_ops 2018-03-26 08:53:43 -06:00
rdma.c nvmet: constify struct nvmet_fabrics_ops 2018-03-26 08:53:43 -06:00