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

misc: fastrpc: Fix double free of 'buf' in error path

smatch warning:
drivers/misc/fastrpc.c:1926 fastrpc_req_mmap() error: double free of 'buf'

In fastrpc_req_mmap() error path, the fastrpc buffer is freed in
fastrpc_req_munmap_impl() if unmap is successful.

But in the end, there is an unconditional call to fastrpc_buf_free().
So the above case triggers the double free of fastrpc buf.

Fixes: 72fa6f7820c4 ("misc: fastrpc: Rework fastrpc_req_munmap")
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Sukrut Bellary <sukrut.bellary@linux.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: stable <stable@kernel.org>
Link: https://lore.kernel.org/r/20240902141409.70371-2-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Sukrut Bellary and committed by
Greg Kroah-Hartman
e8c276d4 4df15365

+2 -3
+2 -3
drivers/misc/fastrpc.c
··· 1910 1910 &args[0]); 1911 1911 if (err) { 1912 1912 dev_err(dev, "mmap error (len 0x%08llx)\n", buf->size); 1913 - goto err_invoke; 1913 + fastrpc_buf_free(buf); 1914 + return err; 1914 1915 } 1915 1916 1916 1917 /* update the buffer to be able to deallocate the memory on the DSP */ ··· 1949 1948 1950 1949 err_assign: 1951 1950 fastrpc_req_munmap_impl(fl, buf); 1952 - err_invoke: 1953 - fastrpc_buf_free(buf); 1954 1951 1955 1952 return err; 1956 1953 }