Skip to content

Commit b49f6d8

Browse files
Thierry Escandegregkh
authored andcommitted
misc: fastrpc: Fix a possible double free
This patch fixes the error exit path of fastrpc_init_create_process(). If the DMA allocation or the DSP invoke fails the fastrpc_map was freed but not removed from the mapping list leading to a double free once the mapping list is emptied in fastrpc_device_release(). [srinivas kandagatla]: Cleaned up error path labels and reset init mem to NULL after free Fixes: d73f71c("misc: fastrpc: Add support for create remote init process") Signed-off-by: Thierry Escande <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8e7389c commit b49f6d8

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

drivers/misc/fastrpc.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,12 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
853853

854854
if (copy_from_user(&init, argp, sizeof(init))) {
855855
err = -EFAULT;
856-
goto bail;
856+
goto err;
857857
}
858858

859859
if (init.filelen > INIT_FILELEN_MAX) {
860860
err = -EINVAL;
861-
goto bail;
861+
goto err;
862862
}
863863

864864
inbuf.pgid = fl->tgid;
@@ -872,17 +872,15 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
872872
if (init.filelen && init.filefd) {
873873
err = fastrpc_map_create(fl, init.filefd, init.filelen, &map);
874874
if (err)
875-
goto bail;
875+
goto err;
876876
}
877877

878878
memlen = ALIGN(max(INIT_FILELEN_MAX, (int)init.filelen * 4),
879879
1024 * 1024);
880880
err = fastrpc_buf_alloc(fl, fl->sctx->dev, memlen,
881881
&imem);
882-
if (err) {
883-
fastrpc_map_put(map);
884-
goto bail;
885-
}
882+
if (err)
883+
goto err_alloc;
886884

887885
fl->init_mem = imem;
888886
args[0].ptr = (u64)(uintptr_t)&inbuf;
@@ -918,13 +916,24 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
918916

919917
err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE,
920918
sc, args);
919+
if (err)
920+
goto err_invoke;
921921

922-
if (err) {
922+
kfree(args);
923+
924+
return 0;
925+
926+
err_invoke:
927+
fl->init_mem = NULL;
928+
fastrpc_buf_free(imem);
929+
err_alloc:
930+
if (map) {
931+
spin_lock(&fl->lock);
932+
list_del(&map->node);
933+
spin_unlock(&fl->lock);
923934
fastrpc_map_put(map);
924-
fastrpc_buf_free(imem);
925935
}
926-
927-
bail:
936+
err:
928937
kfree(args);
929938

930939
return err;

0 commit comments

Comments
 (0)