Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'landlock-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mic/linux

Pull landlock update from Mickaël Salaün:
"Fix test issues, improve build compatibility, and add new tests"

* tag 'landlock-6.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mic/linux:
landlock: Fix cosmetic change
samples/landlock: Fix building on musl libc
landlock: Fix warning from KUnit tests
selftests/landlock: Add test to check rule tied to covered mount point
selftests/landlock: Fix build of audit_test
selftests/landlock: Fix readlink check

+92 -31
+4 -1
samples/landlock/sandboxer.c
··· 13 13 #include <errno.h> 14 14 #include <fcntl.h> 15 15 #include <linux/landlock.h> 16 - #include <linux/prctl.h> 17 16 #include <linux/socket.h> 18 17 #include <stddef.h> 19 18 #include <stdio.h> ··· 23 24 #include <sys/syscall.h> 24 25 #include <unistd.h> 25 26 #include <stdbool.h> 27 + 28 + #if defined(__GLIBC__) 29 + #include <linux/prctl.h> 30 + #endif 26 31 27 32 #ifndef landlock_create_ruleset 28 33 static inline int
+1
security/landlock/fs.c
··· 895 895 /* Stops when a rule from each layer grants access. */ 896 896 if (allowed_parent1 && allowed_parent2) 897 897 break; 898 + 898 899 jump_up: 899 900 if (walker_path.dentry == walker_path.mnt->mnt_root) { 900 901 if (follow_up(&walker_path)) {
+42 -27
security/landlock/id.c
··· 119 119 120 120 #ifdef CONFIG_SECURITY_LANDLOCK_KUNIT_TEST 121 121 122 + static u8 get_random_u8_positive(void) 123 + { 124 + /* max() evaluates its arguments once. */ 125 + return max(1, get_random_u8()); 126 + } 127 + 122 128 static void test_range1_rand0(struct kunit *const test) 123 129 { 124 130 atomic64_t counter; ··· 133 127 init = get_random_u32(); 134 128 atomic64_set(&counter, init); 135 129 KUNIT_EXPECT_EQ(test, get_id_range(1, &counter, 0), init); 136 - KUNIT_EXPECT_EQ( 137 - test, get_id_range(get_random_u8(), &counter, get_random_u8()), 138 - init + 1); 130 + KUNIT_EXPECT_EQ(test, 131 + get_id_range(get_random_u8_positive(), &counter, 132 + get_random_u8()), 133 + init + 1); 139 134 } 140 135 141 136 static void test_range1_rand1(struct kunit *const test) ··· 147 140 init = get_random_u32(); 148 141 atomic64_set(&counter, init); 149 142 KUNIT_EXPECT_EQ(test, get_id_range(1, &counter, 1), init); 150 - KUNIT_EXPECT_EQ( 151 - test, get_id_range(get_random_u8(), &counter, get_random_u8()), 152 - init + 2); 143 + KUNIT_EXPECT_EQ(test, 144 + get_id_range(get_random_u8_positive(), &counter, 145 + get_random_u8()), 146 + init + 2); 153 147 } 154 148 155 149 static void test_range1_rand15(struct kunit *const test) ··· 161 153 init = get_random_u32(); 162 154 atomic64_set(&counter, init); 163 155 KUNIT_EXPECT_EQ(test, get_id_range(1, &counter, 15), init); 164 - KUNIT_EXPECT_EQ( 165 - test, get_id_range(get_random_u8(), &counter, get_random_u8()), 166 - init + 16); 156 + KUNIT_EXPECT_EQ(test, 157 + get_id_range(get_random_u8_positive(), &counter, 158 + get_random_u8()), 159 + init + 16); 167 160 } 168 161 169 162 static void test_range1_rand16(struct kunit *const test) ··· 175 166 init = get_random_u32(); 176 167 atomic64_set(&counter, init); 177 168 KUNIT_EXPECT_EQ(test, get_id_range(1, &counter, 16), init); 178 - KUNIT_EXPECT_EQ( 179 - test, get_id_range(get_random_u8(), &counter, get_random_u8()), 180 - init + 1); 169 + KUNIT_EXPECT_EQ(test, 170 + get_id_range(get_random_u8_positive(), &counter, 171 + get_random_u8()), 172 + init + 1); 181 173 } 182 174 183 175 static void test_range2_rand0(struct kunit *const test) ··· 189 179 init = get_random_u32(); 190 180 atomic64_set(&counter, init); 191 181 KUNIT_EXPECT_EQ(test, get_id_range(2, &counter, 0), init); 192 - KUNIT_EXPECT_EQ( 193 - test, get_id_range(get_random_u8(), &counter, get_random_u8()), 194 - init + 2); 182 + KUNIT_EXPECT_EQ(test, 183 + get_id_range(get_random_u8_positive(), &counter, 184 + get_random_u8()), 185 + init + 2); 195 186 } 196 187 197 188 static void test_range2_rand1(struct kunit *const test) ··· 203 192 init = get_random_u32(); 204 193 atomic64_set(&counter, init); 205 194 KUNIT_EXPECT_EQ(test, get_id_range(2, &counter, 1), init); 206 - KUNIT_EXPECT_EQ( 207 - test, get_id_range(get_random_u8(), &counter, get_random_u8()), 208 - init + 3); 195 + KUNIT_EXPECT_EQ(test, 196 + get_id_range(get_random_u8_positive(), &counter, 197 + get_random_u8()), 198 + init + 3); 209 199 } 210 200 211 201 static void test_range2_rand2(struct kunit *const test) ··· 217 205 init = get_random_u32(); 218 206 atomic64_set(&counter, init); 219 207 KUNIT_EXPECT_EQ(test, get_id_range(2, &counter, 2), init); 220 - KUNIT_EXPECT_EQ( 221 - test, get_id_range(get_random_u8(), &counter, get_random_u8()), 222 - init + 4); 208 + KUNIT_EXPECT_EQ(test, 209 + get_id_range(get_random_u8_positive(), &counter, 210 + get_random_u8()), 211 + init + 4); 223 212 } 224 213 225 214 static void test_range2_rand15(struct kunit *const test) ··· 231 218 init = get_random_u32(); 232 219 atomic64_set(&counter, init); 233 220 KUNIT_EXPECT_EQ(test, get_id_range(2, &counter, 15), init); 234 - KUNIT_EXPECT_EQ( 235 - test, get_id_range(get_random_u8(), &counter, get_random_u8()), 236 - init + 17); 221 + KUNIT_EXPECT_EQ(test, 222 + get_id_range(get_random_u8_positive(), &counter, 223 + get_random_u8()), 224 + init + 17); 237 225 } 238 226 239 227 static void test_range2_rand16(struct kunit *const test) ··· 245 231 init = get_random_u32(); 246 232 atomic64_set(&counter, init); 247 233 KUNIT_EXPECT_EQ(test, get_id_range(2, &counter, 16), init); 248 - KUNIT_EXPECT_EQ( 249 - test, get_id_range(get_random_u8(), &counter, get_random_u8()), 250 - init + 2); 234 + KUNIT_EXPECT_EQ(test, 235 + get_id_range(get_random_u8_positive(), &counter, 236 + get_random_u8()), 237 + init + 2); 251 238 } 252 239 253 240 #endif /* CONFIG_SECURITY_LANDLOCK_KUNIT_TEST */
+4 -3
tools/testing/selftests/landlock/audit.h
··· 403 403 /* It is assume that there is not already filtering rules. */ 404 404 filter->record_type = AUDIT_EXE; 405 405 if (!path) { 406 - filter->exe_len = readlink("/proc/self/exe", filter->exe, 407 - sizeof(filter->exe) - 1); 408 - if (filter->exe_len < 0) 406 + int ret = readlink("/proc/self/exe", filter->exe, 407 + sizeof(filter->exe) - 1); 408 + if (ret < 0) 409 409 return -errno; 410 410 411 + filter->exe_len = ret; 411 412 return 0; 412 413 } 413 414
+1
tools/testing/selftests/landlock/audit_test.c
··· 7 7 8 8 #define _GNU_SOURCE 9 9 #include <errno.h> 10 + #include <fcntl.h> 10 11 #include <limits.h> 11 12 #include <linux/landlock.h> 12 13 #include <pthread.h>
+40
tools/testing/selftests/landlock/fs_test.c
··· 1832 1832 ASSERT_EQ(ENOENT, test_open(dir_s3d3, O_RDONLY)); 1833 1833 } 1834 1834 1835 + /* 1836 + * This test checks that a rule on a directory used as a mount point does not 1837 + * grant access to the mount covering it. It is a generalization of the bind 1838 + * mount case in layout3_fs.hostfs.release_inodes that tests hidden mount points. 1839 + */ 1840 + TEST_F_FORK(layout1, covered_rule) 1841 + { 1842 + const struct rule layer1[] = { 1843 + { 1844 + .path = dir_s3d2, 1845 + .access = LANDLOCK_ACCESS_FS_READ_DIR, 1846 + }, 1847 + {}, 1848 + }; 1849 + int ruleset_fd; 1850 + 1851 + /* Unmount to simplify FIXTURE_TEARDOWN. */ 1852 + set_cap(_metadata, CAP_SYS_ADMIN); 1853 + ASSERT_EQ(0, umount(dir_s3d2)); 1854 + clear_cap(_metadata, CAP_SYS_ADMIN); 1855 + 1856 + /* Creates a ruleset with the future hidden directory. */ 1857 + ruleset_fd = 1858 + create_ruleset(_metadata, LANDLOCK_ACCESS_FS_READ_DIR, layer1); 1859 + ASSERT_LE(0, ruleset_fd); 1860 + 1861 + /* Covers with a new mount point. */ 1862 + set_cap(_metadata, CAP_SYS_ADMIN); 1863 + ASSERT_EQ(0, mount_opt(&mnt_tmp, dir_s3d2)); 1864 + clear_cap(_metadata, CAP_SYS_ADMIN); 1865 + 1866 + ASSERT_EQ(0, test_open(dir_s3d2, O_RDONLY)); 1867 + 1868 + enforce_ruleset(_metadata, ruleset_fd); 1869 + ASSERT_EQ(0, close(ruleset_fd)); 1870 + 1871 + /* Checks that access to the new mount point is denied. */ 1872 + ASSERT_EQ(EACCES, test_open(dir_s3d2, O_RDONLY)); 1873 + } 1874 + 1835 1875 enum relative_access { 1836 1876 REL_OPEN, 1837 1877 REL_CHDIR,