Skip to content

mctp-netlink: Cleanups from a -Db_sanitize=address,undefined build run in a target environment#131

Open
amboar wants to merge 3 commits into
CodeConstruct:mainfrom
amboar:sanitize
Open

mctp-netlink: Cleanups from a -Db_sanitize=address,undefined build run in a target environment#131
amboar wants to merge 3 commits into
CodeConstruct:mainfrom
amboar:sanitize

Conversation

@amboar

@amboar amboar commented Nov 28, 2025

Copy link
Copy Markdown
Contributor

I was doing some testing a while back and found a couple of minor issues. Rediscovered them today.

Mitigate the following ubsan splat:

    Feb 27 09:32:23 test mctpd[1034]: ../git/src/mctp-netlink.c:960:3: runtime error: null pointer passed as argument 1, which is declared to never be null
    Feb 27 09:32:23 test mctpd[1034]:     #0 0x4552c4  (/usr/sbin/mctpd+0x4a2c4) (BuildId: 0a2c71201a0ddde8f9bbe7d2fd65628c4e08f5d8)
    Feb 27 09:32:23 test mctpd[1034]:     CodeConstruct#1 0x42c3b0  (/usr/sbin/mctpd+0x213b0) (BuildId: 0a2c71201a0ddde8f9bbe7d2fd65628c4e08f5d8)
    Feb 27 09:32:23 test mctpd[1034]:     CodeConstruct#2 0xa623b4ac  (/usr/lib/libc.so.6+0x1f4ac) (BuildId: f7dfc12cfaed3ca290b3c7f41ef9145c0de0fe6b)
    Feb 27 09:32:23 test mctpd[1034]:     CodeConstruct#3 0xa623b598 in __libc_start_main (/usr/lib/libc.so.6+0x1f598) (BuildId: f7dfc12cfaed3ca290b3c7f41ef9145c0de0fe6b)

glibc (e.g. 2.41) declares qsort as:

    extern void qsort (void *__base, size_t __nmemb, size_t __size,
    		   __compar_fn_t __compar) __nonnull ((1, 4));

Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
Mitigate the ubsan splat:

    Feb 27 09:30:55 test mctpd[984]: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../../../../../workspace/sources/mctp/src/mctp-netlink.c:1102:2 in
    Feb 27 09:31:00 test mctpd[993]: ../../../../../../workspace/sources/mctp/src/mctp-netlink.c:1102:2: runtime error: null pointer passed as argument 2, which is declared to never be null
    Feb 27 09:31:00 test mctpd[993]:     #0 0x47fcc0  (/usr/sbin/mctpd+0x57cc0) (BuildId: 74658a0b3317f1295bab6bbcd8febf809768bfda)
    Feb 27 09:31:00 test mctpd[993]:     CodeConstruct#1 0x459590  (/usr/sbin/mctpd+0x31590) (BuildId: 74658a0b3317f1295bab6bbcd8febf809768bfda)
    Feb 27 09:31:00 test mctpd[993]:     CodeConstruct#2 0x4498f0  (/usr/sbin/mctpd+0x218f0) (BuildId: 74658a0b3317f1295bab6bbcd8febf809768bfda)
    Feb 27 09:31:00 test mctpd[993]:     CodeConstruct#3 0xa62904ac  (/usr/lib/libc.so.6+0x1f4ac) (BuildId: f7dfc12cfaed3ca290b3c7f41ef9145c0de0fe6b)
    Feb 27 09:31:00 test mctpd[993]:     CodeConstruct#4 0xa6290598 in __libc_start_main (/usr/lib/libc.so.6+0x1f598) (BuildId: f7dfc12cfaed3ca290b3c7f41ef9145c0de0fe6b)

Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
@jk-ozlabs

Copy link
Copy Markdown
Member

Nice. Should we be doing some UBSANning in CI?

@jk-ozlabs

Copy link
Copy Markdown
Member

aww, we can't pass NULL even when we're representing the size as zero?

Given we were already enabling ASAN and there were a couple of UBSAN
bugs, let's enable UBSAN too.

Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants