summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2025-11-12 22:28:13 +0100
committerjvoisin2025-11-14 13:55:31 +0100
commitbf242b15e1f7873bdb940c2441b5e57747bc2f81 (patch)
treedd80ee51edf4542b65a9e49db369dc44d089c359
parentc93890993aded39be2f8f820fb19d8efe2cd9184 (diff)
Add `access` annotations
-rw-r--r--include/fortify-headers.h11
-rw-r--r--include/stdio.h10
-rw-r--r--include/string.h23
-rw-r--r--include/strings.h3
-rw-r--r--include/sys/socket.h4
-rw-r--r--include/unistd.h10
6 files changed, 61 insertions, 0 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index e406dce..a9b7498 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -59,4 +59,15 @@
59#define __bos(ptr, type) __builtin_object_size (ptr, type) 59#define __bos(ptr, type) __builtin_object_size (ptr, type)
60#endif 60#endif
61 61
62/* This needs to be two different conditions: https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html */
63#if defined __has_attribute
64#if __has_attribute (access)
65#define __access(...) __attribute__ ((access (__VA_ARGS__)))
66#else
67#define __access(...)
68#endif
69#else
70#define __access(...)
71#endif
72
62#endif 73#endif
diff --git a/include/stdio.h b/include/stdio.h
index a75c9ea..67738ed 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -37,6 +37,8 @@ extern "C" {
37#undef snprintf 37#undef snprintf
38#undef sprintf 38#undef sprintf
39 39
40__access(read_write, 1, 2)
41__access(read_only, 3)
40_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) 42_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
41{ 43{
42 size_t __b = __bos(__s, 0); 44 size_t __b = __bos(__s, 0);
@@ -46,6 +48,8 @@ _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
46 return __orig_fgets(__s, __n, __f); 48 return __orig_fgets(__s, __n, __f);
47} 49}
48 50
51__access(write_only, 1)
52__access(read_only, 4)
49_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, 53_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
50 size_t __m, FILE *__f) 54 size_t __m, FILE *__f)
51{ 55{
@@ -58,6 +62,8 @@ _FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
58 return __orig_fread(__d, __n, __m, __f); 62 return __orig_fread(__d, __n, __m, __f);
59} 63}
60 64
65__access(read_only, 1)
66__access(write_only, 4)
61_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, 67_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
62 size_t __m, FILE *__f) 68 size_t __m, FILE *__f)
63{ 69{
@@ -70,6 +76,8 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
70 return __orig_fwrite(__d, __n, __m, __f); 76 return __orig_fwrite(__d, __n, __m, __f);
71} 77}
72 78
79__access(write_only, 1, 2)
80__access(read_only, 3)
73_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n, 81_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
74 const char *__f, __builtin_va_list __v) 82 const char *__f, __builtin_va_list __v)
75{ 83{
@@ -80,6 +88,8 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
80 return __orig_vsnprintf(__s, __n, __f, __v); 88 return __orig_vsnprintf(__s, __n, __f, __v);
81} 89}
82 90
91__access(write_only, 1)
92__access(read_only, 2)
83_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, 93_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
84 __builtin_va_list __v) 94 __builtin_va_list __v)
85{ 95{
diff --git a/include/string.h b/include/string.h
index 9fc1cd4..cf0be60 100644
--- a/include/string.h
+++ b/include/string.h
@@ -37,6 +37,8 @@ extern "C" {
37#undef strncat 37#undef strncat
38#undef strncpy 38#undef strncpy
39 39
40__access(write_only, 1, 3)
41__access(read_only, 2, 3)
40_FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od, 42_FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od,
41 const void * _FORTIFY_POS0 __os, size_t __n) 43 const void * _FORTIFY_POS0 __os, size_t __n)
42{ 44{
@@ -55,6 +57,8 @@ _FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od,
55 return __builtin_memcpy(__od, __os, __n); 57 return __builtin_memcpy(__od, __os, __n);
56} 58}
57 59
60__access(write_only, 1, 3)
61__access(read_only, 2, 3)
58_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d, 62_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
59 const void * _FORTIFY_POS0 __s, size_t __n) 63 const void * _FORTIFY_POS0 __s, size_t __n)
60{ 64{
@@ -66,6 +70,7 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
66 return __orig_memmove(__d, __s, __n); 70 return __orig_memmove(__d, __s, __n);
67} 71}
68 72
73__access(write_only, 1, 3)
69_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n) 74_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n)
70{ 75{
71 size_t __b = __bos(__d, 0); 76 size_t __b = __bos(__d, 0);
@@ -79,6 +84,8 @@ _FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n)
79 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 84 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
80 || defined(_BSD_SOURCE) 85 || defined(_BSD_SOURCE)
81#undef stpcpy 86#undef stpcpy
87__access(write_only, 1)
88__access(read_only, 2)
82_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s) 89_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
83{ 90{
84 size_t __b = __bos(__d, 0); 91 size_t __b = __bos(__d, 0);
@@ -89,6 +96,8 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
89} 96}
90 97
91#undef stpncpy 98#undef stpncpy
99__access(write_only, 1)
100__access(read_only, 2)
92_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s, 101_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
93 size_t __n) 102 size_t __n)
94{ 103{
@@ -100,6 +109,8 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
100} 109}
101#endif 110#endif
102 111
112__access(read_write, 1)
113__access(read_only, 2)
103_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s) 114_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
104{ 115{
105 size_t __b = __bos(__d, 0); 116 size_t __b = __bos(__d, 0);
@@ -109,6 +120,8 @@ _FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
109 return __orig_strcat(__d, __s); 120 return __orig_strcat(__d, __s);
110} 121}
111 122
123__access(write_only, 1)
124__access(read_only, 2)
112_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s) 125_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
113{ 126{
114 size_t __b = __bos(__d, 0); 127 size_t __b = __bos(__d, 0);
@@ -118,6 +131,8 @@ _FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
118 return __orig_strcpy(__d, __s); 131 return __orig_strcpy(__d, __s);
119} 132}
120 133
134__access(read_write, 1)
135__access(read_only, 2)
121_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s, 136_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
122 size_t __n) 137 size_t __n)
123{ 138{
@@ -135,6 +150,8 @@ _FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
135 return __orig_strncat(__d, __s, __n); 150 return __orig_strncat(__d, __s, __n);
136} 151}
137 152
153__access(write_only, 1)
154__access(read_only, 2)
138_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d, 155_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
139 const char *__s, size_t __n) 156 const char *__s, size_t __n)
140{ 157{
@@ -147,6 +164,8 @@ _FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
147 164
148#ifdef _GNU_SOURCE 165#ifdef _GNU_SOURCE
149#undef mempcpy 166#undef mempcpy
167__access(write_only, 1, 3)
168__access(read_only, 2, 3)
150_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d, 169_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
151 const void * _FORTIFY_POS0 __s, size_t __n) 170 const void * _FORTIFY_POS0 __s, size_t __n)
152{ 171{
@@ -162,6 +181,8 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
162#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 181#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
163#undef strlcat 182#undef strlcat
164#undef strlcpy 183#undef strlcpy
184__access(read_write, 1)
185__access(read_only, 2)
165_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d, 186_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
166 const char *__s, size_t __n) 187 const char *__s, size_t __n)
167{ 188{
@@ -172,6 +193,8 @@ _FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
172 return __orig_strlcat(__d, __s, __n); 193 return __orig_strlcat(__d, __s, __n);
173} 194}
174 195
196__access(write_only, 1)
197__access(read_only, 2)
175_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d, 198_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d,
176 const char *__s, size_t __n) 199 const char *__s, size_t __n)
177{ 200{
diff --git a/include/strings.h b/include/strings.h
index 862b7be..3b6b765 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -31,6 +31,8 @@ extern "C" {
31 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) 31 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
32#undef bcopy 32#undef bcopy
33#undef bzero 33#undef bzero
34__access(write_only, 2, 3)
35__access(read_only, 1, 3)
34_FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s, 36_FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s,
35 void * _FORTIFY_POS0 __d, size_t __n) 37 void * _FORTIFY_POS0 __d, size_t __n)
36{ 38{
@@ -42,6 +44,7 @@ _FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s,
42 return __orig_bcopy(__s, __d, __n); 44 return __orig_bcopy(__s, __d, __n);
43} 45}
44 46
47__access(write_only, 1, 2)
45_FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n) 48_FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n)
46{ 49{
47 size_t __b = __bos(__s, 0); 50 size_t __b = __bos(__s, 0);
diff --git a/include/sys/socket.h b/include/sys/socket.h
index 7dfa71a..94cc0c8 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -34,6 +34,7 @@ extern "C" {
34#undef send 34#undef send
35#undef sendto 35#undef sendto
36 36
37__access(write_only, 2, 3)
37_FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n, 38_FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n,
38 int __fl) 39 int __fl)
39{ 40{
@@ -44,6 +45,7 @@ _FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n,
44 return __orig_recv(__f, __s, __n, __fl); 45 return __orig_recv(__f, __s, __n, __fl);
45} 46}
46 47
48__access(write_only, 2, 3)
47_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void * _FORTIFY_POS0 __s, 49_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void * _FORTIFY_POS0 __s,
48 size_t __n, int __fl, 50 size_t __n, int __fl,
49 struct sockaddr *__a, socklen_t *__l) 51 struct sockaddr *__a, socklen_t *__l)
@@ -55,6 +57,7 @@ _FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void * _FORTIFY_POS0 __s,
55 return __orig_recvfrom(__f, __s, __n, __fl, __a, __l); 57 return __orig_recvfrom(__f, __s, __n, __fl, __a, __l);
56} 58}
57 59
60__access(read_only, 2, 3)
58_FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s, 61_FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s,
59 size_t __n, int __fl) 62 size_t __n, int __fl)
60{ 63{
@@ -65,6 +68,7 @@ _FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s,
65 return __orig_send(__f, __s, __n, __fl); 68 return __orig_send(__f, __s, __n, __fl);
66} 69}
67 70
71__access(read_only, 2, 3)
68_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void * _FORTIFY_POS0 __s, 72_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void * _FORTIFY_POS0 __s,
69 size_t __n, int __fl, 73 size_t __n, int __fl,
70 const struct sockaddr *__a, socklen_t __l) 74 const struct sockaddr *__a, socklen_t __l)
diff --git a/include/unistd.h b/include/unistd.h
index 4c18b73..a6c2ed1 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -41,6 +41,7 @@ extern "C" {
41#undef ttyname_r 41#undef ttyname_r
42#undef write 42#undef write
43 43
44__access(write_only, 2, 3)
44_FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l) 45_FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l)
45{ 46{
46 size_t __b = __bos(__s, 0); 47 size_t __b = __bos(__s, 0);
@@ -51,6 +52,7 @@ _FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __
51 return __r; 52 return __r;
52} 53}
53 54
55__access(write_only, 1, 2)
54_FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l) 56_FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l)
55{ 57{
56 size_t __b = __bos(__s, 0); 58 size_t __b = __bos(__s, 0);
@@ -62,6 +64,7 @@ _FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l)
62 64
63#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 65#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
64#undef getdomainname 66#undef getdomainname
67__access(write_only, 1, 2)
65_FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l) 68_FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l)
66{ 69{
67 size_t __b = __bos(__s, 0); 70 size_t __b = __bos(__s, 0);
@@ -81,6 +84,7 @@ _FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s)
81 return __orig_getgroups(__l, __s); 84 return __orig_getgroups(__l, __s);
82} 85}
83 86
87__access(write_only, 1, 2)
84_FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l) 88_FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l)
85{ 89{
86 size_t __b = __bos(__s, 0); 90 size_t __b = __bos(__s, 0);
@@ -90,6 +94,7 @@ _FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l)
90 return __orig_gethostname(__s, __l); 94 return __orig_gethostname(__s, __l);
91} 95}
92 96
97__access(write_only, 1, 2)
93_FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l) 98_FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l)
94{ 99{
95 size_t __b = __bos(__s, 0); 100 size_t __b = __bos(__s, 0);
@@ -109,6 +114,7 @@ _FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s,
109 return __orig_pread(__f, __s, __n, __o); 114 return __orig_pread(__f, __s, __n, __o);
110} 115}
111 116
117__access(write_only, 2, 3)
112_FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n) 118_FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n)
113{ 119{
114 size_t __b = __bos(__s, 0); 120 size_t __b = __bos(__s, 0);
@@ -118,6 +124,7 @@ _FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n)
118 return __orig_read(__f, __s, __n); 124 return __orig_read(__f, __s, __n);
119} 125}
120 126
127__access(write_only, 2, 3)
121_FORTIFY_FN(readlink) ssize_t readlink(const char *__p, 128_FORTIFY_FN(readlink) ssize_t readlink(const char *__p,
122 char * _FORTIFY_POS0 __s, size_t __n) 129 char * _FORTIFY_POS0 __s, size_t __n)
123{ 130{
@@ -128,6 +135,7 @@ _FORTIFY_FN(readlink) ssize_t readlink(const char *__p,
128 return __orig_readlink(__p, __s, __n); 135 return __orig_readlink(__p, __s, __n);
129} 136}
130 137
138__access(write_only, 3, 4)
131_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, 139_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p,
132 char * _FORTIFY_POS0 __s, size_t __n) 140 char * _FORTIFY_POS0 __s, size_t __n)
133{ 141{
@@ -138,6 +146,7 @@ _FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p,
138 return __orig_readlinkat(__f, __p, __s, __n); 146 return __orig_readlinkat(__f, __p, __s, __n);
139} 147}
140 148
149__access(write_only, 2, 3)
141_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s, 150_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s,
142 size_t __n) 151 size_t __n)
143{ 152{
@@ -148,6 +157,7 @@ _FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s,
148 return __orig_ttyname_r(__f, __s, __n); 157 return __orig_ttyname_r(__f, __s, __n);
149} 158}
150 159
160__access(read_only, 2, 3)
151_FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s, 161_FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s,
152 size_t __n) 162 size_t __n)
153{ 163{