Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: fastrpc: Fix incorrect DMA mapping unmap request

Scatterlist table is obtained during map create request and the same
table is used for DMA mapping unmap. In case there is any failure
while getting the sg_table, ERR_PTR is returned instead of sg_table.

When the map is getting freed, there is only a non-NULL check of
sg_table which will also be true in case failure was returned instead
of sg_table. This would result in improper unmap request. Add proper
check before setting map table to avoid bad unmap request.

Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context Invoke method")
Cc: stable <stable@kernel.org>
Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230811115643.38578-3-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ekansh Gupta and committed by
Greg Kroah-Hartman
a2cb9cd6 ada6c2d9

+5 -3
+5 -3
drivers/misc/fastrpc.c
··· 757 757 { 758 758 struct fastrpc_session_ctx *sess = fl->sctx; 759 759 struct fastrpc_map *map = NULL; 760 + struct sg_table *table; 760 761 int err = 0; 761 762 762 763 if (!fastrpc_map_lookup(fl, fd, ppmap, true)) ··· 785 784 goto attach_err; 786 785 } 787 786 788 - map->table = dma_buf_map_attachment_unlocked(map->attach, DMA_BIDIRECTIONAL); 789 - if (IS_ERR(map->table)) { 790 - err = PTR_ERR(map->table); 787 + table = dma_buf_map_attachment_unlocked(map->attach, DMA_BIDIRECTIONAL); 788 + if (IS_ERR(table)) { 789 + err = PTR_ERR(table); 791 790 goto map_err; 792 791 } 792 + map->table = table; 793 793 794 794 if (attr & FASTRPC_ATTR_SECUREMAP) { 795 795 map->phys = sg_phys(map->table->sgl);