nvmet-tcp: fix potential race of tcp socket closing accept_work
authorSagi Grimberg <sagi@grimberg.me>
Fri, 5 Feb 2021 19:47:25 +0000 (11:47 -0800)
committerChristoph Hellwig <hch@lst.de>
Wed, 10 Feb 2021 15:38:03 +0000 (16:38 +0100)
commit0fbcfb089a3f2f2a731d01f0aec8f7697a849c28
tree907f42b38ac3f6a7c029568841ec56fa5cd1002a
parentfda871c0ba5d2eed2cd1c881573168129da70058
nvmet-tcp: fix potential race of tcp socket closing accept_work

When we accept a TCP connection and allocate an nvmet-tcp queue we should
make sure not to fully establish it or reference it as the connection may
be already closing, which triggers queue release work, which does not
fence against queue establishment.

In order to address such a race, we make sure to check the sk_state and
contain the queue reference to be done underneath the sk_callback_lock
such that the queue release work correctly fences against it.

Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
Reported-by: Elad Grupi <elad.grupi@dell.com>
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/tcp.c