[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251220215608.434614-2-david.laight.linux@gmail.com>
Date: Sat, 20 Dec 2025 21:56:04 +0000
From: david.laight.linux@...il.com
To: Thomas Gleixner <tglx@...utronix.de>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Peter Zijlstra <peterz@...radead.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Kees Cook <kees@...nel.org>,
linux-kernel@...r.kernel.org,
akpm@...ux-foundation.org,
Al Viro <viro@...iv.linux.org.uk>
Cc: David Laight <david.laight.linux@...il.com>
Subject: [PATCH 1/5] uaccess: Fix scoped_user_read_access() for 'pointer to const'
From: David Laight <david.laight.linux@...il.com>
If a 'const struct foo __user *ptr' is used for the address passed
to scoped_user_read_access() then you get a warning/error
uaccess.h:691:1: error: initialization discards 'const' qualifier
from pointer target type [-Werror=discarded-qualifiers]
for the
void __user *_tmpptr = __scoped_user_access_begin(mode, uptr, size, elbl)
assignment.
Fix by using typeof(uptr) in that assignment and changing the 'read' functions
to use 'const void __user *ptr' rather than 'void __user *ptr'.
Fixes: e497310b4ffb "(uaccess: Provide scoped user access regions)"
Signed-off-by: David Laight <david.laight.linux@...il.com>
---
include/linux/uaccess.h | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 1f3804245c06..c5d5f2d395bc 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -650,32 +650,32 @@ static inline void user_access_restore(unsigned long flags) { }
#define user_rw_access_end() user_access_end()
/* Scoped user access */
-#define USER_ACCESS_GUARD(_mode) \
-static __always_inline void __user * \
-class_user_##_mode##_begin(void __user *ptr) \
+#define USER_ACCESS_GUARD(_mode, type) \
+static __always_inline type __user * \
+class_user_##_mode##_begin(type __user *ptr) \
{ \
return ptr; \
} \
\
static __always_inline void \
-class_user_##_mode##_end(void __user *ptr) \
+class_user_##_mode##_end(type __user *ptr) \
{ \
user_##_mode##_access_end(); \
} \
\
-DEFINE_CLASS(user_ ##_mode## _access, void __user *, \
+DEFINE_CLASS(user_ ##_mode## _access, type __user *, \
class_user_##_mode##_end(_T), \
- class_user_##_mode##_begin(ptr), void __user *ptr) \
+ class_user_##_mode##_begin(ptr), type __user *ptr) \
\
static __always_inline class_user_##_mode##_access_t \
-class_user_##_mode##_access_ptr(void __user *scope) \
+class_user_##_mode##_access_ptr(type __user *scope) \
{ \
return scope; \
}
-USER_ACCESS_GUARD(read)
-USER_ACCESS_GUARD(write)
-USER_ACCESS_GUARD(rw)
+USER_ACCESS_GUARD(read, const void)
+USER_ACCESS_GUARD(write, void)
+USER_ACCESS_GUARD(rw, void)
#undef USER_ACCESS_GUARD
/**
@@ -752,7 +752,7 @@ USER_ACCESS_GUARD(rw)
*/
#define __scoped_user_access(mode, uptr, size, elbl) \
for (bool done = false; !done; done = true) \
- for (void __user *_tmpptr = __scoped_user_access_begin(mode, uptr, size, elbl); \
+ for (typeof(uptr) _tmpptr = __scoped_user_access_begin(mode, uptr, size, elbl); \
!done; done = true) \
for (CLASS(user_##mode##_access, scope)(_tmpptr); !done; done = true) \
/* Force modified pointer usage within the scope */ \
--
2.39.5
Powered by blists - more mailing lists