[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3c474453-fc89-42b2-9ddc-fdc3a2893064@arm.com>
Date: Fri, 3 May 2024 13:29:23 +0100
From: Robin Murphy <robin.murphy@....com>
To: Fedor Pchelkin <pchelkin@...ras.ru>,
Xiang Chen <chenxiang66@...ilicon.com>
Cc: Christoph Hellwig <hch@....de>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Barry Song <song.bao.hua@...ilicon.com>, iommu@...ts.linux.dev,
linux-kernel@...r.kernel.org, Alexey Khoroshilov <khoroshilov@...ras.ru>,
lvc-project@...uxtesting.org
Subject: Re: [PATCH 1/2] dma-mapping: benchmark: fix up kthread creation error
handling
On 2024-05-02 5:18 pm, Fedor Pchelkin wrote:
> If a kthread creation fails for some reason then uninitialized members of
> the tasks array will be accessed on the error path since it is allocated
> by kmalloc_array().
>
> Limit the bound in such case.
I don't think this is right... The put_task_struct() calls on the error
path are supposed to balance the get_task_struct() calls which only
happen *after* all the threads are successfully created - see commit
d17405d52bac ("dma-mapping: benchmark: fix kernel crash when
dma_map_single fails") - although I now wonder whether that might have
been better done by replacing kthread_stop() with kthread_stop_put(). It
doesn't look like we've ever actually tried to free any previous threads
from the point of allocation failure.
Thanks,
Robin.
> Found by Linux Verification Center (linuxtesting.org).
>
> Fixes: 65789daa8087 ("dma-mapping: add benchmark support for streaming DMA APIs")
> Signed-off-by: Fedor Pchelkin <pchelkin@...ras.ru>
> ---
> kernel/dma/map_benchmark.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c
> index 02205ab53b7e..ea938bc6c7e3 100644
> --- a/kernel/dma/map_benchmark.c
> +++ b/kernel/dma/map_benchmark.c
> @@ -118,6 +118,7 @@ static int do_map_benchmark(struct map_benchmark_data *map)
> if (IS_ERR(tsk[i])) {
> pr_err("create dma_map thread failed\n");
> ret = PTR_ERR(tsk[i]);
> + threads = i;
> goto out;
> }
>
Powered by blists - more mailing lists