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 00B99606A31D for ; Tue, 20 Oct 2026 10:20: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=NYS5BFm2; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=hZfr9nuN; 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=NYS5BFm2; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=hZfr9nuN Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B62153EA60F for ; Tue, 20 Oct 2026 12:20:16 +0200 (CEST) Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (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 DA7703EA602 for ; Tue, 20 Oct 2026 12:16:36 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) (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-4.smtp.seeweb.it (Postfix) with ESMTPS id 5BBA91000939 for ; Tue, 20 Oct 2026 12:16:36 +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-out2.suse.de (Postfix) with ESMTPS id 189381F7A9; Tue, 20 Oct 2026 10:16:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1792491395; 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=DFibNCWoXr+/7MGAx3shKUS2W3kWM6yqZ5It7P7NrbQ=; b=NYS5BFm2EyfT0akusL4nbFwXgg9VrdLs+pV1rekf2tO0Sjv3wn4LxASDhdTYYHaKJfOC6t 9Jes/NbPOpnjWgNKqSRu5ybCl2Ri0z2NhbkwZ1aMLRCNr8OGGi6HY3UlIoIuc7n/UieErV Q8ZaNwG3lyg2gL1iXB7L17b0ogwOG3s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1792491395; 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=DFibNCWoXr+/7MGAx3shKUS2W3kWM6yqZ5It7P7NrbQ=; b=hZfr9nuNAWMtb/H6FiiJQwYgraJSr4XDkr2r6CStfTnDYSgubanslJsFQhexdOPeYYUi5p Py8BW5CqwLEnjZBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=NYS5BFm2; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=hZfr9nuN DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1792491395; 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=DFibNCWoXr+/7MGAx3shKUS2W3kWM6yqZ5It7P7NrbQ=; b=NYS5BFm2EyfT0akusL4nbFwXgg9VrdLs+pV1rekf2tO0Sjv3wn4LxASDhdTYYHaKJfOC6t 9Jes/NbPOpnjWgNKqSRu5ybCl2Ri0z2NhbkwZ1aMLRCNr8OGGi6HY3UlIoIuc7n/UieErV Q8ZaNwG3lyg2gL1iXB7L17b0ogwOG3s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1792491395; 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=DFibNCWoXr+/7MGAx3shKUS2W3kWM6yqZ5It7P7NrbQ=; b=hZfr9nuNAWMtb/H6FiiJQwYgraJSr4XDkr2r6CStfTnDYSgubanslJsFQhexdOPeYYUi5p Py8BW5CqwLEnjZBA== 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 DAD80136CC; 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:T15 (envelope-from ); Tue, 20 Oct 2026 10:16:34 +0000 From: Andrea Cervesato Date: Tue, 20 Oct 2026 12:16:43 +0200 X-Archived-By: MIME-Version: 1.0 Message-Id: <20261020-fchroot-v5-14-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=3063; i=andrea.cervesato@suse.com; s=20251210; h=from:subject:message-id; bh=9dxsFQWQry41oY5dAa/4LIPMDTmx0t7c7rswhR1jJRw=; b=JFCLvFptIa5lB41+rfFHpR4EpaLKOKEN+9R5Jn7psN1axQN/BRGEs0rsZ3lgU400rF8Nd00tn Lyl2vfR2KHgAToc6bCH3cBRZ/ss1GOokt6h8qNCA4CBK4fkCLx2el1z 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: 189381F7A9 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.de:dkim,suse.com:email,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-4.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v5 14/14] fchroot13: test failfs entry when chrooted 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 unprivileged fchroot() into failfs is refused when the process is already chrooted: moving the root of a chrooted task into failfs would allow it to escape its chroot via openat(fd, "..") with a pre-opened directory fd, so the kernel refuses the syscall with EPERM. Signed-off-by: Andrea Cervesato --- runtest/syscalls | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot13.c | 61 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/runtest/syscalls b/runtest/syscalls index bd3bbff4a..2bdb4a9a2 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -328,6 +328,7 @@ fchroot09 fchroot09 fchroot10 fchroot10 fchroot11 fchroot11 fchroot12 fchroot12 +fchroot13 fchroot13 fcntl01 fcntl01 fcntl01_64 fcntl01_64 diff --git a/testcases/kernel/syscalls/fchroot/.gitignore b/testcases/kernel/syscalls/fchroot/.gitignore index e8a6730ee..3e77e3762 100644 --- a/testcases/kernel/syscalls/fchroot/.gitignore +++ b/testcases/kernel/syscalls/fchroot/.gitignore @@ -11,3 +11,4 @@ fchroot09 fchroot10 fchroot11 fchroot12 +fchroot13 diff --git a/testcases/kernel/syscalls/fchroot/fchroot13.c b/testcases/kernel/syscalls/fchroot/fchroot13.c new file mode 100644 index 000000000..ea361ff6a --- /dev/null +++ b/testcases/kernel/syscalls/fchroot/fchroot13.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 SUSE LLC Andrea Cervesato + */ + +/*\ + * Test that unprivileged :manpage:`fchroot(2)` into failfs is refused + * when the process is already chrooted. + * + * The root directory is what confines ".." resolution and the failfs root + * can never be reached by walking up a real mount tree. Moving the root + * of a chrooted task into failfs would allow it to escape its chroot via + * :manpage:`openat(2)` with ".." and a pre-opened directory file descriptor, + * so the kernel refuses the syscall with ``EPERM``. + * + * Root is required to create the chroot jail before dropping to an + * unprivileged user in the forked child. + */ + +#define _GNU_SOURCE +#include +#include +#include "tst_test.h" +#include "lapi/fcntl.h" +#include "lapi/prctl.h" +#include "lapi/syscalls.h" + +#define JAILDIR "jail" + +static struct passwd *ltpuser; + +static void run(void) +{ + if (SAFE_FORK()) + return; + + SAFE_CHROOT(JAILDIR); + SAFE_CHDIR("/"); + + SAFE_SETRESUID(ltpuser->pw_uid, ltpuser->pw_uid, + ltpuser->pw_uid); + + SAFE_PRCTL(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); + + TST_EXP_FAIL(tst_syscall(__NR_fchroot, FD_FAILFS_ROOT, 0), + EPERM, "fchroot() from a chrooted process"); +} + +static void setup(void) +{ + ltpuser = SAFE_GETPWNAM("nobody"); + SAFE_MKDIR(JAILDIR, 0755); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .needs_tmpdir = 1, + .forks_child = 1, +}; -- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp