Skip to content

Commit abdf4ae

Browse files
Avineshacerv
authored andcommitted
setsockopt08: Handle EPERM from disabled compat xtables in userns
Since kernel commit ec1806a730a1 ("netfilter: x_tables: disable 32bit compat interface in user namespaces"), the compat xtables ABI returns EPERM when called from inside a non-init user namespace, regardless of privileges held there. Since the test isolates itself with tst_setup_netns(), it always hits this path on 32-bit/compat runs and can no longer reach the CVE-2021-22555 code path setsockopt08.c:139: TFAIL: setsockopt(3, IPPROTO_IP, IPT_SO_SET_REPLACE, 0xf7f0c800, 1): EPERM (1) So treat EPERM as TCONF instead of TFAIL. Signed-off-by: Avinesh Kumar <avinesh.kumar@suse.com> Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com> Link: https://lore.kernel.org/20260828095724.194900-1-avinesh.kumar@suse.com
1 parent 8d81c77 commit abdf4ae

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

testcases/kernel/syscalls/setsockopt/setsockopt08.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
* * the kernel will insert four bytes of padding
8383
* after the match and target entries each.
8484
* * sizeof(struct xt_entry_target) = 32
85+
*
86+
* Since kernel commit ec1806a730a1 ("netfilter: x_tables: disable
87+
* 32bit compat interface in user namespaces") in v7.2, the compat
88+
* xtables ABI is rejected with EPERM inside a non-init user namespace.
89+
* As this test runs isolated via tst_setup_netns(), it can no longer
90+
* reach the vulnerable code path on such kernels and reports TCONF
91+
* instead.
8592
*/
8693

8794
#include <netinet/in.h>
@@ -135,6 +142,11 @@ static void run(void)
135142
if (TST_RET == -1 && TST_ERR == ENOPROTOOPT)
136143
tst_brk(TCONF | TTERRNO, res_fmt_str, fd, buffer);
137144

145+
if (TST_RET == -1 && TST_ERR == EPERM && tst_is_compat_mode()) {
146+
tst_res(TINFO, "32bit compat xtables interface is disabled in user namespaces since commit ec1806a730a1");
147+
tst_brk(TCONF | TTERRNO, res_fmt_str, fd, buffer);
148+
}
149+
138150
result = (TST_RET == -1 && TST_ERR == EINVAL) ? TPASS : TFAIL;
139151
tst_res(result | TTERRNO, res_fmt_str, fd, buffer);
140152

@@ -163,6 +175,7 @@ static struct tst_test test = {
163175
},
164176
.tags = (const struct tst_tag[]) {
165177
{"linux-git", "b29c457a6511435960115c0f548c4360d5f4801d"},
178+
{"linux-git", "ec1806a730a1c0b3d68a7f9afe81514fb0dd7991"},
166179
{"CVE", "2021-22555"},
167180
{}
168181
}

0 commit comments

Comments
 (0)