You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function rt_smem_setname in mem.c should successfully copy the thread name into the memory structure without errors. It should iterate through the name string and properly terminate the loop when encountering a null character ('\0'), ensuring no out-of-bound access or unexpected behavior.
Actual Behavior:
The function rt_smem_setname in mem.c at line 108 encounters an issue where it fails to handle the input string name properly. Specifically, the condition if (name[index] == '\0') break; does not safeguard against cases where name is NULL. This leads to a potential dereference of a null pointer, causing a system crash and halting execution. Additionally, the log indicates a mismatch in returned syscall calls (info.Calls : 22 != ncalls : 30), further suggesting undefined behavior in memory handling.
Description:
During the execution of syz_recvfrom, the system encounters a critical failure leading to a timeout.The issue originates in the rt_smem_setname function at line 108 of mem.c, which lacks a check to ensure the name pointer is non-NULL before dereferencing it. If name is NULL, the condition if (name[index] == '\0') results in undefined behavior, causing the system to crash. This problem is exacerbated by the fact that rt_smem_setname is invoked without sufficient validation of the input arguments, leading to unpredictable behavior during runtime.
The error log highlights a stack trace showing the crash in mem.c at line 108. It further indicates the crash occurred during the execution of a syscall (syz_recvfrom) and subsequent memory operations (rt_smem_free, rt_free), pointing to improper memory handling as the root cause.
Observe the behavior; if the bug persists, you should see similar logs indicating a timeout and register access failure.
Suggested Fix
To resolve this issue, modify the rt_smem_setname function to include a null pointer check for the name parameter before accessing it. This ensures the function does not dereference a null pointer, preventing crashes and undefined behavior.
Here is the updated code for rt_smem_setname:
rt_inlinevoidrt_smem_setname(structrt_small_mem_item*mem, constchar*name)
{
intindex;
// Check if the name pointer is NULLif (name==NULL)
{
// If NULL, fill the thread name with spaces and returnfor (index=0; index<sizeof(mem->thread); index++)
{
mem->thread[index] =' ';
}
return;
}
// Copy the name string into the thread fieldfor (index=0; index<sizeof(mem->thread); index++)
{
if (name[index] =='\0') break;
mem->thread[index] =name[index];
}
// Fill remaining space with spacesfor (; index<sizeof(mem->thread); index++)
{
mem->thread[index] =' ';
}
}
Additionally, review all calls to rt_smem_setname to ensure that valid pointers are passed wherever possible. This defensive programming practice will reduce the likelihood of similar issues in the future.
Other additional context
No response
The text was updated successfully, but these errors were encountered:
RT-Thread Version
2f55990
Hardware Type/Architectures
arm32
Develop Toolchain
GCC
Describe the bug
Expected Behavior:
The function
rt_smem_setname
inmem.c
should successfully copy the thread name into the memory structure without errors. It should iterate through thename
string and properly terminate the loop when encountering a null character ('\0'
), ensuring no out-of-bound access or unexpected behavior.Actual Behavior:
The function
rt_smem_setname
inmem.c
at line 108 encounters an issue where it fails to handle the input stringname
properly. Specifically, the conditionif (name[index] == '\0') break;
does not safeguard against cases wherename
isNULL
. This leads to a potential dereference of a null pointer, causing a system crash and halting execution. Additionally, the log indicates a mismatch in returned syscall calls (info.Calls : 22 != ncalls : 30
), further suggesting undefined behavior in memory handling.Description:
During the execution of
syz_recvfrom
, the system encounters a critical failure leading to a timeout.The issue originates in thert_smem_setname
function at line 108 ofmem.c
, which lacks a check to ensure thename
pointer is non-NULL before dereferencing it. Ifname
isNULL
, the conditionif (name[index] == '\0')
results in undefined behavior, causing the system to crash. This problem is exacerbated by the fact thatrt_smem_setname
is invoked without sufficient validation of the input arguments, leading to unpredictable behavior during runtime.The error log highlights a stack trace showing the crash in
mem.c
at line 108. It further indicates the crash occurred during the execution of a syscall (syz_recvfrom
) and subsequent memory operations (rt_smem_free
,rt_free
), pointing to improper memory handling as the root cause.Debug Logs:
__Note:
kcov.c main.c common_freertos.h executor.h
is a file we wrote ourselves.Steps to Reproduce:
syz_recvfrom
function with ((0x2, 0x0, 0xffffffffffffffff, 0x0, 0xfffffffffffffffc, 0x0)
).Suggested Fix
To resolve this issue, modify the
rt_smem_setname
function to include a null pointer check for thename
parameter before accessing it. This ensures the function does not dereference a null pointer, preventing crashes and undefined behavior.Here is the updated code for
rt_smem_setname
:Additionally, review all calls to
rt_smem_setname
to ensure that valid pointers are passed wherever possible. This defensive programming practice will reduce the likelihood of similar issues in the future.Other additional context
No response
The text was updated successfully, but these errors were encountered: