Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 1 | From d5aac3401e180f3d4ff3db04ebb4e3165b975987 Mon Sep 17 00:00:00 2001 |
| 2 | From: Ankit Kumar <ankit.kumar@samsung.com> |
| 3 | Date: Tue, 16 Aug 2022 11:08:20 +0530 |
| 4 | Subject: [PATCH] engines/xnvme: fix segfault issue with xnvme ioengine |
| 5 | |
| 6 | fix segfault when xnvme ioengine is called without thread=1. |
| 7 | The segfault happens because td->io_ops_data is accessed at |
| 8 | two locations xnvme_fioe_cleanup and xnvme_fioe_iomem_free, |
| 9 | during the error handling call. |
| 10 | |
| 11 | Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com> |
| 12 | Link: https://lore.kernel.org/r/20220816053821.440-2-ankit.kumar@samsung.com |
| 13 | Signed-off-by: Jens Axboe <axboe@kernel.dk> |
| 14 | --- |
| 15 | engines/xnvme.c | 17 ++++++++++++++--- |
| 16 | 1 file changed, 14 insertions(+), 3 deletions(-) |
| 17 | |
| 18 | diff --git a/engines/xnvme.c b/engines/xnvme.c |
| 19 | index c11b33a8..d8647481 100644 |
| 20 | --- a/engines/xnvme.c |
| 21 | +++ b/engines/xnvme.c |
| 22 | @@ -205,9 +205,14 @@ static void _dev_close(struct thread_data *td, struct xnvme_fioe_fwrap *fwrap) |
| 23 | |
| 24 | static void xnvme_fioe_cleanup(struct thread_data *td) |
| 25 | { |
| 26 | - struct xnvme_fioe_data *xd = td->io_ops_data; |
| 27 | + struct xnvme_fioe_data *xd = NULL; |
| 28 | int err; |
| 29 | |
| 30 | + if (!td->io_ops_data) |
| 31 | + return; |
| 32 | + |
| 33 | + xd = td->io_ops_data; |
| 34 | + |
| 35 | err = pthread_mutex_lock(&g_serialize); |
| 36 | if (err) |
| 37 | log_err("ioeng->cleanup(): pthread_mutex_lock(), err(%d)\n", err); |
| 38 | @@ -367,8 +372,14 @@ static int xnvme_fioe_iomem_alloc(struct thread_data *td, size_t total_mem) |
| 39 | /* NOTE: using the first device for buffer-allocators) */ |
| 40 | static void xnvme_fioe_iomem_free(struct thread_data *td) |
| 41 | { |
| 42 | - struct xnvme_fioe_data *xd = td->io_ops_data; |
| 43 | - struct xnvme_fioe_fwrap *fwrap = &xd->files[0]; |
| 44 | + struct xnvme_fioe_data *xd = NULL; |
| 45 | + struct xnvme_fioe_fwrap *fwrap = NULL; |
| 46 | + |
| 47 | + if (!td->io_ops_data) |
| 48 | + return; |
| 49 | + |
| 50 | + xd = td->io_ops_data; |
| 51 | + fwrap = &xd->files[0]; |
| 52 | |
| 53 | if (!fwrap->dev) { |
| 54 | log_err("ioeng->iomem_free(): failed no dev-handle\n"); |