Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A1A5606A319 for ; Tue, 20 Oct 2026 10:18:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=bbBVy23d; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ystqzFpL; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=bbBVy23d; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ystqzFpL Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4AEEA3EA611 for ; Tue, 20 Oct 2026 12:18:17 +0200 (CEST) Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id BD2E43EA603 for ; Tue, 20 Oct 2026 12:16:35 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 2E2F9200976 for ; Tue, 20 Oct 2026 12:16:35 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AB42B21DAC; Tue, 20 Oct 2026 10:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1792491394; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ujamfeVxS0lhBHNjWQUuSRcMErHuhmco95vrBY2U0nU=; b=bbBVy23d66z6L5w5mPKxtLe+81zJxCHqLx4PfmvlX0vYVvlalB2lkXkJkznxsKH+q2hHbJ bLyTctI3HZFb9zQlNQh6E0wOivood+2kVxNYOHtfoqVmBwtVB8VDAzgO1JItZdOMknoekL h+NNctyjZPRk2Pvfmn2PIT1jQCGqjQo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1792491394; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ujamfeVxS0lhBHNjWQUuSRcMErHuhmco95vrBY2U0nU=; b=ystqzFpLSFcW5TlErq+6C/gc5ozOyw/69LA9Ijl0jsEfYot2Pq8YQeLQ9ngDqImpfMPeDP YpPcpAZkP4efOACA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=bbBVy23d; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=ystqzFpL DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1792491394; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ujamfeVxS0lhBHNjWQUuSRcMErHuhmco95vrBY2U0nU=; b=bbBVy23d66z6L5w5mPKxtLe+81zJxCHqLx4PfmvlX0vYVvlalB2lkXkJkznxsKH+q2hHbJ bLyTctI3HZFb9zQlNQh6E0wOivood+2kVxNYOHtfoqVmBwtVB8VDAzgO1JItZdOMknoekL h+NNctyjZPRk2Pvfmn2PIT1jQCGqjQo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1792491394; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ujamfeVxS0lhBHNjWQUuSRcMErHuhmco95vrBY2U0nU=; b=ystqzFpLSFcW5TlErq+6C/gc5ozOyw/69LA9Ijl0jsEfYot2Pq8YQeLQ9ngDqImpfMPeDP YpPcpAZkP4efOACA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3E7AD136CC; Tue, 20 Oct 2026 10:16:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id B2PKGIA/12rCMgAAD6G6ig:T11 (envelope-from ); Tue, 20 Oct 2026 10:16:34 +0000 From: Andrea Cervesato Date: Tue, 20 Oct 2026 12:16:39 +0200 X-Archived-By: MIME-Version: 1.0 Message-Id: <20261020-fchroot-v5-10-63aa6faff503@suse.com> References: <20261020-fchroot-v5-0-63aa6faff503@suse.com> In-Reply-To: <20261020-fchroot-v5-0-63aa6faff503@suse.com> To: Linux Test Project X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1792491392; l=3361; i=andrea.cervesato@suse.com; s=20251210; h=from:subject:message-id; bh=gm2siPhuWmg7hZ4DKVeNFrcAa8dUZcQTuHT9ejIaR9c=; b=61BcJveRVPmH/WC47SQqUXcVAVWc4yTLN1aPSXk4+vovNHTJl4rE6f+crjAIhAmtuWk2ONL2L XOn9oHUqbNbDrdnZ+Ui4UsiQc+eVLVwLy6f8gHsdeYyIqe+SZ6Sdsot X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=zKY+6GCauOiuHNZ//d8PQ/UL4jFCTKbXrzXAOQSLevI= X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: AB42B21DAC X-Rspamd-Action: no action X-Spam-Level: X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+] X-Spam-Score: -4.51 X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Virus-Scanned: clamav-milter 1.0.9 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v5 10/14] fchroot09: test setns escape from failfs root X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "ltp" From: Andrea Cervesato Verify that entering failfs with fchroot() is hard to undo: a process inside counts as chrooted, and one way out is a pre-opened mount namespace fd. setns() into it resets both the root and the working directory. Signed-off-by: Andrea Cervesato --- runtest/syscalls | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot09.c | 68 +++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/runtest/syscalls b/runtest/syscalls index 24d9b1b4a..b4723fee4 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -324,6 +324,7 @@ fchroot05 fchroot05 fchroot06 fchroot06 fchroot07 fchroot07 fchroot08 fchroot08 +fchroot09 fchroot09 fcntl01 fcntl01 fcntl01_64 fcntl01_64 diff --git a/testcases/kernel/syscalls/fchroot/.gitignore b/testcases/kernel/syscalls/fchroot/.gitignore index 0a2510d8a..b577da61f 100644 --- a/testcases/kernel/syscalls/fchroot/.gitignore +++ b/testcases/kernel/syscalls/fchroot/.gitignore @@ -7,3 +7,4 @@ fchroot06 fchroot07 fchroot07_child fchroot08 +fchroot09 diff --git a/testcases/kernel/syscalls/fchroot/fchroot09.c b/testcases/kernel/syscalls/fchroot/fchroot09.c new file mode 100644 index 000000000..f4f0e1100 --- /dev/null +++ b/testcases/kernel/syscalls/fchroot/fchroot09.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 SUSE LLC Andrea Cervesato + */ + +/*\ + * Test that :manpage:`setns(2)` escapes the failfs root. + * + * Entering failfs with :manpage:`fchroot(2)` is hard to undo: a process + * inside counts as chrooted, so :manpage:`chroot(2)` and :manpage:`fchroot(2)` + * back out require ``CAP_SYS_CHROOT``. One way out is a pre-opened mount + * namespace file descriptor: :manpage:`setns(2)` into it resets both the + * root and the working directory. + * + * Root is required because entering failfs requires ``CAP_SYS_CHROOT`` and + * :manpage:`setns(2)` into the mount namespace requires ``CAP_SYS_ADMIN``. + * + * The test runs in a forked child so the root of the parent process is + * left untouched. + */ + +#define _GNU_SOURCE +#include +#include +#include "tst_test.h" +#include "lapi/fcntl.h" +#include "lapi/sched.h" +#include "lapi/setns.h" +#include "lapi/syscalls.h" + +static void run(void) +{ + if (SAFE_FORK()) + return; + + struct stat realroot, st; + int nsfd; + + SAFE_STAT("/", &realroot); + nsfd = SAFE_OPEN("/proc/self/ns/mnt", O_RDONLY); + + TST_EXP_PASS(tst_syscall(__NR_fchroot, FD_FAILFS_ROOT, 0), + "fchroot() with the FD_FAILFS_ROOT sentinel"); + + TST_EXP_FAIL2(open("/", O_PATH), EOPNOTSUPP, + "absolute lookup after entering failfs"); + + TST_EXP_PASS(setns(nsfd, CLONE_NEWNS), + "setns() back into the mount namespace"); + + SAFE_CLOSE(nsfd); + + SAFE_STAT("/", &st); + TST_EXP_EXPR(st.st_dev == realroot.st_dev && + st.st_ino == realroot.st_ino, + "root restored after setns()"); + + SAFE_STAT(".", &st); + TST_EXP_EXPR(st.st_dev == realroot.st_dev && + st.st_ino == realroot.st_ino, + "working directory restored after setns()"); +} + +static struct tst_test test = { + .test_all = run, + .needs_root = 1, + .forks_child = 1, +}; -- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp