@@ -48,6 +48,15 @@ static const struct bpf_map_ops * const bpf_map_types[] = {
48
48
#undef BPF_MAP_TYPE
49
49
};
50
50
51
+ /*
52
+ * If we're handed a bigger struct than we know of, ensure all the unknown bits
53
+ * are 0 - i.e. new user-space does not rely on any kernel feature extensions
54
+ * we don't know about yet.
55
+ *
56
+ * There is a ToCToU between this function call and the following
57
+ * copy_from_user() call. However, this is not a concern since this function is
58
+ * meant to be a future-proofing of bits.
59
+ */
51
60
static int check_uarg_tail_zero (void __user * uaddr ,
52
61
size_t expected_size ,
53
62
size_t actual_size )
@@ -57,6 +66,12 @@ static int check_uarg_tail_zero(void __user *uaddr,
57
66
unsigned char val ;
58
67
int err ;
59
68
69
+ if (unlikely (actual_size > PAGE_SIZE )) /* silly large */
70
+ return - E2BIG ;
71
+
72
+ if (unlikely (!access_ok (VERIFY_READ , uaddr , actual_size )))
73
+ return - EFAULT ;
74
+
60
75
if (actual_size <= expected_size )
61
76
return 0 ;
62
77
@@ -1393,17 +1408,6 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
1393
1408
if (!capable (CAP_SYS_ADMIN ) && sysctl_unprivileged_bpf_disabled )
1394
1409
return - EPERM ;
1395
1410
1396
- if (!access_ok (VERIFY_READ , uattr , 1 ))
1397
- return - EFAULT ;
1398
-
1399
- if (size > PAGE_SIZE ) /* silly large */
1400
- return - E2BIG ;
1401
-
1402
- /* If we're handed a bigger struct than we know of,
1403
- * ensure all the unknown bits are 0 - i.e. new
1404
- * user-space does not rely on any kernel feature
1405
- * extensions we dont know about yet.
1406
- */
1407
1411
err = check_uarg_tail_zero (uattr , sizeof (attr ), size );
1408
1412
if (err )
1409
1413
return err ;
0 commit comments