CTSRD-CHERI/cheribsd

vm_do_cheri_revoke inline ASM missing early-clobber

Closed this issue · 1 comments

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__ (

This is also true of ok for riscv.