From: Taehee Yoo <ap420073@gmail.com>
To: linux-nvme@lists.infradead.org, kbusch@kernel.org, axboe@fb.com,
hch@lst.de, sagi@grimberg.me, kch@nvidia.com
Cc: james.p.freyensee@intel.com, ming.l@ssi.samsung.com,
larrystevenwise@gmail.com, anthony.j.knapp@intel.com,
pizhenwei@bytedance.com, ap420073@gmail.com
Subject: [PATCH 4/4] nvmet-tcp: fix memory leak in nvmet_tcp_free_cmd_data_in_buffers()
Date: Tue, 3 Jan 2023 10:03:57 +0000 [thread overview]
Message-ID: <20230103100357.875854-5-ap420073@gmail.com> (raw)
In-Reply-To: <20230103100357.875854-1-ap420073@gmail.com>
While tcp socket is being released, nvmet_tcp_release_queue_work() is
called.
It calls nvmet_tcp_free_cmd_data_in_buffers() to free CMD resources.
But it may skip freeing resources due to unnecessary condition checks.
So, the memory leak will occur.
In order to fix this problem, it removes unnecessary condition checks
in nvmet_tcp_free_cmd_data_in_buffers().
This memory leak issue will occur in the target machine when a host
sends reset command to a target.
Reproducer:
while :
do
echo 1 > /sys/class/nvme/nvme<NS>/reset_controller
done
unreferenced object 0xffff88814a5c6da0 (size 32):
comm "kworker/2:1H", pid 176, jiffies 4305953739 (age 72707.743s)
hex dump (first 32 bytes):
82 84 c8 04 00 ea ff ff 00 00 00 00 00 04 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<ffffffffaa795cf7>] __kmalloc+0x47/0xc0
[<ffffffffab030a72>] sgl_alloc_order+0x82/0x3a0
[<ffffffffc086593c>] nvmet_tcp_map_data+0x1bc/0x570 [nvmet_tcp]
[<ffffffffc086a7d4>] nvmet_tcp_try_recv_pdu+0x7f4/0x1e20 [nvmet_tcp]
[<ffffffffc086c5a0>] nvmet_tcp_io_work+0x120/0x3272 [nvmet_tcp]
[<ffffffffaa1b059d>] process_one_work+0x81d/0x1450
[<ffffffffaa1b177c>] worker_thread+0x5ac/0xed0
[<ffffffffaa1c8ccf>] kthread+0x29f/0x340
[<ffffffffaa0034cf>] ret_from_fork+0x1f/0x30
unreferenced object 0xffff888153f3e1c0 (size 16):
comm "kworker/2:1H", pid 176, jiffies 4305953739 (age 72707.743s)
hex dump (first 16 bytes):
80 84 c8 04 00 ea ff ff 00 04 00 00 00 00 00 00 ................
backtrace:
[<ffffffffaa795cf7>] __kmalloc+0x47/0xc0
[<ffffffffc0865a80>] nvmet_tcp_map_data+0x300/0x570 [nvmet_tcp]
[<ffffffffc086a7d4>] nvmet_tcp_try_recv_pdu+0x7f4/0x1e20 [nvmet_tcp]
[<ffffffffc086c5a0>] nvmet_tcp_io_work+0x120/0x3272 [nvmet_tcp]
[<ffffffffaa1b059d>] process_one_work+0x81d/0x1450
[<ffffffffaa1b177c>] worker_thread+0x5ac/0xed0
[<ffffffffaa1c8ccf>] kthread+0x29f/0x340
[<ffffffffaa0034cf>] ret_from_fork+0x1f/0x30
Fixes: db94f240280c ("nvmet-tcp: fix NULL pointer dereference during release")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
drivers/nvme/target/tcp.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index cc05c094de22..dac08603fec9 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -1427,13 +1427,10 @@ static void nvmet_tcp_free_cmd_data_in_buffers(struct nvmet_tcp_queue *queue)
struct nvmet_tcp_cmd *cmd = queue->cmds;
int i;
- for (i = 0; i < queue->nr_cmds; i++, cmd++) {
- if (nvmet_tcp_need_data_in(cmd))
- nvmet_tcp_free_cmd_buffers(cmd);
- }
+ for (i = 0; i < queue->nr_cmds; i++, cmd++)
+ nvmet_tcp_free_cmd_buffers(cmd);
- if (!queue->nr_cmds && nvmet_tcp_need_data_in(&queue->connect))
- nvmet_tcp_free_cmd_buffers(&queue->connect);
+ nvmet_tcp_free_cmd_buffers(&queue->connect);
}
static void nvmet_tcp_release_queue_work(struct work_struct *w)
--
2.34.1
next prev parent reply other threads:[~2023-01-03 10:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-03 10:03 [PATCH 0/4] nvme: fix several bugs in nvme-fabric Taehee Yoo
2023-01-03 10:03 ` [PATCH 1/4] nvme: fix delete uninitialized controller Taehee Yoo
2023-01-03 10:30 ` Sagi Grimberg
2023-01-04 0:24 ` Chaitanya Kulkarni
2023-01-04 2:42 ` Taehee Yoo
2023-01-03 10:03 ` [PATCH 2/4] nvme: fix reset " Taehee Yoo
2023-01-03 10:32 ` Sagi Grimberg
2023-01-03 10:03 ` [PATCH 3/4] nvmet: fix hang in nvmet_ns_disable() Taehee Yoo
2023-01-03 10:58 ` Sagi Grimberg
2023-01-04 0:32 ` Chaitanya Kulkarni
2023-01-04 8:56 ` Taehee Yoo
2023-01-03 10:03 ` Taehee Yoo [this message]
2023-01-03 10:54 ` [PATCH 4/4] nvmet-tcp: fix memory leak in nvmet_tcp_free_cmd_data_in_buffers() Sagi Grimberg
2023-01-04 8:44 ` Taehee Yoo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230103100357.875854-5-ap420073@gmail.com \
--to=ap420073@gmail.com \
--cc=anthony.j.knapp@intel.com \
--cc=axboe@fb.com \
--cc=hch@lst.de \
--cc=james.p.freyensee@intel.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=larrystevenwise@gmail.com \
--cc=linux-nvme@lists.infradead.org \
--cc=ming.l@ssi.samsung.com \
--cc=pizhenwei@bytedance.com \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox