From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx1.buffet.re (mx1.buffet.re [51.83.41.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36B1847A0B7; Thu, 11 Jun 2026 16:22:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.83.41.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781194924; cv=none; b=Kz2g4IzjElDVvQN0IRUH/SVGwXR/bkPtV6ji/z5efPTABj7+Ipp4MufbK1+ddziS0qYmUWQVXrDOEFPwFF19fLpJBqlA5GVxrw3rz36GW725T1InAaY1Q+zDh5r6NrZ488ALQ9rrl22qEJvebz6XTcl3KRSmnw9PySRueKL1wko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781194924; c=relaxed/simple; bh=6s9FQE/AqMeA9j0zY7JOimr29B5dqFvNXh9YRzIT/MY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WRD7R0O7MBzKQEdNugL7maQ/JZi3vrawFCk5DvjPzwQ10s2ARoelVL5JmQKeRgA2RwB1qtfsRBS1t0L8lbYwB2JhqX2auQtuUm3rl74VN235/hGUDB9FQX/U/gGDG7PS3BDF4D32iajVP4DPGwd/9w25vNIIGqx7jtr6b974RCI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=buffet.re; spf=pass smtp.mailfrom=buffet.re; dkim=pass (2048-bit key) header.d=buffet.re header.i=@buffet.re header.b=sp8qDmzK; arc=none smtp.client-ip=51.83.41.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=buffet.re Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=buffet.re Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=buffet.re header.i=@buffet.re header.b="sp8qDmzK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=buffet.re; s=mx1; t=1781194921; bh=6s9FQE/AqMeA9j0zY7JOimr29B5dqFvNXh9YRzIT/MY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sp8qDmzKjjeSD8w4/3c8ROGtoA/1jU1iq2wQjesYkSIWyGRwar4DQpRU01uQMabnY M60MFO0aActAUdrpugeEp5X5qwoaF5o13pXT5aQHARYGlxkbvlucDpSRqG5OZwMNMB 1tLE1BKI78opEWONFXtIUOqyseaLsoAPIRTIzEQdNzrKifSGZDJUADq/T0AEWwZVAO lrgDP/3SSb0i5lBeadMUI7ab1hVEaZmoQJo7xZQmJSJ5D7fdkGnzU1QabL/QrfowTx kydamWH8bkkgFjM+alPvrhYWSdIwtJtIoaEyoX4wcnXqZiVXJT0VwFFhTxIq1dlHGg orik+N5gYafQw== Received: from localhost.localdomain (unknown [10.0.1.3]) by mx1.buffet.re (Postfix) with ESMTPSA id 3D71A1253FC; Thu, 11 Jun 2026 18:22:01 +0200 (CEST) From: Matthieu Buffet To: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , =?UTF-8?q?G=C3=BCnther=20Noack?= Cc: linux-security-module@vger.kernel.org, Mikhail Ivanov , konstantin.meskhidze@huawei.com, Tingmao Wang , netdev@vger.kernel.org, Matthieu Buffet Subject: [PATCH v5 5/6] samples/landlock: Add sandboxer UDP access control Date: Thu, 11 Jun 2026 18:21:05 +0200 Message-ID: <20260611162107.49278-6-matthieu@buffet.re> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260611162107.49278-1-matthieu@buffet.re> References: <20260611162107.49278-1-matthieu@buffet.re> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add environment variables to control associated access rights: - LL_UDP_BIND - LL_UDP_CONNECT_SEND Each one takes a list of ports separated by colons, like other list options. Signed-off-by: Matthieu Buffet --- samples/landlock/sandboxer.c | 41 ++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/samples/landlock/sandboxer.c b/samples/landlock/sandboxer.c index 66e56ae275c6..f44db2857bbf 100644 --- a/samples/landlock/sandboxer.c +++ b/samples/landlock/sandboxer.c @@ -62,6 +62,8 @@ static inline int landlock_restrict_self(const int ruleset_fd, #define ENV_TCP_CONNECT_NAME "LL_TCP_CONNECT" #define ENV_SCOPED_NAME "LL_SCOPED" #define ENV_FORCE_LOG_NAME "LL_FORCE_LOG" +#define ENV_UDP_BIND_NAME "LL_UDP_BIND" +#define ENV_UDP_CONNECT_SEND_NAME "LL_UDP_CONNECT_SEND" #define ENV_DELIMITER ":" static int str2num(const char *numstr, __u64 *num_dst) @@ -301,7 +303,7 @@ static bool check_ruleset_scope(const char *const env_var, /* clang-format on */ -#define LANDLOCK_ABI_LAST 9 +#define LANDLOCK_ABI_LAST 10 #define XSTR(s) #s #define STR(s) XSTR(s) @@ -324,6 +326,11 @@ static const char help[] = "means an empty list):\n" "* " ENV_TCP_BIND_NAME ": ports allowed to bind (server)\n" "* " ENV_TCP_CONNECT_NAME ": ports allowed to connect (client)\n" + "* " ENV_UDP_BIND_NAME ": local UDP ports allowed to bind (server: " + "prepare to receive on port / client: set as source port)\n" + "* " ENV_UDP_CONNECT_SEND_NAME ": remote UDP ports allowed to connect " + "or send to (client: use as destination port / server: receive only from it)\n" + "(caution: sending requires being able to bind to a local source port)\n" "* " ENV_SCOPED_NAME ": actions denied on the outside of the landlock domain\n" " - \"a\" to restrict opening abstract unix sockets\n" " - \"s\" to restrict sending signals\n" @@ -336,6 +343,7 @@ static const char help[] = ENV_FS_RW_NAME "=\"/dev/null:/dev/full:/dev/zero:/dev/pts:/tmp\" " ENV_TCP_BIND_NAME "=\"9418\" " ENV_TCP_CONNECT_NAME "=\"80:443\" " + ENV_UDP_CONNECT_SEND_NAME "=\"53\" " ENV_SCOPED_NAME "=\"a:s\" " "%1$s bash -i\n" "\n" @@ -356,7 +364,9 @@ int main(const int argc, char *const argv[], char *const *const envp) struct landlock_ruleset_attr ruleset_attr = { .handled_access_fs = access_fs_rw, .handled_access_net = LANDLOCK_ACCESS_NET_BIND_TCP | - LANDLOCK_ACCESS_NET_CONNECT_TCP, + LANDLOCK_ACCESS_NET_CONNECT_TCP | + LANDLOCK_ACCESS_NET_BIND_UDP | + LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP, .scoped = LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET | LANDLOCK_SCOPE_SIGNAL, }; @@ -444,6 +454,13 @@ int main(const int argc, char *const argv[], char *const *const envp) /* Removes LANDLOCK_ACCESS_FS_RESOLVE_UNIX for ABI < 9 */ ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_RESOLVE_UNIX; + __attribute__((fallthrough)); + case 9: + /* Removes UDP support for ABI < 10 */ + ruleset_attr.handled_access_net &= + ~(LANDLOCK_ACCESS_NET_BIND_UDP | + LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP); + /* Must be printed for any ABI < LANDLOCK_ABI_LAST. */ fprintf(stderr, "Hint: You should update the running kernel " @@ -475,6 +492,18 @@ int main(const int argc, char *const argv[], char *const *const envp) ruleset_attr.handled_access_net &= ~LANDLOCK_ACCESS_NET_CONNECT_TCP; } + /* Removes UDP bind access control if not supported by a user. */ + env_port_name = getenv(ENV_UDP_BIND_NAME); + if (!env_port_name) { + ruleset_attr.handled_access_net &= + ~LANDLOCK_ACCESS_NET_BIND_UDP; + } + /* Removes UDP connect/send access control if not supported by a user. */ + env_port_name = getenv(ENV_UDP_CONNECT_SEND_NAME); + if (!env_port_name) { + ruleset_attr.handled_access_net &= + ~LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP; + } if (check_ruleset_scope(ENV_SCOPED_NAME, &ruleset_attr)) return 1; @@ -519,6 +548,14 @@ int main(const int argc, char *const argv[], char *const *const envp) LANDLOCK_ACCESS_NET_CONNECT_TCP)) { goto err_close_ruleset; } + if (populate_ruleset_net(ENV_UDP_BIND_NAME, ruleset_fd, + LANDLOCK_ACCESS_NET_BIND_UDP)) { + goto err_close_ruleset; + } + if (populate_ruleset_net(ENV_UDP_CONNECT_SEND_NAME, ruleset_fd, + LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP)) { + goto err_close_ruleset; + } if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { perror("Failed to restrict privileges"); -- 2.47.3