Bug 261454

Summary: Fix a possible Null pointer dereference about svc_xprt_alloc()
Product: Base System Reporter: Zhou Qingyang <zhou1615>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed Not A Bug    
Severity: Affects Many People CC: kib
Priority: ---    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
A simple fix for this bugs none

Description Zhou Qingyang 2022-01-25 04:18:40 UTC
Created attachment 231294 [details]
A simple fix for this bugs

In sys/rpc/svc_vc.c() file, the return value of svc_xprt_alloc() is not checked before the dereference in svc_vc_create_conn() function, svc_vc_create_backchannel() function and svc_vc_create(). svc_xprt_alloc() could return NULL on failure of allocation, which could lead to NULL pointer dereference.

Fix this bugs by adding checks of svc_xprt_alloc() in all three functions.

This bug is found by static analyzer, please advise.
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2022-01-27 02:37:32 UTC
Why the result of svc_xprt_alloc() need to be checked?  How could it return
NULL?  The function uses mem_alloc() for two allocations, and mem_alloc() is
malloc(M_WAITOK) which always succeed.