Skip to content

Commit a2cb9cd

Browse files
Ekansh Guptagregkh
authored andcommitted
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: c68cfb7 ("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>
1 parent ada6c2d commit a2cb9cd

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

drivers/misc/fastrpc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
757757
{
758758
struct fastrpc_session_ctx *sess = fl->sctx;
759759
struct fastrpc_map *map = NULL;
760+
struct sg_table *table;
760761
int err = 0;
761762

762763
if (!fastrpc_map_lookup(fl, fd, ppmap, true))
@@ -784,11 +785,12 @@ static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
784785
goto attach_err;
785786
}
786787

787-
map->table = dma_buf_map_attachment_unlocked(map->attach, DMA_BIDIRECTIONAL);
788-
if (IS_ERR(map->table)) {
789-
err = PTR_ERR(map->table);
788+
table = dma_buf_map_attachment_unlocked(map->attach, DMA_BIDIRECTIONAL);
789+
if (IS_ERR(table)) {
790+
err = PTR_ERR(table);
790791
goto map_err;
791792
}
793+
map->table = table;
792794

793795
if (attr & FASTRPC_ATTR_SECUREMAP) {
794796
map->phys = sg_phys(map->table->sgl);

0 commit comments

Comments
 (0)