Re: [PATCH v2 1/4] misc: fastrpc: Add NULL check to fastrpc_buf_free to prevent crash
From: Jianping
Date: Mon Feb 02 2026 - 01:34:36 EST
On 1/16/2026 4:43 AM, Dmitry Baryshkov wrote:
On Thu, Jan 15, 2026 at 04:28:48PM +0800, Jianping Li wrote:Thanks, Dmitry.
From: Ekansh Gupta <ekansh.gupta@xxxxxxxxxxxxxxxx>
The fastrpc_buf_free function currently does not handle the case where
the input buffer pointer (buf) is NULL. This can lead to a null pointer
dereference, causing a crash or undefined behavior when the function
attempts to access members of the buf structure. Add a NULL check to
ensure safe handling of NULL pointers and prevent potential crashes.
When does it happen? Do you have a backtrace or is it a safety coding?
Do you pass NULL buffer pointers to the function?
Yes, this change is mainly for safety‑coding purposes.
This is reachable on during remove/deinit sequences when a buffer was never allocated or allocation failed part‑way and cleanup proceeds.
It's a saftety coding: to eliminate NULL checks on the caller side, as we do in a lot of other kernel API.
At the same time, there is a possibility that this buffer passes NULL, and during verification, this can cause the kernel to crash.
The patch makes fastrpc_buf_free() NULL‑tolerant and simplifies callers by removing duplicated if (ptr) checks, reducing the chance of future omissions.
Fixes: c68cfb718c8f9 ("misc: fastrpc: Add support for context Invoke method")
Cc: stable@xxxxxxxxxx
Co-developed-by: Ekansh Gupta <ekansh.gupta@xxxxxxxxxxxxxxxx>
Signed-off-by: Ekansh Gupta <ekansh.gupta@xxxxxxxxxxxxxxxx>
Signed-off-by: Jianping Li <jianping.li@xxxxxxxxxxxxxxxx>
---
drivers/misc/fastrpc.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)