Skip to content

Commit 3b82a6e

Browse files
James Morsectmarinas
authored andcommitted
Revert "arm64: uaccess: implement unsafe accessors"
This reverts commit a1f3394. The unsafe accessors allow the PAN enable/disable calls to be made once for a group of accesses. Adding these means we can now have sequences that look like this: | user_access_begin(); | unsafe_put_user(static-value, x, err); | unsafe_put_user(helper-that-sleeps(), x, err); | user_access_end(); Calling schedule() without taking an exception doesn't switch the PSTATE or TTBRs. We can switch out of a uaccess-enabled region, and run other code with uaccess enabled for a different thread. We can also switch from uaccess-disabled code back into this region, meaning the unsafe_put_user()s will fault. For software-PAN, threads that do this will get stuck as handle_mm_fault() will determine the page has already been mapped in, but we fault again as the page tables aren't loaded. To solve this we need code in __switch_to() that save/restores the PAN state. Acked-by: Julien Thierry <julien.thierry@arm.com> Acked-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 742fafa commit 3b82a6e

1 file changed

Lines changed: 15 additions & 46 deletions

File tree

‎arch/arm64/include/asm/uaccess.h‎

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,11 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr)
276276
: "+r" (err), "=&r" (x) \
277277
: "r" (addr), "i" (-EFAULT))
278278

279-
#define __get_user_err_unsafe(x, ptr, err) \
279+
#define __get_user_err(x, ptr, err) \
280280
do { \
281281
unsigned long __gu_val; \
282+
__chk_user_ptr(ptr); \
283+
uaccess_enable_not_uao(); \
282284
switch (sizeof(*(ptr))) { \
283285
case 1: \
284286
__get_user_asm("ldrb", "ldtrb", "%w", __gu_val, (ptr), \
@@ -299,39 +301,32 @@ do { \
299301
default: \
300302
BUILD_BUG(); \
301303
} \
302-
(x) = (__force __typeof__(*(ptr)))__gu_val; \
303-
} while (0)
304-
305-
#define __get_user_err_check(x, ptr, err) \
306-
do { \
307-
__chk_user_ptr(ptr); \
308-
uaccess_enable_not_uao(); \
309-
__get_user_err_unsafe((x), (ptr), (err)); \
310304
uaccess_disable_not_uao(); \
305+
(x) = (__force __typeof__(*(ptr)))__gu_val; \
311306
} while (0)
312307

313-
#define __get_user_err(x, ptr, err, accessor) \
308+
#define __get_user_check(x, ptr, err) \
314309
({ \
315310
__typeof__(*(ptr)) __user *__p = (ptr); \
316311
might_fault(); \
317312
if (access_ok(VERIFY_READ, __p, sizeof(*__p))) { \
318313
__p = uaccess_mask_ptr(__p); \
319-
accessor((x), __p, (err)); \
314+
__get_user_err((x), __p, (err)); \
320315
} else { \
321316
(x) = 0; (err) = -EFAULT; \
322317
} \
323318
})
324319

325320
#define __get_user_error(x, ptr, err) \
326321
({ \
327-
__get_user_err((x), (ptr), (err), __get_user_err_check); \
322+
__get_user_check((x), (ptr), (err)); \
328323
(void)0; \
329324
})
330325

331326
#define __get_user(x, ptr) \
332327
({ \
333328
int __gu_err = 0; \
334-
__get_user_err((x), (ptr), __gu_err, __get_user_err_check); \
329+
__get_user_check((x), (ptr), __gu_err); \
335330
__gu_err; \
336331
})
337332

@@ -351,9 +346,11 @@ do { \
351346
: "+r" (err) \
352347
: "r" (x), "r" (addr), "i" (-EFAULT))
353348

354-
#define __put_user_err_unsafe(x, ptr, err) \
349+
#define __put_user_err(x, ptr, err) \
355350
do { \
356351
__typeof__(*(ptr)) __pu_val = (x); \
352+
__chk_user_ptr(ptr); \
353+
uaccess_enable_not_uao(); \
357354
switch (sizeof(*(ptr))) { \
358355
case 1: \
359356
__put_user_asm("strb", "sttrb", "%w", __pu_val, (ptr), \
@@ -374,64 +371,36 @@ do { \
374371
default: \
375372
BUILD_BUG(); \
376373
} \
377-
} while (0)
378-
379-
380-
#define __put_user_err_check(x, ptr, err) \
381-
do { \
382-
__chk_user_ptr(ptr); \
383-
uaccess_enable_not_uao(); \
384-
__put_user_err_unsafe((x), (ptr), (err)); \
385374
uaccess_disable_not_uao(); \
386375
} while (0)
387376

388-
#define __put_user_err(x, ptr, err, accessor) \
377+
#define __put_user_check(x, ptr, err) \
389378
({ \
390379
__typeof__(*(ptr)) __user *__p = (ptr); \
391380
might_fault(); \
392381
if (access_ok(VERIFY_WRITE, __p, sizeof(*__p))) { \
393382
__p = uaccess_mask_ptr(__p); \
394-
accessor((x), __p, (err)); \
383+
__put_user_err((x), __p, (err)); \
395384
} else { \
396385
(err) = -EFAULT; \
397386
} \
398387
})
399388

400389
#define __put_user_error(x, ptr, err) \
401390
({ \
402-
__put_user_err((x), (ptr), (err), __put_user_err_check); \
391+
__put_user_check((x), (ptr), (err)); \
403392
(void)0; \
404393
})
405394

406395
#define __put_user(x, ptr) \
407396
({ \
408397
int __pu_err = 0; \
409-
__put_user_err((x), (ptr), __pu_err, __put_user_err_check); \
398+
__put_user_check((x), (ptr), __pu_err); \
410399
__pu_err; \
411400
})
412401

413402
#define put_user __put_user
414403

415-
416-
#define user_access_begin() uaccess_enable_not_uao()
417-
#define user_access_end() uaccess_disable_not_uao()
418-
419-
#define unsafe_get_user(x, ptr, err) \
420-
do { \
421-
int __gu_err = 0; \
422-
__get_user_err((x), (ptr), __gu_err, __get_user_err_unsafe); \
423-
if (__gu_err != 0) \
424-
goto err; \
425-
} while (0)
426-
427-
#define unsafe_put_user(x, ptr, err) \
428-
do { \
429-
int __pu_err = 0; \
430-
__put_user_err((x), (ptr), __pu_err, __put_user_err_unsafe); \
431-
if (__pu_err != 0) \
432-
goto err; \
433-
} while (0)
434-
435404
extern unsigned long __must_check __arch_copy_from_user(void *to, const void __user *from, unsigned long n);
436405
#define raw_copy_from_user(to, from, n) \
437406
({ \

0 commit comments

Comments
 (0)