Mike Frysinger | 13a7f29 | 2013-02-08 19:42:14 -0500 | [diff] [blame] | 1 | From 75201f160b9aa49af70d8f46fb1f087e63d603dd Mon Sep 17 00:00:00 2001 |
| 2 | From: Mike Frysinger <vapier@gentoo.org> |
| 3 | Date: Fri, 8 Feb 2013 17:12:41 -0500 |
| 4 | Subject: [PATCH] syscalls/sysctl: check if __NR_sysctl is defined |
| 5 | |
| 6 | Recent kernel ports have started omitting this old syscall, so if it |
| 7 | isn't defined, just display a normal TCONF message. |
| 8 | |
| 9 | Signed-off-by: Mike Frysinger <vapier@gentoo.org> |
| 10 | --- |
| 11 | testcases/kernel/syscalls/sysctl/sysctl01.c | 15 +++++++++++++++ |
| 12 | testcases/kernel/syscalls/sysctl/sysctl03.c | 15 +++++++++++++++ |
| 13 | testcases/kernel/syscalls/sysctl/sysctl04.c | 15 +++++++++++++++ |
| 14 | testcases/kernel/syscalls/sysctl/sysctl05.c | 15 +++++++++++++++ |
| 15 | 4 files changed, 60 insertions(+) |
| 16 | |
| 17 | diff --git a/testcases/kernel/syscalls/sysctl/sysctl01.c b/testcases/kernel/syscalls/sysctl/sysctl01.c |
| 18 | index ed2d067..cc2817e 100644 |
| 19 | --- a/testcases/kernel/syscalls/sysctl/sysctl01.c |
| 20 | +++ b/testcases/kernel/syscalls/sysctl/sysctl01.c |
| 21 | @@ -53,6 +53,10 @@ |
| 22 | #include <linux/sysctl.h> |
| 23 | |
| 24 | char *TCID = "sysctl01"; |
| 25 | + |
| 26 | +/* This is an older/deprecated syscall that newer arches are omitting */ |
| 27 | +#ifdef __NR_sysctl |
| 28 | + |
| 29 | int TST_TOTAL = 3; |
| 30 | |
| 31 | static int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp, |
| 32 | @@ -194,3 +198,14 @@ void cleanup() |
| 33 | TEST_CLEANUP; |
| 34 | |
| 35 | } |
| 36 | + |
| 37 | +#else |
| 38 | +int TST_TOTAL = 0; /* Total number of test cases. */ |
| 39 | + |
| 40 | +int main() |
| 41 | +{ |
| 42 | + |
| 43 | + tst_resm(TCONF, "This test needs a kernel that has sysctl syscall."); |
| 44 | + tst_exit(); |
| 45 | +} |
| 46 | +#endif |
| 47 | diff --git a/testcases/kernel/syscalls/sysctl/sysctl03.c b/testcases/kernel/syscalls/sysctl/sysctl03.c |
| 48 | index 09713d7..6caaa72 100644 |
| 49 | --- a/testcases/kernel/syscalls/sysctl/sysctl03.c |
| 50 | +++ b/testcases/kernel/syscalls/sysctl/sysctl03.c |
| 51 | @@ -73,6 +73,10 @@ |
| 52 | #include <pwd.h> |
| 53 | |
| 54 | char *TCID = "sysctl03"; |
| 55 | + |
| 56 | +/* This is an older/deprecated syscall that newer arches are omitting */ |
| 57 | +#ifdef __NR_sysctl |
| 58 | + |
| 59 | int TST_TOTAL = 2; |
| 60 | |
| 61 | int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp, |
| 62 | @@ -213,3 +217,14 @@ void cleanup(void) |
| 63 | { |
| 64 | TEST_CLEANUP; |
| 65 | } |
| 66 | + |
| 67 | +#else |
| 68 | +int TST_TOTAL = 0; /* Total number of test cases. */ |
| 69 | + |
| 70 | +int main() |
| 71 | +{ |
| 72 | + |
| 73 | + tst_resm(TCONF, "This test needs a kernel that has sysctl syscall."); |
| 74 | + tst_exit(); |
| 75 | +} |
| 76 | +#endif |
| 77 | diff --git a/testcases/kernel/syscalls/sysctl/sysctl04.c b/testcases/kernel/syscalls/sysctl/sysctl04.c |
| 78 | index 3e41418..bda1020 100644 |
| 79 | --- a/testcases/kernel/syscalls/sysctl/sysctl04.c |
| 80 | +++ b/testcases/kernel/syscalls/sysctl/sysctl04.c |
| 81 | @@ -54,6 +54,10 @@ |
| 82 | #include <linux/sysctl.h> |
| 83 | |
| 84 | char *TCID = "sysctl04"; |
| 85 | + |
| 86 | +/* This is an older/deprecated syscall that newer arches are omitting */ |
| 87 | +#ifdef __NR_sysctl |
| 88 | + |
| 89 | int TST_TOTAL = 2; |
| 90 | |
| 91 | int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp, |
| 92 | @@ -166,3 +170,14 @@ void cleanup() |
| 93 | TEST_CLEANUP; |
| 94 | |
| 95 | } |
| 96 | + |
| 97 | +#else |
| 98 | +int TST_TOTAL = 0; /* Total number of test cases. */ |
| 99 | + |
| 100 | +int main() |
| 101 | +{ |
| 102 | + |
| 103 | + tst_resm(TCONF, "This test needs a kernel that has sysctl syscall."); |
| 104 | + tst_exit(); |
| 105 | +} |
| 106 | +#endif |
| 107 | diff --git a/testcases/kernel/syscalls/sysctl/sysctl05.c b/testcases/kernel/syscalls/sysctl/sysctl05.c |
| 108 | index 4ec4e20..e06ad6e 100644 |
| 109 | --- a/testcases/kernel/syscalls/sysctl/sysctl05.c |
| 110 | +++ b/testcases/kernel/syscalls/sysctl/sysctl05.c |
| 111 | @@ -56,6 +56,10 @@ |
| 112 | #include <errno.h> |
| 113 | |
| 114 | char *TCID = "sysctl05"; |
| 115 | + |
| 116 | +/* This is an older/deprecated syscall that newer arches are omitting */ |
| 117 | +#ifdef __NR_sysctl |
| 118 | + |
| 119 | int TST_TOTAL = 2; |
| 120 | |
| 121 | int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp, |
| 122 | @@ -193,3 +197,14 @@ void cleanup() |
| 123 | TEST_CLEANUP; |
| 124 | |
| 125 | } |
| 126 | + |
| 127 | +#else |
| 128 | +int TST_TOTAL = 0; /* Total number of test cases. */ |
| 129 | + |
| 130 | +int main() |
| 131 | +{ |
| 132 | + |
| 133 | + tst_resm(TCONF, "This test needs a kernel that has sysctl syscall."); |
| 134 | + tst_exit(); |
| 135 | +} |
| 136 | +#endif |
| 137 | -- |
| 138 | 1.8.0.2 |
| 139 | |
| 140 | From a62b53febaa0a236c00a502c79c8e9ac0f3b468e Mon Sep 17 00:00:00 2001 |
| 141 | From: Mike Frysinger <vapier@gentoo.org> |
| 142 | Date: Fri, 8 Feb 2013 19:33:22 -0500 |
| 143 | Subject: [PATCH] tomoyo: stop using sysctl() |
| 144 | |
| 145 | Recent kernel ports have started omitting this old syscall, and glibc |
| 146 | makes it an error to try to include that header when it's unavailable. |
| 147 | So convert over to reading/writing the /proc/sys/ paths directly. |
| 148 | |
| 149 | Signed-off-by: Mike Frysinger <vapier@gentoo.org> |
| 150 | --- |
| 151 | testcases/kernel/security/tomoyo/include.h | 31 +++++++++++++++++++++- |
| 152 | .../kernel/security/tomoyo/tomoyo_file_test.c | 10 +++---- |
| 153 | .../kernel/security/tomoyo/tomoyo_new_file_test.c | 18 ++++++------- |
| 154 | 3 files changed, 42 insertions(+), 17 deletions(-) |
| 155 | |
| 156 | diff --git a/testcases/kernel/security/tomoyo/include.h b/testcases/kernel/security/tomoyo/include.h |
| 157 | index 44d6f6a..fd1b19b 100644 |
| 158 | --- a/testcases/kernel/security/tomoyo/include.h |
| 159 | +++ b/testcases/kernel/security/tomoyo/include.h |
| 160 | @@ -35,7 +35,6 @@ |
| 161 | #include <sys/socket.h> |
| 162 | #include <sys/stat.h> |
| 163 | #include <sys/syscall.h> |
| 164 | -#include <sys/sysctl.h> |
| 165 | #include <sys/time.h> |
| 166 | #include <sys/timex.h> |
| 167 | #include <sys/types.h> |
| 168 | @@ -84,6 +83,36 @@ static inline int pivot_root(const char *new_root, const char *put_old) |
| 169 | } |
| 170 | #endif |
| 171 | |
| 172 | +/* The sysctl() wrapper is dead and newer arches omit it now. */ |
| 173 | +static inline int write_sysctl(const char *path, const char *value) |
| 174 | +{ |
| 175 | + FILE *fp = fopen(path, "w"); |
| 176 | + if (!fp) |
| 177 | + return 1; |
| 178 | + fputs(value, fp); |
| 179 | + fclose(fp); |
| 180 | + return 0; |
| 181 | +} |
| 182 | + |
| 183 | +static inline int read_sysctl(const char *path, char *value, int len) |
| 184 | +{ |
| 185 | + char scratch[100]; |
| 186 | + FILE *fp = fopen(path, "r"); |
| 187 | + if (!fp) |
| 188 | + return 1; |
| 189 | + if (!value) { |
| 190 | + value = scratch; |
| 191 | + len = sizeof(scratch); |
| 192 | + } |
| 193 | + if (fgets(value, len, fp)) |
| 194 | + /* ignore */; |
| 195 | + fclose(fp); |
| 196 | + return 0; |
| 197 | +} |
| 198 | + |
| 199 | +/* Should be a fairly benign path to bang on. */ |
| 200 | +#define TEST_SYSCTL_PATH "/proc/sys/net/ipv4/ip_local_port_range" |
| 201 | + |
| 202 | #define proc_policy_dir "/sys/kernel/security/tomoyo/" |
| 203 | #define proc_policy_domain_policy "/sys/kernel/security/tomoyo/domain_policy" |
| 204 | #define proc_policy_exception_policy "/sys/kernel/security/tomoyo/exception_policy" |
| 205 | diff --git a/testcases/kernel/security/tomoyo/tomoyo_file_test.c b/testcases/kernel/security/tomoyo/tomoyo_file_test.c |
| 206 | index fa2dec1..010802e 100644 |
| 207 | --- a/testcases/kernel/security/tomoyo/tomoyo_file_test.c |
| 208 | +++ b/testcases/kernel/security/tomoyo/tomoyo_file_test.c |
| 209 | @@ -77,14 +77,11 @@ static void stage_file_test(void) |
| 210 | { |
| 211 | int fd; |
| 212 | { |
| 213 | - static int name[] = { CTL_NET, NET_IPV4, |
| 214 | - NET_IPV4_LOCAL_PORT_RANGE }; |
| 215 | - int buffer[2] = { 32768, 61000 }; |
| 216 | - size_t size = sizeof(buffer); |
| 217 | + const char buffer[] = "32768 61000"; |
| 218 | show_prompt("sysctl(READ)"); |
| 219 | - show_result(sysctl(name, 3, buffer, &size, 0, 0)); |
| 220 | + show_result(read_sysctl(TEST_SYSCTL_PATH, NULL, 0)); |
| 221 | show_prompt("sysctl(WRITE)"); |
| 222 | - show_result(sysctl(name, 3, 0, 0, buffer, size)); |
| 223 | + show_result(write_sysctl(TEST_SYSCTL_PATH, buffer)); |
| 224 | } |
| 225 | |
| 226 | /* QUESTION: Is there a file which can be passed to uselib()? */ |
| 227 | diff --git a/testcases/kernel/security/tomoyo/tomoyo_new_file_test.c b/testcases/kernel/security/tomoyo/tomoyo_new_file_test.c |
| 228 | index 2ed021e..16427d2 100644 |
| 229 | --- a/testcases/kernel/security/tomoyo/tomoyo_new_file_test.c |
| 230 | +++ b/testcases/kernel/security/tomoyo/tomoyo_new_file_test.c |
| 231 | @@ -90,9 +90,7 @@ static void mkfifo2(const char *pathname) |
| 232 | |
| 233 | static void stage_file_test(void) |
| 234 | { |
| 235 | - static int name[] = { CTL_NET, NET_IPV4, NET_IPV4_LOCAL_PORT_RANGE }; |
| 236 | - int buffer[2] = { 32768, 61000 }; |
| 237 | - size_t size = sizeof(buffer); |
| 238 | + const char buffer[] = "32768 61000"; |
| 239 | int pipe_fd[2] = { EOF, EOF }; |
| 240 | int error = 0; |
| 241 | int fd; |
| 242 | @@ -127,21 +125,23 @@ static void stage_file_test(void) |
| 243 | |
| 244 | policy = "allow_read /proc/sys/net/ipv4/ip_local_port_range"; |
| 245 | write_domain_policy(policy, 0); |
| 246 | - show_result(sysctl(name, 3, buffer, &size, 0, 0), 1); |
| 247 | + show_result(read_sysctl(TEST_SYSCTL_PATH, NULL, 0), 1); |
| 248 | write_domain_policy(policy, 1); |
| 249 | - show_result(sysctl(name, 3, buffer, &size, 0, 0), 0); |
| 250 | + show_result(read_sysctl(TEST_SYSCTL_PATH, NULL, 0), 0); |
| 251 | |
| 252 | policy = "allow_write /proc/sys/net/ipv4/ip_local_port_range"; |
| 253 | write_domain_policy(policy, 0); |
| 254 | - show_result(sysctl(name, 3, 0, 0, buffer, size), 1); |
| 255 | + show_result(write_sysctl(TEST_SYSCTL_PATH, buffer), 1); |
| 256 | write_domain_policy(policy, 1); |
| 257 | - show_result(sysctl(name, 3, 0, 0, buffer, size), 0); |
| 258 | + show_result(write_sysctl(TEST_SYSCTL_PATH, buffer), 0); |
| 259 | |
| 260 | policy = "allow_read/write /proc/sys/net/ipv4/ip_local_port_range"; |
| 261 | write_domain_policy(policy, 0); |
| 262 | - show_result(sysctl(name, 3, buffer, &size, buffer, size), 1); |
| 263 | + show_result(read_sysctl(TEST_SYSCTL_PATH, NULL, 0) && |
| 264 | + write_sysctl(TEST_SYSCTL_PATH, buffer), 1); |
| 265 | write_domain_policy(policy, 1); |
| 266 | - show_result(sysctl(name, 3, buffer, &size, buffer, size), 0); |
| 267 | + show_result(read_sysctl(TEST_SYSCTL_PATH, NULL, 0) && |
| 268 | + write_sysctl(TEST_SYSCTL_PATH, buffer), 0); |
| 269 | |
| 270 | policy = "allow_read /bin/true"; |
| 271 | write_domain_policy(policy, 0); |
| 272 | -- |
| 273 | 1.8.0.2 |