nvmet-tcp: Fix NULL dereference when a connect data comes in h2cdata pdu
authorZiye Yang <ziye.yang@intel.com>
Fri, 21 Aug 2020 16:48:10 +0000 (00:48 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Sep 2020 11:55:34 +0000 (13:55 +0200)
commit0a12c794513ccb18d2d2e1b5ef73d0536a403d25
treed7f7b7e52106f2afbef6fe627b3c9d49b0b68bed
parent76101def01209fb491b9e03f73e67c95914e0fef
nvmet-tcp: Fix NULL dereference when a connect data comes in h2cdata pdu

[ Upstream commit a6ce7d7b4adaebc27ee7e78e5ecc378a1cfc221d ]

When handling commands without in-capsule data, we assign the ttag
assuming we already have the queue commands array allocated (based
on the queue size information in the connect data payload). However
if the connect itself did not send the connect data in-capsule we
have yet to allocate the queue commands,and we will assign a bogus
ttag and suffer a NULL dereference when we receive the corresponding
h2cdata pdu.

Fix this by checking if we already allocated commands before
dereferencing it when handling h2cdata, if we didn't, its for sure a
connect and we should use the preallocated connect command.

Signed-off-by: Ziye Yang <ziye.yang@intel.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/target/tcp.c