Commit Graph

774 Commits

Author SHA1 Message Date
yinshengkai c158ed2c32 mm/heap: memory alignment before executing kasan_register
The unaligned address is used in kasan_register, but the aligned address is used in kasan_unregister.
The mismatch between the addr value and mm_heapstart will result in a crash due to the inability to unregister correctly.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-10 23:11:37 +08:00
wangmingrong1 5c3025e2fb mm/mempool: Merge two memory requests
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-09 18:15:13 +08:00
wangmingrong1 dd57400e7b mm/mempool: Fix mempool tag kasan error
The address needs to be reset only when comparing addition, subtraction, multiplication and division addresses. Otherwise, the original address is always returned or saved.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-09 18:15:13 +08:00
ligd 183ff9b6cc mm/mempool: fix mempool crash when use KASAN SW_TAG
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-09 18:15:13 +08:00
ligd 5258e48be6 mm/heap: fix heap crash when use KASAN SW_TAG
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-09 18:15:13 +08:00
Xiang Xiao b068e2357a circbuf: Move from mm/circbuf to libs/libc/misc
so that it can be used by userspace program.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-09 08:41:49 +08:00
buxiasen 8def44b65a mm/dump: pretty the log and thin dump call
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-08 23:55:59 +08:00
buxiasen 9f2b08a91a memdump: add dump for the orphan nodes(neighbor of free node)
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-08 23:55:59 +08:00
buxiasen fd9a9f67cc memdump: add biggest allocated node dump
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-08 23:55:59 +08:00
buxiasen fd6634ecb5 mm/dump: make macro more common, fix help prompt
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-08 23:55:59 +08:00
wangmingrong1 55c9697efe mm/kconfig: The default alignment of global variable out-of-bounds detection is 1
It is recommended to use 1 on qemu and 16 or even 32 on the device.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-08 19:53:38 +08:00
xuxingliang 18d5ae20f5 drivers/segger: add heap data plot
Add heap current used to note.
Plot it in segger sysview data plot.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
xuxingliang eac6a8597f sched/note: add note when mm add new region
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
xuxingliang 0663ac1483 sched/note: specify note event for heap instrumentation
1. Add NOTE_HEAP_ prefix for heap note event.
2. Use note type as heap instrumentation parameter.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
yinshengkai 8fecd0385b mm: fix memory statistics error
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
yinshengkai 79eab8783f note: add memory tracing event support
Record all memory allocation and release, save to ram, used to analyze memory allocation rate and memory usage
Its absolute value is not trustworthy because the memory will be allocated in thread A and released in thread B

 netinit-5   [0]   0.105984392: tracing_mark_write: C|5|Heap Usage|96|free: heap: 0x606000000020 size:24, address: 0x603000000370
 netinit-5   [0]   0.105996874: tracing_mark_write: C|5|Heap Usage|24|free: heap: 0x606000000020 size:72, address: 0x6070000008e0
nsh_main-4   [0]   3.825169408: tracing_mark_write: C|4|Heap Usage|2177665|free: heap: 0x606000000020 size:424, address: 0x614000000840
nsh_main-4   [0]   3.825228525: tracing_mark_write: C|4|Heap Usage|14977|free: heap: 0x606000000020 size:2162688, address: 0x7f80a639f800
nsh_main-4   [0]   3.825298789: tracing_mark_write: C|4|Heap Usage|15189|malloc: heap: 0x606000000020 size:20, address: 0x6030000003a0

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
Xiang Xiao 6e5c81e061 mm/heap: hold heap lock before access mm_nregions
to remove the race condition and rename IDX to idx

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 04:19:27 +08:00
wangmingrong1 469418f3c9 mm/kasan: Kasan global support setting alignment length
1. Similar to asan, supports single byte out of bounds detection
2. Fix the script to address the issue of not supporting the big end

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 21:47:23 +08:00
wangmingrong1 071af0c993 mm/kasan: Tag kasan and generic kasan use the same instrumentation options
1. Tested on QEMU, the two sockets were basically the same, and their performance was not affected. The size of the generated bin file was also the same
2. Extract global detection as a separate file, both types of Kasan support global variable out of bounds detection simultaneously

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 21:47:23 +08:00
wangmingrong1 5c511443fe mm/kasan: Using arrays instead of linked lists
1. Modify the Kasan global variable script to support array storage of region addresses
2. Due to the lack of formatting in the previous attempt, a formatting script was created

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 21:47:23 +08:00
wangmingrong1 7796161ee2 mm/kasan:Remove compiler restrictions
The latest version of clang also supports kasan

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 21:47:23 +08:00
wangmingrong1 23981cdf3d mm/kasan: Add branch prediction and constant prediction
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 63a371b261 mm/kasan: Change the init flag
predict_false(g_region_init == KASAN_INIT_VALUE))
   c:	e3003000 	movw	r3, #0
  10:	e3403000 	movt	r3, #0
  if (predict_false(size == 0) ||
  14:	e5932000 	ldr	r2, [r3]
  18:	e30e3adf 	movw	r3, #60127	; 0xeadf
if KASAN_INIT_VALUE is 0xdeadcafe, run function movw will again and load twice

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 b49eef7f4e mm/kasan: The complete implementation of inline instrumentation functions
1. Use always_inline_function instead of inline, inline does not take effect
2. Activate Kasan acceleration by 1/7

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 27f8f87331 mm/kasan: Fix the issue where Kasan Global cannot be used
1. The shadow area of global variables is different from heap
2. This modification has little impact on performance under O3 optimization

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 4473f2f847 mm/kasan: Increase size alignment
The following situations cannot be detected by Kasan:
On a 32-bit machine, only 12 bytes were poisoned, but 13 bytes were accessed. Due to the lack of upward alignment, only 3 bits were detected

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 430820e7ec mm/sw_tags: Add API for register
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 1da8cf8104 kasan: No citation removed
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai 87dc91b588 mm/kasan: add kasan watch point implementation
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai e154c6d071 mm/kasan: add null pointer access configuration
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
xuxingliang 38010adc02 nuttx/mm: fix cmake kasan flags
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai 496e44db7f mm: kasan supports checking 0 address access
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai ae7a3d7071 mm: move kasna_start/stop to hook.c
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao 2d8b582ce6 kasan:add kasan_start/stop api to control kasan check
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai be86b03794 mm/kasan: support Disable Kasan read Panic
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai d365be9f2f kasan: remove kasan report recursive check
PANIC never returns and abort is called to exit the process after calling assert
When BOARD_RESET_ON_ASSERT < 2, the second kasan_report will not be executed.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai 5ee7c563a5 mm: add kasan_unregister implementaion
In mm_uninitialize should unregister kasan

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai 1771d233c9 mm/kasan: fix kasan_is_poisoned check error
When size is less than or equal to KASAN_SHADOW_SCALE, no check will be performed
We need to check whether the memory is accessible based on bit

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
ligd 13a0682340 kasan: disable the built-in 'memset' function
In function kasan_set_poison:
{
  ...

  while (size--)
    {
      p[size] = value;
    }
}
This will optimize to 'memset' function when compile option > O2.

But the memset must be instrument by kasan, so there is recursive

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-19 03:15:29 +08:00
ligd 8a272511d5 kasan: remove unused statement
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai e0c8189818 mm/kasan: fix kasan false positives
When using memset via __asan_storeN check, not checking if all memory is accessible

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong ae3facda53 kasan: Implementation of Kasan based on software tags.
Currently, only aarch64 is supported

Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2024-09-19 03:15:29 +08:00
Xiang Xiao 9c6bed4b00 mm: Move kasan.h from mm/kasan to include/nuttx/mm
so other parts of the system can use it.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-09-19 03:15:29 +08:00
Xiang Xiao 47ffb9019f mm: Support the different kasan implementation
Split kasan.c to incorporate label based kasan:
hook.c: Implement compiler instrumentation function
generic.c: Implementation software kasan algorithm

Signed-off-by: wangmingrong <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao 70b9f63985 kasan:fix arch_xxx size is 0,kasan report
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao e26e1ab2ab kasan:fix bug if kasan_mem_to_shadow mod size is 0 just return
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao 745611f800 kasan:fix bug for kasan_mem_to_shadow
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao 780abec239 kasan:support kasan_mem_to_shadow can check any size
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
zhangshoukui 8e4e09be2d shm: The limits have been made in Make.defs and remove useless macro in code
ifeq ($(CONFIG_MM_SHM),y)
CSRCS += shmat.c shmctl.c shmdt.c shmget.c

DEPPATH += --dep-path shm
VPATH += :shm
endif

Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-09-18 13:42:11 +08:00
Masayuki Ishikawa df298c186f Revert "build depend:Revert Make.dep intermediate ddc file"
This reverts commit ddc3119c4e.
2024-09-15 19:29:47 +08:00