Page MenuHomeFreeBSD

kern linker: Mark link_elf_ireloc as no-KASAN
AcceptedPublic

Authored by andrew on Tue, Feb 3, 11:19 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Feb 3, 7:04 PM
Unknown Object (File)
Tue, Feb 3, 6:39 PM
Unknown Object (File)
Tue, Feb 3, 6:28 PM
Subscribers

Details

Summary

When moving the kernel mem* functions to be an ifunc we need to ensure
they are not called before the relocations are processed. When
link_elf_ireloc is built with KASAN we may call into memset via the
KASAN runtime code.

Fix this by marking the function as no-KASAN so this isn't possible.

Sponsored by: Arm Ltd

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 70368
Build 67251: arc lint + arc unit

Event Timeline

Do you mean that the low-level startup, e.g. hammertime() for amd64, and initarm() for arm64, must be tagged with __nosanitizeaddress as well? (And recursively every function that is called from them, at least up to the point where ifuncs are resolved).

This revision is now accepted and ready to land.Tue, Feb 3, 11:43 AM

This is the only early function I found that calls into a sanitizer runtime. I booted KASAN, KMSAN, and KCSAN with a slightly modified D55051 (disable mops_supported in the ifunc resolvers) & exited initarm in all cases.

In this case it looks like the compiler is adding checks for eff.

Isn't this the problem that memset_early() etc. are supposed to solve? Where exactly is the memset() call happening?

The memset call is in __asan_set_shadow_f8, so is only indirectly called.

The memset call is in __asan_set_shadow_f8, so is only indirectly called.

So this is the __builtin_memset() call from kasan_shadow_Nbyte_fill(). Probably that code should be trying to use memset_early() instead, say, if kasan_init() hasn't already been called?

I'm not sure if it's worth complicating the KASAN runtime for just one function.

I'm not sure if it's worth complicating the KASAN runtime for just one function.

For this bug fix to be complete, you have to patch all callees of link_elf_ireloc(), not just link_elf_ireloc().

Does D55079 fix the problem for you?

I've asked @sarah.walker2_arm.com to test. I have confirmed that eff is the issue. If I move it off the stack I can boot without needing either this patch or changing the sanitizer runtimes.

Does D55079 fix the problem for you?

I've asked @sarah.walker2_arm.com to test. I have confirmed that eff is the issue. If I move it off the stack I can boot without needing either this patch or changing the sanitizer runtimes.

Ok. I'd still prefer to fix this in the sanitizer runtime, otherwise we'll probably see this problem again in the future.