Skip to content

Commit 9dd819a

Browse files
keestorvalds
authored andcommitted
uaccess: add missing __must_check attributes
The usercopy implementation comments describe that callers of the copy_*_user() family of functions must always have their return values checked. This can be enforced at compile time with __must_check, so add it where needed. Link: http://lkml.kernel.org/r/201908251609.ADAD5CAAC1@keescook Signed-off-by: Kees Cook <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Dan Carpenter <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d5372c3 commit 9dd819a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

include/linux/thread_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static inline void copy_overflow(int size, unsigned long count)
134134
WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
135135
}
136136

137-
static __always_inline bool
137+
static __always_inline __must_check bool
138138
check_copy_size(const void *addr, size_t bytes, bool is_source)
139139
{
140140
int sz = __compiletime_object_size(addr);

include/linux/uaccess.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@
5555
* as usual) and both source and destination can trigger faults.
5656
*/
5757

58-
static __always_inline unsigned long
58+
static __always_inline __must_check unsigned long
5959
__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
6060
{
6161
kasan_check_write(to, n);
6262
check_object_size(to, n, false);
6363
return raw_copy_from_user(to, from, n);
6464
}
6565

66-
static __always_inline unsigned long
66+
static __always_inline __must_check unsigned long
6767
__copy_from_user(void *to, const void __user *from, unsigned long n)
6868
{
6969
might_fault();
@@ -85,15 +85,15 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
8585
* The caller should also make sure he pins the user space address
8686
* so that we don't result in page fault and sleep.
8787
*/
88-
static __always_inline unsigned long
88+
static __always_inline __must_check unsigned long
8989
__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
9090
{
9191
kasan_check_read(from, n);
9292
check_object_size(from, n, true);
9393
return raw_copy_to_user(to, from, n);
9494
}
9595

96-
static __always_inline unsigned long
96+
static __always_inline __must_check unsigned long
9797
__copy_to_user(void __user *to, const void *from, unsigned long n)
9898
{
9999
might_fault();
@@ -103,7 +103,7 @@ __copy_to_user(void __user *to, const void *from, unsigned long n)
103103
}
104104

105105
#ifdef INLINE_COPY_FROM_USER
106-
static inline unsigned long
106+
static inline __must_check unsigned long
107107
_copy_from_user(void *to, const void __user *from, unsigned long n)
108108
{
109109
unsigned long res = n;
@@ -117,12 +117,12 @@ _copy_from_user(void *to, const void __user *from, unsigned long n)
117117
return res;
118118
}
119119
#else
120-
extern unsigned long
120+
extern __must_check unsigned long
121121
_copy_from_user(void *, const void __user *, unsigned long);
122122
#endif
123123

124124
#ifdef INLINE_COPY_TO_USER
125-
static inline unsigned long
125+
static inline __must_check unsigned long
126126
_copy_to_user(void __user *to, const void *from, unsigned long n)
127127
{
128128
might_fault();
@@ -133,7 +133,7 @@ _copy_to_user(void __user *to, const void *from, unsigned long n)
133133
return n;
134134
}
135135
#else
136-
extern unsigned long
136+
extern __must_check unsigned long
137137
_copy_to_user(void __user *, const void *, unsigned long);
138138
#endif
139139

@@ -222,8 +222,9 @@ static inline bool pagefault_disabled(void)
222222

223223
#ifndef ARCH_HAS_NOCACHE_UACCESS
224224

225-
static inline unsigned long __copy_from_user_inatomic_nocache(void *to,
226-
const void __user *from, unsigned long n)
225+
static inline __must_check unsigned long
226+
__copy_from_user_inatomic_nocache(void *to, const void __user *from,
227+
unsigned long n)
227228
{
228229
return __copy_from_user_inatomic(to, from, n);
229230
}

0 commit comments

Comments
 (0)