Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/taint-CVE-2020-13143.h

raw
1 /* Shared header for the various taint-CVE-2020-13143.h tests.
2
3 "gadget_dev_desc_UDC_store in drivers/usb/gadget/configfs.c in the
4 Linux kernel 3.16 through 5.6.13 relies on kstrdup without considering
5 the possibility of an internal '\0' value, which allows attackers to
6 trigger an out-of-bounds read, aka CID-15753588bcd4."
7
8 Fixed by 15753588bcd4bbffae1cca33c8ced5722477fe1f on linux-5.7.y
9 in linux-stable. */
10
11 #include <stddef.h>
12
13 /* Adapted from include/uapi/asm-generic/posix_types.h */
14
15 typedef unsigned int __kernel_size_t;
16 typedef int __kernel_ssize_t;
17
18 /* Adapted from include/linux/types.h */
19
20 //typedef __kernel_size_t size_t;
21 typedef __kernel_ssize_t ssize_t;
22
23 /* Adapted from include/linux/kernel.h */
24
25 #define container_of(ptr, type, member) ({ \
26 void *__mptr = (void *)(ptr); \
27 /* [...snip...] */ \
28 ((type *)(__mptr - offsetof(type, member))); })
29
30 /* Adapted from include/linux/configfs.h */
31
32 struct config_item {
33 /* [...snip...] */
34 };
35
36 struct config_group {
37 struct config_item cg_item;
38 /* [...snip...] */
39 };
40
41 static inline struct config_group *to_config_group(struct config_item *item)
42 {
43 return item ? container_of(item,struct config_group,cg_item) : NULL;
44 }
45
46 #define CONFIGFS_ATTR(_pfx, _name) \
47 static struct configfs_attribute _pfx##attr_##_name = { \
48 /* [...snip...] */ \
49 .store = _pfx##_name##_store, \
50 }
51
52 /* Adapted from include/linux/compiler.h */
53
54 #define __force
55
56 /* Adapted from include/asm-generic/errno-base.h */
57
58 #define ENOMEM 12 /* Out of memory */
59
60 /* Adapted from include/linux/types.h */
61
62 #define __bitwise__
63 typedef unsigned __bitwise__ gfp_t;
64
65 /* Adapted from include/linux/gfp.h */
66
67 #define ___GFP_WAIT 0x10u
68 #define ___GFP_IO 0x40u
69 #define ___GFP_FS 0x80u
70 #define __GFP_WAIT ((__force gfp_t)___GFP_WAIT)
71 #define __GFP_IO ((__force gfp_t)___GFP_IO)
72 #define __GFP_FS ((__force gfp_t)___GFP_FS)
73 #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS)
74
75 /* Adapted from include/linux/compiler_attributes.h */
76
77 #define __malloc __attribute__((__malloc__))
78
79 /* Adapted from include/linux/string.h */
80
81 extern char *kstrdup(const char *s, gfp_t gfp) __malloc;
82
83 /* Adapted from drivers/usb/gadget/configfs.c */
84
85 struct gadget_info {
86 struct config_group group;
87 /* [...snip...] */ \
88 };