xen/x86: atomic: Don't allow to write atomically in a pointer to const
authorJulien Grall <jgrall@amazon.com>
Sat, 2 May 2020 14:26:10 +0000 (15:26 +0100)
committerJulien Grall <jgrall@amazon.com>
Mon, 11 May 2020 09:50:17 +0000 (10:50 +0100)
At the moment, write_atomic() will happily write to a pointer to const.
While there are no use in Xen, it would be best to catch them at
compilation time.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/include/asm-x86/atomic.h

index 6b40f9c9f8724b1d2a2171866a6e51276d6af4bb..27aad43aaa8f923b0c239c6887602f3c32a38739 100644 (file)
@@ -63,6 +63,8 @@ void __bad_atomic_size(void);
 
 #define write_atomic(p, x) ({                             \
     typeof(*(p)) __x = (x);                               \
+    /* Check that the pointer is not a const type */      \
+    void *__maybe_unused p_ = &__x;                       \
     unsigned long x_ = (unsigned long)__x;                \
     switch ( sizeof(*(p)) ) {                             \
     case 1: write_u8_atomic((uint8_t *)(p), x_); break;   \