1 /* "The osf_getsysinfo function in arch/alpha/kernel/osf_sys.c in the
2 Linux kernel before 2.6.39.4 on the Alpha platform does not properly
3 restrict the data size for GSI_GET_HWRPB operations, which allows
4 local users to obtain sensitive information from kernel memory via
7 Fixed in 3d0475119d8722798db5e88f26493f6547a4bb5b on linux-2.6.39.y
10 // TODO: remove need for this option:
11 /* { dg-additional-options "-fanalyzer-checker=taint" } */
13 #include "analyzer-decls.h"
14 #include "test-uaccess.h"
16 /* Adapted from include/linux/linkage.h. */
20 /* Adapted from include/linux/syscalls.h. */
22 #define __SC_DECL1(t1, a1) t1 a1
23 #define __SC_DECL2(t2, a2, ...) t2 a2, __SC_DECL1(__VA_ARGS__)
24 #define __SC_DECL3(t3, a3, ...) t3 a3, __SC_DECL2(__VA_ARGS__)
25 #define __SC_DECL4(t4, a4, ...) t4 a4, __SC_DECL3(__VA_ARGS__)
26 #define __SC_DECL5(t5, a5, ...) t5 a5, __SC_DECL4(__VA_ARGS__)
27 #define __SC_DECL6(t6, a6, ...) t6 a6, __SC_DECL5(__VA_ARGS__)
29 #define SYSCALL_DEFINEx(x, sname, ...) \
30 __SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
32 #define SYSCALL_DEFINE(name) asmlinkage long sys_##name
33 #define __SYSCALL_DEFINEx(x, name, ...) \
34 asmlinkage __attribute__((tainted_args)) \
35 long sys##name(__SC_DECL##x(__VA_ARGS__))
37 #define SYSCALL_DEFINE5(name, ...) SYSCALL_DEFINEx(5, _##name, __VA_ARGS__)
39 /* Adapted from arch/alpha/include/asm/hwrpb.h. */
42 unsigned long phys_addr
; /* check: physical address of the hwrpb */
43 unsigned long id
; /* check: "HWRPB\0\0\0" */
44 unsigned long revision
;
45 unsigned long size
; /* size of hwrpb */
49 extern struct hwrpb_struct
*hwrpb
;
51 /* Adapted from arch/alpha/kernel/osf_sys.c. */
53 SYSCALL_DEFINE5(osf_getsysinfo
, unsigned long, op
, void __user
*, buffer
,
54 unsigned long, nbytes
, int __user
*, start
, void __user
*, arg
)
58 __analyzer_dump_state ("taint", nbytes
); /* { dg-warning "tainted" } */
60 /* TODO: should have an event explaining why "nbytes" is treated as
61 attacker-controlled. */
63 /* case GSI_GET_HWRPB: */
64 if (nbytes
< sizeof(*hwrpb
))
67 __analyzer_dump_state ("taint", nbytes
); /* { dg-warning "has_lb" } */
69 if (copy_to_user(buffer
, hwrpb
, nbytes
) != 0) /* { dg-warning "use of attacker-controlled value 'nbytes' as size without upper-bounds checking" } */
77 /* With the fix for the sense of the size comparison. */
79 SYSCALL_DEFINE5(osf_getsysinfo_fixed
, unsigned long, op
, void __user
*, buffer
,
80 unsigned long, nbytes
, int __user
*, start
, void __user
*, arg
)
84 /* case GSI_GET_HWRPB: */
85 if (nbytes
> sizeof(*hwrpb
))
87 if (copy_to_user(buffer
, hwrpb
, nbytes
) != 0) /* { dg-bogus "attacker-controlled" } */