Skip to content

Commit 84164ac

Browse files
kawasakikeithbusch
authored andcommitted
nvmet: do not copy beyond sybsysnqn string length
Commit edd1720 ("nvmet: remove redundant subsysnqn field from ctrl") replaced ctrl->subsysnqn with ctrl->subsys->subsysnqn. This change works as expected because both point to strings with the same data. However, their memory allocation lengths differ. ctrl->subsysnqn had the fixed size defined as NVMF_NQN_FILED_LEN, while ctrl->subsys->subsysnqn has variable length determined by kstrndup(). Due to this difference, KASAN slab-out-of-bounds occurs at memcpy() in nvmet_passthru_override_id_ctrl() after the commit. The failure can be recreated by running the blktests test case nvme/033. To prevent such failures, replace memcpy() with strscpy(), which copies only the string length and avoids overruns. Fixes: edd1720 ("nvmet: remove redundant subsysnqn field from ctrl") Signed-off-by: Shin'ichiro Kawasaki <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 2fa8961 commit 84164ac

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/nvme/target/passthru.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static u16 nvmet_passthru_override_id_ctrl(struct nvmet_req *req)
150150
* code path with duplicate ctrl subsysnqn. In order to prevent that we
151151
* mask the passthru-ctrl subsysnqn with the target ctrl subsysnqn.
152152
*/
153-
memcpy(id->subnqn, ctrl->subsys->subsysnqn, sizeof(id->subnqn));
153+
strscpy(id->subnqn, ctrl->subsys->subsysnqn, sizeof(id->subnqn));
154154

155155
/* use fabric id-ctrl values */
156156
id->ioccsz = cpu_to_le32((sizeof(struct nvme_command) +

0 commit comments

Comments
 (0)