Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm_do_cheri_revoke inline ASM missing early-clobber #2227

Open
RoundofThree opened this issue Oct 8, 2024 · 1 comment
Open

vm_do_cheri_revoke inline ASM missing early-clobber #2227

RoundofThree opened this issue Oct 8, 2024 · 1 comment

Comments

@RoundofThree
Copy link
Member

It seems to me that stxr_status has to be marked as early-clobbered (=&r instead of =r). I am running GENERIC-MORELLO-PURECAP with KASAN and I found out that, due to ASAN instrumentation, the compiler will try to assign the same register to cutp and stxr_status, therefore causing a fault when loading from cutp. This doesn’t happen when compiling without KASAN, probably because the compiler didn’t have to make this register allocation optimisation.

This is the relevant inline asm:

		__asm__ __volatile__ (
		        "mov %w[stxr_status], #1\n\t"
#ifndef __CHERI_PURE_CAPABILITY__
			"bx #4\n\t"
			".arch_extension c64\n\t"
#endif
			"0: ldxr %[cscratch], [%[cutp]]\n\t"
			"cmp %[cscratch], %[cut]\n\t"
			"bne 1f\n\t"
			"stxr %w[stxr_status], %[cutr], [%[cutp]]\n\t"
			"cbnz %w[stxr_status], 0b\n\t"
			"1:\n\t"
#ifndef __CHERI_PURE_CAPABILITY__
			"bx #4\n\t"
			".arch_extension noc64\n\t"
			".arch_extension a64c\n\t"
#endif
		  : [stxr_status] "=r" (stxr_status),
		    [cscratch] "=&C" (cscratch), [cutr] "+C" (cutr)
		  : [cut] "C" (cut), [cutp] "C" (cutp)
		  : "memory");

__asm__ __volatile__ (

@jrtc27
Copy link
Member

jrtc27 commented Oct 8, 2024

This is also true of ok for riscv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants