From patchwork Fri Mar 28 14:24:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2066493 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.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=1Qs5HQQq; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=IKJBHyBt; 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=1Qs5HQQq; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=IKJBHyBt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 legolas.ozlabs.org (Postfix) with ESMTPS id 4ZPN9x5j9dz1yGC for ; Sat, 29 Mar 2025 01:26:13 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E12D33CA45D for ; Fri, 28 Mar 2025 15:26:22 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (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 552413CA464 for ; Fri, 28 Mar 2025 15:25:46 +0100 (CET) Authentication-Results: in-3.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=195.135.223.130; helo=smtp-out1.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) 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-3.smtp.seeweb.it (Postfix) with ESMTPS id 89F261A00EC2 for ; Fri, 28 Mar 2025 15:25:46 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [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 55F9C211D6; Fri, 28 Mar 2025 14:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1743171942; 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=ZjdbQy4TBJj3L6uH2kX2fThdGYDTY/yThCTiuGTCR5U=; b=1Qs5HQQqHRaiII+r2mVDtEEWKcltdJtAIKSnqn5jiARCucGGkWTt2Oj7TNrMaLG/EENKZn 049bDAhEZeh6ZlXTMGiVcJjmVFu8soVxQ0dRgeXF3aImNDklb4D2qhtFv2LNvJ7pz6cmrK Fx1h0XLz+c5+T3G9yIKxbBho1KyryNQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1743171942; 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=ZjdbQy4TBJj3L6uH2kX2fThdGYDTY/yThCTiuGTCR5U=; b=IKJBHyBt+Uwmk1VsfG9/pIbpxC1hoEzw8D4bDUL5ytLIXL8h7K1jhi4by+iBwtAd5xcEMd q8VPddDuIzYrXXCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1743171942; 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=ZjdbQy4TBJj3L6uH2kX2fThdGYDTY/yThCTiuGTCR5U=; b=1Qs5HQQqHRaiII+r2mVDtEEWKcltdJtAIKSnqn5jiARCucGGkWTt2Oj7TNrMaLG/EENKZn 049bDAhEZeh6ZlXTMGiVcJjmVFu8soVxQ0dRgeXF3aImNDklb4D2qhtFv2LNvJ7pz6cmrK Fx1h0XLz+c5+T3G9yIKxbBho1KyryNQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1743171942; 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=ZjdbQy4TBJj3L6uH2kX2fThdGYDTY/yThCTiuGTCR5U=; b=IKJBHyBt+Uwmk1VsfG9/pIbpxC1hoEzw8D4bDUL5ytLIXL8h7K1jhi4by+iBwtAd5xcEMd q8VPddDuIzYrXXCg== 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 35991139D4; Fri, 28 Mar 2025 14:25:42 +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 APhlC2ax5mfndgAAD6G6ig (envelope-from ); Fri, 28 Mar 2025 14:25:42 +0000 From: Andrea Cervesato Date: Fri, 28 Mar 2025 15:24:53 +0100 MIME-Version: 1.0 Message-Id: <20250328-landlock_unix_socket-v3-1-e2643f65b25e@suse.com> References: <20250328-landlock_unix_socket-v3-0-e2643f65b25e@suse.com> In-Reply-To: <20250328-landlock_unix_socket-v3-0-e2643f65b25e@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1743171941; l=1824; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=djlfNKJeXRBdXG8bxC1T3GXTH5Ws1RpcGTK7pGzPp9U=; b=1QPZ7l4o5uJ7PDerbi/uEytJgFCxi1tJoZEncBQgO4gGaEx6rOHP4jLwHkffs3RrI6+czoGd1 smLvJUhqFzRCrNrwjtQelt7XeOtjShIZyH70pcPOVVpi0owg8++lmt5 X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Spam-Level: X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email, suse.com:mid, imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -4.30 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-3.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-3.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v3 1/4] Add landlock ABI v6 fallback X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato The new ABI v6 is defining the following IPC scoped operations: * LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET * LANDLOCK_SCOPE_SIGNAL Reviewed-by: Cyril Hrubis Signed-off-by: Andrea Cervesato --- include/lapi/landlock.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/include/lapi/landlock.h b/include/lapi/landlock.h index b3c8c548e661680541cdf6e4a8fb68a3f5029fec..e579500ec26cdc0a568620bc35386f3d2b68952e 100644 --- a/include/lapi/landlock.h +++ b/include/lapi/landlock.h @@ -15,15 +15,19 @@ #include "lapi/syscalls.h" -struct tst_landlock_ruleset_attr_abi1 -{ +struct tst_landlock_ruleset_attr_abi1 { uint64_t handled_access_fs; }; -struct tst_landlock_ruleset_attr_abi4 -{ +struct tst_landlock_ruleset_attr_abi4 { + uint64_t handled_access_fs; + uint64_t handled_access_net; +}; + +struct tst_landlock_ruleset_attr_abi6 { uint64_t handled_access_fs; uint64_t handled_access_net; + uint64_t scoped; }; #ifndef HAVE_STRUCT_LANDLOCK_PATH_BENEATH_ATTR @@ -43,8 +47,7 @@ struct landlock_path_beneath_attr #endif #ifndef HAVE_STRUCT_LANDLOCK_NET_PORT_ATTR -struct landlock_net_port_attr -{ +struct landlock_net_port_attr { uint64_t allowed_access; uint64_t port; }; @@ -126,6 +129,14 @@ struct landlock_net_port_attr # define LANDLOCK_ACCESS_NET_CONNECT_TCP (1ULL << 1) #endif +#ifndef LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET +# define LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET (1ULL << 0) +#endif + +#ifndef LANDLOCK_SCOPE_SIGNAL +# define LANDLOCK_SCOPE_SIGNAL (1ULL << 1) +#endif + static inline int safe_landlock_create_ruleset(const char *file, const int lineno, const void *attr, size_t size , uint32_t flags) { From patchwork Fri Mar 28 14:24:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2066492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.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=YdZwdSKP; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=uijry9Gf; 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=YdZwdSKP; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=uijry9Gf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZPN9b3vlFz1yGC for ; Sat, 29 Mar 2025 01:25:55 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B4A543CA2DD for ; Fri, 28 Mar 2025 15:26:04 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (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 DB4303C023C for ; Fri, 28 Mar 2025 15:25:43 +0100 (CET) Authentication-Results: in-6.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=195.135.223.131; helo=smtp-out2.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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-6.smtp.seeweb.it (Postfix) with ESMTPS id 2936F1400518 for ; Fri, 28 Mar 2025 15:25:42 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [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 8449C1F38F; Fri, 28 Mar 2025 14:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1743171942; 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=k4/6NmN12zMhARy09p/3zhEqby9RGArkleaXIvP/l5g=; b=YdZwdSKPBgsgNBGtWJ/wf07k8FJOVBDNda0eSUDteayw71GT3hUQ6l9T3JTZCaOHy33DNz yzxY1U2VJWf70fJST+DJNIg/K2ovFjduTw6khDgk7kPN9iVNP+TAkgAu28FhHIRKyH9JQF devGeawWhyfiio0GGHOh5MRVHBuA70o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1743171942; 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=k4/6NmN12zMhARy09p/3zhEqby9RGArkleaXIvP/l5g=; b=uijry9Gfbri73LjlsNu5CSuzl16yJEIZXCJN2w7JtC618CzmaInNaYVQwbTts/T6smgycj Vs6n7DBn/GREUVCA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1743171942; 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=k4/6NmN12zMhARy09p/3zhEqby9RGArkleaXIvP/l5g=; b=YdZwdSKPBgsgNBGtWJ/wf07k8FJOVBDNda0eSUDteayw71GT3hUQ6l9T3JTZCaOHy33DNz yzxY1U2VJWf70fJST+DJNIg/K2ovFjduTw6khDgk7kPN9iVNP+TAkgAu28FhHIRKyH9JQF devGeawWhyfiio0GGHOh5MRVHBuA70o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1743171942; 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=k4/6NmN12zMhARy09p/3zhEqby9RGArkleaXIvP/l5g=; b=uijry9Gfbri73LjlsNu5CSuzl16yJEIZXCJN2w7JtC618CzmaInNaYVQwbTts/T6smgycj Vs6n7DBn/GREUVCA== 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 5F9DE13927; Fri, 28 Mar 2025 14:25:42 +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 SAO4FWax5mfndgAAD6G6ig (envelope-from ); Fri, 28 Mar 2025 14:25:42 +0000 From: Andrea Cervesato Date: Fri, 28 Mar 2025 15:24:54 +0100 MIME-Version: 1.0 Message-Id: <20250328-landlock_unix_socket-v3-2-e2643f65b25e@suse.com> References: <20250328-landlock_unix_socket-v3-0-e2643f65b25e@suse.com> In-Reply-To: <20250328-landlock_unix_socket-v3-0-e2643f65b25e@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1743171941; l=2317; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=uDQWYCSUB2odNfq6v5J8I71qWSjXqr/wEcMg55NMTaM=; b=ssUBF0NovddFTivseIImzziex3Mzr6iqwqWhjS4UbeAGRvyaxnH6jy1gMkmgp+ifSSPne2TFw m8xQao5bFEjCkzD9PGK7N5ky0RXZNyRfcromyDUgt2FX+ZAUlrcoOfN X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Spam-Level: X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, suse.com:email, suse.com:mid] X-Spam-Score: -4.30 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v3 2/4] landlock02: support landlock ABI v6 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Reviewed-by: Cyril Hrubis Signed-off-by: Andrea Cervesato --- testcases/kernel/syscalls/landlock/landlock02.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/testcases/kernel/syscalls/landlock/landlock02.c b/testcases/kernel/syscalls/landlock/landlock02.c index 60010f554b001156f3feb30283bb5c22a5fea1fc..37dc72d32c633a2f249c5a9ef879b6d288a63259 100644 --- a/testcases/kernel/syscalls/landlock/landlock02.c +++ b/testcases/kernel/syscalls/landlock/landlock02.c @@ -20,6 +20,7 @@ static struct tst_landlock_ruleset_attr_abi1 *attr_abi1; static struct tst_landlock_ruleset_attr_abi4 *attr_abi4; +static struct tst_landlock_ruleset_attr_abi6 *attr_abi6; static struct landlock_path_beneath_attr *path_beneath_attr; static struct landlock_path_beneath_attr *rule_null; static struct landlock_net_port_attr *net_port_attr; @@ -144,15 +145,19 @@ static void setup(void) { abi_current = verify_landlock_is_enabled(); - attr_abi1->handled_access_fs = - attr_abi4->handled_access_fs = LANDLOCK_ACCESS_FS_EXECUTE; + attr_abi1->handled_access_fs = LANDLOCK_ACCESS_FS_EXECUTE; + attr_abi4->handled_access_fs = LANDLOCK_ACCESS_FS_EXECUTE; + attr_abi6->handled_access_fs = LANDLOCK_ACCESS_FS_EXECUTE; if (abi_current < 4) { ruleset_fd = TST_EXP_FD_SILENT(tst_syscall(__NR_landlock_create_ruleset, attr_abi1, sizeof(struct tst_landlock_ruleset_attr_abi1), 0)); - } else { + } else if (abi_current < 6) { ruleset_fd = TST_EXP_FD_SILENT(tst_syscall(__NR_landlock_create_ruleset, attr_abi4, sizeof(struct tst_landlock_ruleset_attr_abi4), 0)); + } else { + ruleset_fd = TST_EXP_FD_SILENT(tst_syscall(__NR_landlock_create_ruleset, + attr_abi6, sizeof(struct tst_landlock_ruleset_attr_abi6), 0)); } } @@ -171,6 +176,7 @@ static struct tst_test test = { .bufs = (struct tst_buffers []) { {&attr_abi1, .size = sizeof(struct tst_landlock_ruleset_attr_abi1)}, {&attr_abi4, .size = sizeof(struct tst_landlock_ruleset_attr_abi4)}, + {&attr_abi6, .size = sizeof(struct tst_landlock_ruleset_attr_abi6)}, {&path_beneath_attr, .size = sizeof(struct landlock_path_beneath_attr)}, {&net_port_attr, .size = sizeof(struct landlock_net_port_attr)}, {}, From patchwork Fri Mar 28 14:24:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2066496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.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=G9eNiYp8; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=f/69i9KL; 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=G9eNiYp8; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=f/69i9KL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZPNBl4LCNz1yGC for ; Sat, 29 Mar 2025 01:26:55 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AB2113CA2DD for ; Fri, 28 Mar 2025 15:27:04 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (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 0621F3CA2DD for ; Fri, 28 Mar 2025 15:25:51 +0100 (CET) Authentication-Results: in-6.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=2a07:de40:b251:101:10:150:64:1; helo=smtp-out1.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) (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-6.smtp.seeweb.it (Postfix) with ESMTPS id 737C81400192 for ; Fri, 28 Mar 2025 15:25:50 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [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 ADF4E211DD; Fri, 28 Mar 2025 14:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1743171942; 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=zeRc0bYR12FWdpoWtOznDwSsfkmtuAmNa5U3aJs8iSE=; b=G9eNiYp8hD7n+BMDeF6haRfH3pIfy3FiyhkMBoBvrkwKbILw59OwNyZYmerhagMqAplYjB MQDIof90KNQ1cXwAlH2gjyQvo/BNf33+X27rFu38+5diuZX/Dc87whJtBXjFoR+GXZcT0c DXH10Py8+xCpuhfMpC1S86Igt1V6fuA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1743171942; 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=zeRc0bYR12FWdpoWtOznDwSsfkmtuAmNa5U3aJs8iSE=; b=f/69i9KLWVuzzEaztPaGRssKqpLIBiBsWDTNApY63waEwWQFaaVTQcwFY/jwTFZwl/JoC+ 3pHztAppfUH3wFAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1743171942; 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=zeRc0bYR12FWdpoWtOznDwSsfkmtuAmNa5U3aJs8iSE=; b=G9eNiYp8hD7n+BMDeF6haRfH3pIfy3FiyhkMBoBvrkwKbILw59OwNyZYmerhagMqAplYjB MQDIof90KNQ1cXwAlH2gjyQvo/BNf33+X27rFu38+5diuZX/Dc87whJtBXjFoR+GXZcT0c DXH10Py8+xCpuhfMpC1S86Igt1V6fuA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1743171942; 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=zeRc0bYR12FWdpoWtOznDwSsfkmtuAmNa5U3aJs8iSE=; b=f/69i9KLWVuzzEaztPaGRssKqpLIBiBsWDTNApY63waEwWQFaaVTQcwFY/jwTFZwl/JoC+ 3pHztAppfUH3wFAw== 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 8BDD6139D4; Fri, 28 Mar 2025 14:25:42 +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 iD+GIGax5mfndgAAD6G6ig (envelope-from ); Fri, 28 Mar 2025 14:25:42 +0000 From: Andrea Cervesato Date: Fri, 28 Mar 2025 15:24:55 +0100 MIME-Version: 1.0 Message-Id: <20250328-landlock_unix_socket-v3-3-e2643f65b25e@suse.com> References: <20250328-landlock_unix_socket-v3-0-e2643f65b25e@suse.com> In-Reply-To: <20250328-landlock_unix_socket-v3-0-e2643f65b25e@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1743171941; l=5609; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=WFpyCov6OfGomS+hBh5rafP1Lht5D9vv6oW8PUfR7Zw=; b=Vdbi/P0YGnH73snYvmX9f4JVvncloqEUI9UrF/8M/scmB48/2q7jgf3y8z/2iuC/zEkYNGSlk OvjEjotPCwECwtahMRE+hFOauhTWr96sxWQYOixZrqciBnWFD1RlY8D X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, suse.com:mid, suse.com:email] X-Spam-Level: X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v3 3/4] landlock: add landlock09 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Create landlock09 test in order to verify that sandboxed processes enforced with LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET rule can't connect to any UNIX socket from non-sandboxed processes. Reviewed-by: Cyril Hrubis Signed-off-by: Andrea Cervesato --- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/landlock09.c | 131 +++++++++++++++++++++ .../kernel/syscalls/landlock/landlock_common.h | 11 ++ 4 files changed, 144 insertions(+) diff --git a/runtest/syscalls b/runtest/syscalls index 05b3e0d376fae3adf1eb29c22c0b83fa49eee56f..e3ed1738922a954493b56240be12cc40de691b6e 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -710,6 +710,7 @@ landlock05 landlock05 landlock06 landlock06 landlock07 landlock07 landlock08 landlock08 +landlock09 landlock09 lchown01 lchown01 lchown01_16 lchown01_16 diff --git a/testcases/kernel/syscalls/landlock/.gitignore b/testcases/kernel/syscalls/landlock/.gitignore index fc7317394948c4ac20cd14c3cd7ba7a47282b2bf..cda8d871e051ec88abba4634a2bcda4b10470d9f 100644 --- a/testcases/kernel/syscalls/landlock/.gitignore +++ b/testcases/kernel/syscalls/landlock/.gitignore @@ -7,3 +7,4 @@ landlock05 landlock06 landlock07 landlock08 +landlock09 diff --git a/testcases/kernel/syscalls/landlock/landlock09.c b/testcases/kernel/syscalls/landlock/landlock09.c new file mode 100644 index 0000000000000000000000000000000000000000..2e7f0021299152a1dbd0d7d7594487f551f04a24 --- /dev/null +++ b/testcases/kernel/syscalls/landlock/landlock09.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2025 SUSE LLC Andrea Cervesato + */ + +/*\ + * Verify that landlock's LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET rule reject any + * connect() coming from a client on a different server domain, but accept any + * connection. + */ + +#include +#include "tst_test.h" +#include "landlock_common.h" + +#define SOCKET_NAME "test.sock" +#define ABSTRACT_SOCKET_NAME "\0"SOCKET_NAME +#define SOCKET_LENGTH (offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_NAME) + 1) + +enum { + DOMAIN_CLIENT = 0, + DOMAIN_SERVER, + DOMAIN_BOTH, +}; + +static struct tst_landlock_ruleset_attr_abi6 *ruleset_attr; + +static void scoped_sandbox(const char *from) +{ + tst_res(TINFO, "Enforcing rule LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET on %s", from); + + ruleset_attr->scoped = LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET; + apply_landlock_scoped_layer(ruleset_attr, sizeof(*ruleset_attr)); +} + +static void run_client(void) +{ + if (tst_variant == DOMAIN_CLIENT) + scoped_sandbox("client"); + + int sendsock; + struct sockaddr_un addr = { + .sun_family = AF_UNIX, + .sun_path = ABSTRACT_SOCKET_NAME, + }; + + TST_CHECKPOINT_WAIT(0); + + tst_res(TINFO, "Connecting to UNIX socket"); + + sendsock = SAFE_SOCKET(AF_UNIX, SOCK_STREAM, 0); + + if (tst_variant != DOMAIN_CLIENT) + TST_EXP_PASS(connect(sendsock, (struct sockaddr *)&addr, SOCKET_LENGTH)); + else + TST_EXP_FAIL(connect(sendsock, (struct sockaddr *)&addr, SOCKET_LENGTH), EPERM); + + SAFE_CLOSE(sendsock); + + TST_CHECKPOINT_WAKE(0); +} + +static void run_server(void) +{ + if (tst_variant == DOMAIN_SERVER) + scoped_sandbox("server"); + + int recvsock; + struct sockaddr_un addr = { + .sun_family = AF_UNIX, + .sun_path = ABSTRACT_SOCKET_NAME, + }; + + recvsock = SAFE_SOCKET(AF_UNIX, SOCK_STREAM, 0); + + SAFE_BIND(recvsock, (struct sockaddr *)&addr, SOCKET_LENGTH); + SAFE_LISTEN(recvsock, 5); + + tst_res(TINFO, "Listening on UNIX socket"); + + TST_CHECKPOINT_WAKE_AND_WAIT(0); + + SAFE_CLOSE(recvsock); +} + +static void run(void) +{ + /* isolate test inside a process so we won't stack too many + * layers (-E2BIG) when there are multiple test's iterations + */ + if (SAFE_FORK()) + return; + + if (tst_variant == DOMAIN_BOTH) + scoped_sandbox("server and client"); + + if (!SAFE_FORK()) { + run_client(); + exit(0); + } + + run_server(); + + tst_reap_children(); +} + +static void setup(void) +{ + int abi; + + abi = verify_landlock_is_enabled(); + if (abi < 6) + tst_brk(TCONF, "LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET is unsupported on ABI < 6"); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, + .forks_child = 1, + .needs_checkpoints = 1, + .test_variants = 3, + .bufs = (struct tst_buffers []) { + {&ruleset_attr, .size = sizeof(struct tst_landlock_ruleset_attr_abi6)}, + {}, + }, + .caps = (struct tst_cap []) { + TST_CAP(TST_CAP_REQ, CAP_SYS_ADMIN), + {} + }, +}; diff --git a/testcases/kernel/syscalls/landlock/landlock_common.h b/testcases/kernel/syscalls/landlock/landlock_common.h index 4aa11b7d2ad46915cd1ce1592bdaa2fb6ad77628..8857745d6f1c1c30fc914924b8d0da381b36059f 100644 --- a/testcases/kernel/syscalls/landlock/landlock_common.h +++ b/testcases/kernel/syscalls/landlock/landlock_common.h @@ -115,6 +115,17 @@ static inline void apply_landlock_net_layer( SAFE_CLOSE(ruleset_fd); } +static inline void apply_landlock_scoped_layer( + void *ruleset_attr, size_t attr_size) +{ + int ruleset_fd; + + ruleset_fd = SAFE_LANDLOCK_CREATE_RULESET(ruleset_attr, attr_size, 0); + enforce_ruleset(ruleset_fd); + + SAFE_CLOSE(ruleset_fd); +} + static inline in_port_t getsocket_port(struct socket_data *socket, const int addr_family) { From patchwork Fri Mar 28 14:24:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2066495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.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=tgyFyq9R; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AGMSHUdy; 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=tgyFyq9R; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AGMSHUdy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (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 legolas.ozlabs.org (Postfix) with ESMTPS id 4ZPNBP2kFMz1yHM for ; Sat, 29 Mar 2025 01:26:37 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 54C6A3CA443 for ; Fri, 28 Mar 2025 15:26:46 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 55D3C3CA443 for ; Fri, 28 Mar 2025 15:25:48 +0100 (CET) Authentication-Results: in-2.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=2a07:de40:b251:101:10:150:64:2; helo=smtp-out2.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) 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-2.smtp.seeweb.it (Postfix) with ESMTPS id A3393600D82 for ; Fri, 28 Mar 2025 15:25:47 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [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 DAB031F390; Fri, 28 Mar 2025 14:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1743171942; 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=oHNCDAloQAG/ZEzjTH8WT0ktCWEY4z2OwQntv1iszCU=; b=tgyFyq9RHd9RrbbKcy9ZJhjm4RlNUl7TFsXA2sPrmb504vc0yc2U/ei2PfuO8GZDD/66bn 2Jqv0VeEQ8PoKF+NMNr5eDTF7Kw1qt2RNNIoSQ7QaSPmRZe1g34XUxhIdND0Ykl2nv5Sv4 JdsarGv5Bt5ItVr0gob54NZ6BwBAIQY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1743171942; 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=oHNCDAloQAG/ZEzjTH8WT0ktCWEY4z2OwQntv1iszCU=; b=AGMSHUdyba6G4kri38wKKwMK/Gwa4s41eh1AkqouRoA6Lx6Gu4dtf0YXE8Y+6/Px+A/w/A 0YBOkwDgolei14Cw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1743171942; 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=oHNCDAloQAG/ZEzjTH8WT0ktCWEY4z2OwQntv1iszCU=; b=tgyFyq9RHd9RrbbKcy9ZJhjm4RlNUl7TFsXA2sPrmb504vc0yc2U/ei2PfuO8GZDD/66bn 2Jqv0VeEQ8PoKF+NMNr5eDTF7Kw1qt2RNNIoSQ7QaSPmRZe1g34XUxhIdND0Ykl2nv5Sv4 JdsarGv5Bt5ItVr0gob54NZ6BwBAIQY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1743171942; 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=oHNCDAloQAG/ZEzjTH8WT0ktCWEY4z2OwQntv1iszCU=; b=AGMSHUdyba6G4kri38wKKwMK/Gwa4s41eh1AkqouRoA6Lx6Gu4dtf0YXE8Y+6/Px+A/w/A 0YBOkwDgolei14Cw== 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 B981A13927; Fri, 28 Mar 2025 14:25:42 +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 mBSlK2ax5mfndgAAD6G6ig (envelope-from ); Fri, 28 Mar 2025 14:25:42 +0000 From: Andrea Cervesato Date: Fri, 28 Mar 2025 15:24:56 +0100 MIME-Version: 1.0 Message-Id: <20250328-landlock_unix_socket-v3-4-e2643f65b25e@suse.com> References: <20250328-landlock_unix_socket-v3-0-e2643f65b25e@suse.com> In-Reply-To: <20250328-landlock_unix_socket-v3-0-e2643f65b25e@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1743171941; l=4142; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=JKjoLBz5m6+jhGN1xoHvt2eQyGvIOTAq/UaEOS06fL4=; b=js4oKx92L/H2ObOATrpjOzbbvnwhtfa65FbYegDKTRX2gQq7iG01oGFxlDOfSGe/Nacei06lv ME5xffzU/5dBQYsbRvquy7pbjXChd6AUDbRZ0lxZ3g3RUbN4G0prJ7O X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Spam-Level: X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, suse.com:email, suse.com:mid] X-Spam-Score: -4.30 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-2.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-2.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v3 4/4] landlock: add landlock10 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Verify that landlock's LANDLOCK_SCOPE_SIGNAL rule rejects any signal coming from a process on a different domain, but accept signals from processes in the same domain. Reviewed-by: Cyril Hrubis Signed-off-by: Andrea Cervesato --- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/landlock10.c | 108 ++++++++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/runtest/syscalls b/runtest/syscalls index e3ed1738922a954493b56240be12cc40de691b6e..de7aacbba4a082df8d3d1c5228b6d5b6e7370c78 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -711,6 +711,7 @@ landlock06 landlock06 landlock07 landlock07 landlock08 landlock08 landlock09 landlock09 +landlock10 landlock10 lchown01 lchown01 lchown01_16 lchown01_16 diff --git a/testcases/kernel/syscalls/landlock/.gitignore b/testcases/kernel/syscalls/landlock/.gitignore index cda8d871e051ec88abba4634a2bcda4b10470d9f..8c88803df4580605da800c414ada62994b35d268 100644 --- a/testcases/kernel/syscalls/landlock/.gitignore +++ b/testcases/kernel/syscalls/landlock/.gitignore @@ -8,3 +8,4 @@ landlock06 landlock07 landlock08 landlock09 +landlock10 diff --git a/testcases/kernel/syscalls/landlock/landlock10.c b/testcases/kernel/syscalls/landlock/landlock10.c new file mode 100644 index 0000000000000000000000000000000000000000..a29e3bca82fe813e9e2dbec5f1f0f42db9ebf367 --- /dev/null +++ b/testcases/kernel/syscalls/landlock/landlock10.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2025 SUSE LLC Andrea Cervesato + */ + +/*\ + * Verify that landlock's LANDLOCK_SCOPE_SIGNAL rule rejects any signal coming + * from a process on a different domain, but accept signals from processes in + * the same domain. + */ + +#include "tst_test.h" +#include "landlock_common.h" + +static struct tst_landlock_ruleset_attr_abi6 *ruleset_attr; + +enum { + DOMAIN_PAUSED = 0, + DOMAIN_KILLER, + DOMAIN_BOTH, +}; + +static void scoped_sandbox(const char *from) +{ + tst_res(TINFO, "Enforcing rule LANDLOCK_SCOPE_SIGNAL for %s process", from); + + ruleset_attr->scoped = LANDLOCK_SCOPE_SIGNAL; + apply_landlock_scoped_layer(ruleset_attr, sizeof(*ruleset_attr)); +} + +static void run(void) +{ + /* isolate test inside a process so we won't stack too many + * layers (-E2BIG) when there are multiple test's iterations + */ + if (SAFE_FORK()) + return; + + if (tst_variant == DOMAIN_BOTH) + scoped_sandbox("paused and killer"); + + pid_t paused_pid; + pid_t killer_pid; + + paused_pid = SAFE_FORK(); + if (!paused_pid) { + if (tst_variant == DOMAIN_PAUSED) + scoped_sandbox("paused"); + + TST_CHECKPOINT_WAKE(0); + pause(); + exit(0); + } + + TST_CHECKPOINT_WAIT(0); + TST_PROCESS_STATE_WAIT(paused_pid, 'S', 10000); + + killer_pid = SAFE_FORK(); + if (!killer_pid) { + if (tst_variant == DOMAIN_KILLER) + scoped_sandbox("killer"); + + TST_CHECKPOINT_WAKE(0); + + if (tst_variant == DOMAIN_KILLER) + TST_EXP_FAIL(kill(paused_pid, SIGKILL), EPERM); + else + TST_EXP_PASS(kill(paused_pid, SIGKILL)); + + exit(0); + } + + TST_CHECKPOINT_WAIT(0); + SAFE_WAITPID(killer_pid, NULL, 0); + + if (kill(paused_pid, SIGKILL) == -1) { + if (errno != ESRCH) + tst_brk(TBROK | TERRNO, "kill(%u, SIGKILL) error", paused_pid); + } + + SAFE_WAITPID(paused_pid, NULL, 0); +} + +static void setup(void) +{ + int abi; + + abi = verify_landlock_is_enabled(); + if (abi < 6) + tst_brk(TCONF, "LANDLOCK_SCOPE_SIGNAL is unsupported on ABI < 6"); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, + .forks_child = 1, + .needs_checkpoints = 1, + .test_variants = 3, + .bufs = (struct tst_buffers []) { + {&ruleset_attr, .size = sizeof(struct tst_landlock_ruleset_attr_abi6)}, + {}, + }, + .caps = (struct tst_cap []) { + TST_CAP(TST_CAP_REQ, CAP_SYS_ADMIN), + {} + }, +};