arch/riscv/include/asm/uaccess.h | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-)
User pointers passed to uaccess routines can be speculatively used
before access_ok() validates them, potentially leaking kernel memory.
Clamp any address >= TASK_SIZE to the guard page at TASK_SIZE-1, which
will always fault. The clamp is branchless to prevent speculative bypass.
Unlike the v1 approach of clearing the sign bit, this works with all
paging modes (Sv39/Sv48/Sv57) and does not interfere with the pointer
masking extension (Smnpm).
Similar to commit 4d8efc2d5ee4 ("arm64: Use pointer masking to limit
uaccess speculation").
Signed-off-by: Lukas Gerlach <lukas.gerlach@cispa.de>
---
arch/riscv/include/asm/uaccess.h | 38 +++++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/arch/riscv/include/asm/uaccess.h b/arch/riscv/include/asm/uaccess.h
index 11c9886c3b70..df31df3bd55c 100644
--- a/arch/riscv/include/asm/uaccess.h
+++ b/arch/riscv/include/asm/uaccess.h
@@ -74,6 +74,20 @@ static inline unsigned long __untagged_addr_remote(struct mm_struct *mm, unsigne
#define __typefits(x, type, not) \
__builtin_choose_expr(sizeof(x) <= sizeof(type), (unsigned type)0, not)
+/*
+ * Sanitize a uaccess pointer such that it cannot reach any kernel address.
+ * Branchlessly clamp any address >= TASK_SIZE to the unmapped guard page
+ * at TASK_SIZE-1, which will always fault on access.
+ */
+#define uaccess_mask_ptr(ptr) ((__typeof__(ptr))__uaccess_mask_ptr(ptr))
+static inline void __user *__uaccess_mask_ptr(const void __user *ptr)
+{
+ unsigned long p = (unsigned long)ptr;
+ unsigned long mask = (unsigned long)((long)(TASK_SIZE - 1 - p) >> 63);
+
+ return (void __user *)((p & ~mask) | ((TASK_SIZE - 1) & mask));
+}
+
/*
* The exception table consists of pairs of addresses: the first is the
* address of an instruction that is allowed to fault, and the second is
@@ -245,7 +259,8 @@ __gu_failed: \
*/
#define __get_user(x, ptr) \
({ \
- const __typeof__(*(ptr)) __user *__gu_ptr = untagged_addr(ptr); \
+ const __typeof__(*(ptr)) __user *__gu_ptr = \
+ uaccess_mask_ptr(untagged_addr(ptr)); \
long __gu_err = 0; \
__typeof__(x) __gu_val; \
\
@@ -376,7 +391,8 @@ err_label: \
*/
#define __put_user(x, ptr) \
({ \
- __typeof__(*(ptr)) __user *__gu_ptr = untagged_addr(ptr); \
+ __typeof__(*(ptr)) __user *__gu_ptr = \
+ uaccess_mask_ptr(untagged_addr(ptr)); \
__typeof__(*__gu_ptr) __val = (x); \
long __pu_err = 0; \
\
@@ -423,13 +439,15 @@ unsigned long __must_check __asm_copy_from_user(void *to,
static inline unsigned long
raw_copy_from_user(void *to, const void __user *from, unsigned long n)
{
- return __asm_copy_from_user(to, untagged_addr(from), n);
+ return __asm_copy_from_user(to,
+ uaccess_mask_ptr(untagged_addr(from)), n);
}
static inline unsigned long
raw_copy_to_user(void __user *to, const void *from, unsigned long n)
{
- return __asm_copy_to_user(untagged_addr(to), from, n);
+ return __asm_copy_to_user(
+ uaccess_mask_ptr(untagged_addr(to)), from, n);
}
extern long strncpy_from_user(char *dest, const char __user *src, long count);
@@ -444,7 +462,7 @@ unsigned long __must_check clear_user(void __user *to, unsigned long n)
{
might_fault();
return access_ok(to, n) ?
- __clear_user(untagged_addr(to), n) : n;
+ __clear_user(uaccess_mask_ptr(untagged_addr(to)), n) : n;
}
#define arch_get_kernel_nofault(dst, src, type, err_label) \
@@ -471,20 +489,22 @@ static inline void user_access_restore(unsigned long enabled) { }
* the error labels - thus the macro games.
*/
#define arch_unsafe_put_user(x, ptr, label) \
- __put_user_nocheck(x, (ptr), label)
+ __put_user_nocheck(x, uaccess_mask_ptr(ptr), label)
#define arch_unsafe_get_user(x, ptr, label) do { \
__inttype(*(ptr)) __gu_val; \
- __get_user_nocheck(__gu_val, (ptr), label); \
+ __get_user_nocheck(__gu_val, uaccess_mask_ptr(ptr), label); \
(x) = (__force __typeof__(*(ptr)))__gu_val; \
} while (0)
#define unsafe_copy_to_user(_dst, _src, _len, label) \
- if (__asm_copy_to_user_sum_enabled(_dst, _src, _len)) \
+ if (__asm_copy_to_user_sum_enabled( \
+ uaccess_mask_ptr(_dst), _src, _len)) \
goto label;
#define unsafe_copy_from_user(_dst, _src, _len, label) \
- if (__asm_copy_from_user_sum_enabled(_dst, _src, _len)) \
+ if (__asm_copy_from_user_sum_enabled( \
+ _dst, uaccess_mask_ptr(_src), _len)) \
goto label;
#else /* CONFIG_MMU */
---
base-commit: f4d0ec0aa20d49f09dc01d82894ce80d72de0560
change-id: 20260226-uaccess-guard-v2-7a3358bee742
Best regards,
--
Lukas Gerlach <lukas.gerlach@cispa.de>
Hi Lukas,
kernel test robot noticed the following build warnings:
[auto build test WARNING on f4d0ec0aa20d49f09dc01d82894ce80d72de0560]
url: https://github.com/intel-lab-lkp/linux/commits/Lukas-Gerlach/riscv-Limit-uaccess-speculation-using-guard-page/20260227-000028
base: f4d0ec0aa20d49f09dc01d82894ce80d72de0560
patch link: https://lore.kernel.org/r/20260226-uaccess-guard-v2-v2-1-765a314839bc%40cispa.de
patch subject: [PATCH v2] riscv: Limit uaccess speculation using guard page
config: riscv-randconfig-001-20260304 (https://download.01.org/0day-ci/archive/20260304/202603042332.krm6lzx8-lkp@intel.com/config)
compiler: riscv32-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260304/202603042332.krm6lzx8-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603042332.krm6lzx8-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from include/linux/uaccess.h:13,
from include/linux/sched/task.h:13,
from include/linux/sched/signal.h:9,
from include/linux/rcuwait.h:6,
from include/linux/mm.h:37,
from arch/riscv/kernel/asm-offsets.c:9:
arch/riscv/include/asm/uaccess.h: In function '__uaccess_mask_ptr':
>> arch/riscv/include/asm/uaccess.h:86:65: warning: right shift count >= width of type [-Wshift-count-overflow]
unsigned long mask = (unsigned long)((long)(TASK_SIZE - 1 - p) >> 63);
^~
--
In file included from include/linux/uaccess.h:13,
from include/linux/sched/task.h:13,
from include/linux/sched/signal.h:9,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs/super_types.h:13,
from include/linux/fs/super.h:5,
from include/linux/fs.h:5,
from include/linux/poll.h:10,
from fs/signalfd.c:22:
arch/riscv/include/asm/uaccess.h: In function '__uaccess_mask_ptr':
>> arch/riscv/include/asm/uaccess.h:86:65: warning: right shift count >= width of type [-Wshift-count-overflow]
unsigned long mask = (unsigned long)((long)(TASK_SIZE - 1 - p) >> 63);
^~
In file included from include/linux/compat.h:34,
from arch/riscv/include/asm/elf.h:12,
from include/linux/elf.h:6,
from include/linux/module.h:20,
from include/linux/device/driver.h:21,
from include/linux/device.h:32,
from include/linux/node.h:18,
from include/linux/cpu.h:17,
from include/linux/static_call.h:135,
from include/linux/tracepoint.h:22,
from include/trace/syscall.h:5,
from include/linux/syscalls.h:95,
from fs/signalfd.c:32:
fs/signalfd.c: At top level:
arch/riscv/include/asm/syscall_wrapper.h:35:14: warning: '__se_sys_signalfd4' alias between functions of incompatible types 'long int(ulong, ulong, ulong, ulong, ulong, ulong, ulong)' {aka 'long int(long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int)'} and 'long int(long int, long int, long int, long int)' [-Wattribute-alias]
static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \
^~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/signalfd.c:299:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:41:14: note: aliased declaration here
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
^~~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/signalfd.c:299:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:35:14: warning: '__se_sys_signalfd' alias between functions of incompatible types 'long int(ulong, ulong, ulong, ulong, ulong, ulong, ulong)' {aka 'long int(long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int)'} and 'long int(long int, long int, long int)' [-Wattribute-alias]
static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \
^~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:227:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE3(name, ...) SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/signalfd.c:311:1: note: in expansion of macro 'SYSCALL_DEFINE3'
SYSCALL_DEFINE3(signalfd, int, ufd, sigset_t __user *, user_mask,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:41:14: note: aliased declaration here
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
^~~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:227:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE3(name, ...) SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/signalfd.c:311:1: note: in expansion of macro 'SYSCALL_DEFINE3'
SYSCALL_DEFINE3(signalfd, int, ufd, sigset_t __user *, user_mask,
^~~~~~~~~~~~~~~
--
In file included from include/linux/uaccess.h:13,
from include/linux/sched/task.h:13,
from include/linux/sched/signal.h:9,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs/super_types.h:13,
from include/linux/fs/super.h:5,
from include/linux/fs.h:5,
from include/linux/highmem.h:5,
from include/linux/bvec.h:10,
from include/linux/blk_types.h:10,
from include/linux/blkdev.h:9,
from fs/sync.c:6:
arch/riscv/include/asm/uaccess.h: In function '__uaccess_mask_ptr':
>> arch/riscv/include/asm/uaccess.h:86:65: warning: right shift count >= width of type [-Wshift-count-overflow]
unsigned long mask = (unsigned long)((long)(TASK_SIZE - 1 - p) >> 63);
^~
In file included from include/linux/compat.h:34,
from arch/riscv/include/asm/elf.h:12,
from include/linux/elf.h:6,
from include/linux/module.h:20,
from include/linux/device/driver.h:21,
from include/linux/device.h:32,
from include/linux/blk_types.h:11,
from include/linux/blkdev.h:9,
from fs/sync.c:6:
fs/sync.c: At top level:
arch/riscv/include/asm/syscall_wrapper.h:35:14: warning: '__se_sys_syncfs' alias between functions of incompatible types 'long int(ulong, ulong, ulong, ulong, ulong, ulong, ulong)' {aka 'long int(long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int)'} and 'long int(long int)' [-Wattribute-alias]
static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \
^~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:225:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/sync.c:148:1: note: in expansion of macro 'SYSCALL_DEFINE1'
SYSCALL_DEFINE1(syncfs, int, fd)
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:41:14: note: aliased declaration here
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
^~~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:225:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/sync.c:148:1: note: in expansion of macro 'SYSCALL_DEFINE1'
SYSCALL_DEFINE1(syncfs, int, fd)
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:35:14: warning: '__se_sys_sync_file_range2' alias between functions of incompatible types 'long int(ulong, ulong, ulong, ulong, ulong, ulong, ulong)' {aka 'long int(long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int)'} and 'long int(long int, long int, long long int, long long int)' [-Wattribute-alias]
static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \
^~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/sync.c:377:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(sync_file_range2, int, fd, unsigned int, flags,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:41:14: note: aliased declaration here
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
^~~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/sync.c:377:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(sync_file_range2, int, fd, unsigned int, flags,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:35:14: warning: '__se_sys_sync_file_range' alias between functions of incompatible types 'long int(ulong, ulong, ulong, ulong, ulong, ulong, ulong)' {aka 'long int(long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int)'} and 'long int(long int, long long int, long long int, long int)' [-Wattribute-alias]
static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \
^~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/sync.c:360:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(sync_file_range, int, fd, loff_t, offset, loff_t, nbytes,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:41:14: note: aliased declaration here
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
^~~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/sync.c:360:1: note: in expansion of macro 'SYSCALL_DEFINE4'
--
In file included from include/linux/uaccess.h:13,
from include/linux/sched/task.h:13,
from include/linux/sched/signal.h:9,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs/super_types.h:13,
from include/linux/fs/super.h:5,
from include/linux/fs.h:5,
from include/linux/namei.h:5,
from fs/utimes.c:4:
arch/riscv/include/asm/uaccess.h: In function '__uaccess_mask_ptr':
>> arch/riscv/include/asm/uaccess.h:86:65: warning: right shift count >= width of type [-Wshift-count-overflow]
unsigned long mask = (unsigned long)((long)(TASK_SIZE - 1 - p) >> 63);
^~
In file included from include/linux/compat.h:34,
from arch/riscv/include/asm/elf.h:12,
from include/linux/elf.h:6,
from include/linux/module.h:20,
from include/linux/device/driver.h:21,
from include/linux/device.h:32,
from include/linux/node.h:18,
from include/linux/cpu.h:17,
from include/linux/static_call.h:135,
from include/linux/tracepoint.h:22,
from include/trace/syscall.h:5,
from include/linux/syscalls.h:95,
from fs/utimes.c:6:
fs/utimes.c: At top level:
arch/riscv/include/asm/syscall_wrapper.h:35:14: warning: '__se_sys_utimensat' alias between functions of incompatible types 'long int(ulong, ulong, ulong, ulong, ulong, ulong, ulong)' {aka 'long int(long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int)'} and 'long int(long int, long int, long int, long int)' [-Wattribute-alias]
static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \
^~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/utimes.c:142:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:41:14: note: aliased declaration here
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
^~~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/utimes.c:142:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename,
^~~~~~~~~~~~~~~
--
In file included from include/linux/uaccess.h:13,
from include/linux/sched/task.h:13,
from include/linux/sched/signal.h:9,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs/super_types.h:13,
from include/linux/fs/super.h:5,
from include/linux/fs.h:5,
from fs/namei.c:22:
arch/riscv/include/asm/uaccess.h: In function '__uaccess_mask_ptr':
>> arch/riscv/include/asm/uaccess.h:86:65: warning: right shift count >= width of type [-Wshift-count-overflow]
unsigned long mask = (unsigned long)((long)(TASK_SIZE - 1 - p) >> 63);
^~
In file included from include/linux/compat.h:34,
from arch/riscv/include/asm/elf.h:12,
from include/linux/elf.h:6,
from include/linux/module.h:20,
from include/linux/bpf.h:21,
from include/linux/security.h:35,
from fs/namei.c:29:
fs/namei.c: At top level:
arch/riscv/include/asm/syscall_wrapper.h:35:14: warning: '__se_sys_mknodat' alias between functions of incompatible types 'long int(ulong, ulong, ulong, ulong, ulong, ulong, ulong)' {aka 'long int(long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int)'} and 'long int(long int, long int, long int, long int)' [-Wattribute-alias]
static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \
^~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/namei.c:5169:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:41:14: note: aliased declaration here
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
^~~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/namei.c:5169:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:35:14: warning: '__se_sys_rename' alias between functions of incompatible types 'long int(ulong, ulong, ulong, ulong, ulong, ulong, ulong)' {aka 'long int(long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int)'} and 'long int(long int, long int)' [-Wattribute-alias]
static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \
^~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:226:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE2(name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/namei.c:6184:1: note: in expansion of macro 'SYSCALL_DEFINE2'
SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newname)
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:41:14: note: aliased declaration here
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
^~~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:226:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE2(name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/namei.c:6184:1: note: in expansion of macro 'SYSCALL_DEFINE2'
SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newname)
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:35:14: warning: '__se_sys_renameat' alias between functions of incompatible types 'long int(ulong, ulong, ulong, ulong, ulong, ulong, ulong)' {aka 'long int(long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int)'} and 'long int(long int, long int, long int, long int)' [-Wattribute-alias]
static long __se_##prefix##name(ulong, ulong, ulong, ulong, ulong, ulong, \
^~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/namei.c:6176:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
^~~~~~~~~~~~~~~
arch/riscv/include/asm/syscall_wrapper.h:41:14: note: aliased declaration here
static long ___se_##prefix##name(__MAP(x,__SC_LONG,__VA_ARGS__))
^~~~~~
arch/riscv/include/asm/syscall_wrapper.h:82:2: note: in expansion of macro '__SYSCALL_SE_DEFINEx'
__SYSCALL_SE_DEFINEx(x, sys, name, __VA_ARGS__) \
^~~~~~~~~~~~~~~~~~~~
include/linux/syscalls.h:236:2: note: in expansion of macro '__SYSCALL_DEFINEx'
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
^~~~~~~~~~~~~~~~~
include/linux/syscalls.h:228:36: note: in expansion of macro 'SYSCALL_DEFINEx'
#define SYSCALL_DEFINE4(name, ...) SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
^~~~~~~~~~~~~~~
fs/namei.c:6176:1: note: in expansion of macro 'SYSCALL_DEFINE4'
SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
^~~~~~~~~~~~~~~
..
vim +86 arch/riscv/include/asm/uaccess.h
58
59 #define __enable_user_access() \
60 __asm__ __volatile__ ("csrs sstatus, %0" : : "r" (SR_SUM) : "memory")
61 #define __disable_user_access() \
62 __asm__ __volatile__ ("csrc sstatus, %0" : : "r" (SR_SUM) : "memory")
63
64 /*
65 * This is the smallest unsigned integer type that can fit a value
66 * (up to 'long long')
67 */
68 #define __inttype(x) __typeof__( \
69 __typefits(x, char, \
70 __typefits(x, short, \
71 __typefits(x, int, \
72 __typefits(x, long, 0ULL)))))
73
74 #define __typefits(x, type, not) \
75 __builtin_choose_expr(sizeof(x) <= sizeof(type), (unsigned type)0, not)
76
77 /*
78 * Sanitize a uaccess pointer such that it cannot reach any kernel address.
79 * Branchlessly clamp any address >= TASK_SIZE to the unmapped guard page
80 * at TASK_SIZE-1, which will always fault on access.
81 */
82 #define uaccess_mask_ptr(ptr) ((__typeof__(ptr))__uaccess_mask_ptr(ptr))
83 static inline void __user *__uaccess_mask_ptr(const void __user *ptr)
84 {
85 unsigned long p = (unsigned long)ptr;
> 86 unsigned long mask = (unsigned long)((long)(TASK_SIZE - 1 - p) >> 63);
87
88 return (void __user *)((p & ~mask) | ((TASK_SIZE - 1) & mask));
89 }
90
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.