Skip to content

Commit

Permalink
swiotlb: fix use after free on error handling path
Browse files Browse the repository at this point in the history
Don't dereference "mem" after it has been freed.  Flip the
two kfree()s around to address this bug.

Fixes: 26ffb91fa5e0 ("swiotlb: split up the global swiotlb lock")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Dan Carpenter authored and Christoph Hellwig committed Jul 18, 2022
1 parent 20347fc commit 4a97739
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/dma/swiotlb.c
Original file line number Diff line number Diff line change
@@ -979,8 +979,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
mem->areas = kcalloc(nareas, sizeof(*mem->areas),
GFP_KERNEL);
if (!mem->areas) {
kfree(mem);
kfree(mem->slots);
kfree(mem);
return -ENOMEM;
}

0 comments on commit 4a97739

Please sign in to comment.