From nobody Fri Dec 19 19:19:20 2025 Received: from smtp-1909.mail.infomaniak.ch (smtp-1909.mail.infomaniak.ch [185.125.25.9]) (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 B2A8720125D for ; Wed, 8 Jan 2025 15:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.25.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736351055; cv=none; b=gWi51O4j3T0r28cLdIADP2533DwigpvOtDdaS6ExaBF+G/3ErzSz7nqtfQ+jeFF8NcGnUW/kQ0tgcY6vbmu0+0HMBSTovwfe4mwOXizyGq46UTUK1wr+g/UZjUgBPG0SE1P2NOXIg7mEA8vWI9o+G6YyBpgQy1F49Duu4Mzg7pU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736351055; c=relaxed/simple; bh=QGgkX4ZMdgskH5gQyj4rVDmPlqBeDjSuaVFMj8kT34Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z11DPo2mMTQq+ZvoxjKukaaasXA6+bkNvK54EWuPlfy/j21oxErLm9UyTTYy+5NtEVF/UgeYnnCSeOZ+VFP7JIWeAVb4P2IDenzVBqCgN9gkMb3Qyu3btGqora6RpywdZHdPnbCipavpJC5ESHoEIyytMZ1Fkb5oxYNAGLuviME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=A3mJfqi6; arc=none smtp.client-ip=185.125.25.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="A3mJfqi6" Received: from smtp-4-0000.mail.infomaniak.ch (unknown [IPv6:2001:1600:7:10:40ca:feff:fe05:0]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4YSsfN21RNzq5T; Wed, 8 Jan 2025 16:44:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1736351052; bh=AnTdAtgZSuavEJrYHBVG062ie022jRaSQUPxZ972iwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A3mJfqi6bewyqNslA0nOOEGFG81zT0bApU/gNwKLuasYvLiixaEDzKmTbXyaC6JQP IsGuOe20wbZ7VR0HHF5kbJ4SixdUUVHlouQ9xVniBCohftMO7YL/s58mutt14TslGm 9iyYwsxwwco15sCdqwn5MqFtvPKgGU1oLi/CNxXk= Received: from unknown by smtp-4-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4YSsfM1pmDz4B8; Wed, 8 Jan 2025 16:44:11 +0100 (CET) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Eric Paris , Paul Moore , =?UTF-8?q?G=C3=BCnther=20Noack?= , "Serge E . Hallyn" Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Ben Scarlato , Casey Schaufler , Charles Zaffery , Daniel Burgener , Francis Laniel , James Morris , Jann Horn , Jeff Xu , Jorge Lucangeli Obes , Kees Cook , Konstantin Meskhidze , Matt Bobrowski , Mikhail Ivanov , Phil Sutter , Praveen K Paladugu , Robert Salvet , Shervin Oloumi , Song Liu , Tahera Fahimi , Tyler Hicks , audit@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v4 17/30] landlock: Log scoped denials Date: Wed, 8 Jan 2025 16:43:25 +0100 Message-ID: <20250108154338.1129069-18-mic@digikod.net> In-Reply-To: <20250108154338.1129069-1-mic@digikod.net> References: <20250108154338.1129069-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Infomaniak-Routing: alpha Add audit support for unix_stream_connect, unix_may_send, task_kill, and file_send_sigiotask hooks. The related blockers are: - scope.abstract_unix_socket - scope.signal Audit event sample for abstract unix socket: type=3DLANDLOCK_DENY msg=3Daudit(1729738800.268:30): domain=3D195ba459b b= lockers=3Dscope.abstract_unix_socket path=3D00666F6F Audit event sample for signal: type=3DLANDLOCK_DENY msg=3Daudit(1729738800.291:31): domain=3D195ba459b b= lockers=3Dscope.signal opid=3D1 ocomm=3D"systemd" Cc: G=C3=BCnther Noack Cc: Tahera Fahimi Signed-off-by: Micka=C3=ABl Sala=C3=BCn Link: https://lore.kernel.org/r/20250108154338.1129069-18-mic@digikod.net --- Changes since v3: - Cosmetic change to the "scope.*" blocker names. - Extend commit message. Changes since v1: - New patch. --- security/landlock/audit.c | 8 ++++++ security/landlock/audit.h | 2 ++ security/landlock/task.c | 58 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/security/landlock/audit.c b/security/landlock/audit.c index 2744e3d4fe73..7a2183ac9add 100644 --- a/security/landlock/audit.c +++ b/security/landlock/audit.c @@ -70,6 +70,14 @@ get_blocker(const enum landlock_request_type type, if (WARN_ON_ONCE(access_bit >=3D ARRAY_SIZE(net_access_strings))) return "unknown"; return net_access_strings[access_bit]; + + case LANDLOCK_REQUEST_SCOPE_ABSTRACT_UNIX_SOCKET: + WARN_ON_ONCE(access_bit !=3D -1); + return "scope.abstract_unix_socket"; + + case LANDLOCK_REQUEST_SCOPE_SIGNAL: + WARN_ON_ONCE(access_bit !=3D -1); + return "scope.signal"; } =20 WARN_ON_ONCE(1); diff --git a/security/landlock/audit.h b/security/landlock/audit.h index 9a3697b901b5..dd5deaf7dc4d 100644 --- a/security/landlock/audit.h +++ b/security/landlock/audit.h @@ -19,6 +19,8 @@ enum landlock_request_type { LANDLOCK_REQUEST_FS_CHANGE_LAYOUT, LANDLOCK_REQUEST_FS_ACCESS, LANDLOCK_REQUEST_NET_ACCESS, + LANDLOCK_REQUEST_SCOPE_ABSTRACT_UNIX_SOCKET, + LANDLOCK_REQUEST_SCOPE_SIGNAL, }; =20 /* diff --git a/security/landlock/task.c b/security/landlock/task.c index 4fef963274fd..1b3d5de89e14 100644 --- a/security/landlock/task.c +++ b/security/landlock/task.c @@ -263,13 +263,27 @@ static int hook_unix_stream_connect(struct sock *cons= t sock, const struct landlock_ruleset *const dom =3D landlock_get_applicable_domain(landlock_get_current_domain(), unix_scope); + struct lsm_network_audit audit_net =3D { + .sk =3D other, + }; + struct landlock_request request =3D { + .type =3D LANDLOCK_REQUEST_SCOPE_ABSTRACT_UNIX_SOCKET, + .audit =3D { + .type =3D LSM_AUDIT_DATA_NET, + .u.net =3D &audit_net, + }, + }; =20 /* Quick return for non-landlocked tasks. */ if (!dom) return 0; =20 - if (is_abstract_socket(other) && sock_is_scoped(other, dom)) + if (is_abstract_socket(other) && sock_is_scoped(other, dom)) { + request.layer_plus_one =3D + landlock_match_layer_level(dom, unix_scope) + 1; + landlock_log_denial(dom, &request); return -EPERM; + } =20 return 0; } @@ -280,6 +294,16 @@ static int hook_unix_may_send(struct socket *const soc= k, const struct landlock_ruleset *const dom =3D landlock_get_applicable_domain(landlock_get_current_domain(), unix_scope); + struct lsm_network_audit audit_net =3D { + .sk =3D other->sk, + }; + struct landlock_request request =3D { + .type =3D LANDLOCK_REQUEST_SCOPE_ABSTRACT_UNIX_SOCKET, + .audit =3D { + .type =3D LSM_AUDIT_DATA_NET, + .u.net =3D &audit_net, + }, + }; =20 if (!dom) return 0; @@ -291,8 +315,12 @@ static int hook_unix_may_send(struct socket *const soc= k, if (unix_peer(sock->sk) =3D=3D other->sk) return 0; =20 - if (is_abstract_socket(other->sk) && sock_is_scoped(other->sk, dom)) + if (is_abstract_socket(other->sk) && sock_is_scoped(other->sk, dom)) { + request.layer_plus_one =3D + landlock_match_layer_level(dom, unix_scope) + 1; + landlock_log_denial(dom, &request); return -EPERM; + } =20 return 0; } @@ -307,6 +335,13 @@ static int hook_task_kill(struct task_struct *const p, { bool is_scoped; const struct landlock_ruleset *dom; + struct landlock_request request =3D { + .type =3D LANDLOCK_REQUEST_SCOPE_SIGNAL, + .audit =3D { + .type =3D LSM_AUDIT_DATA_TASK, + .u.tsk =3D p, + }, + }; =20 if (cred) { /* Dealing with USB IO. */ @@ -324,8 +359,12 @@ static int hook_task_kill(struct task_struct *const p, is_scoped =3D domain_is_scoped(dom, landlock_get_task_domain(p), LANDLOCK_SCOPE_SIGNAL); rcu_read_unlock(); - if (is_scoped) + if (is_scoped) { + request.layer_plus_one =3D + landlock_match_layer_level(dom, signal_scope) + 1; + landlock_log_denial(dom, &request); return -EPERM; + } =20 return 0; } @@ -334,6 +373,13 @@ static int hook_file_send_sigiotask(struct task_struct= *tsk, struct fown_struct *fown, int signum) { const struct landlock_ruleset *dom; + struct landlock_request request =3D { + .type =3D LANDLOCK_REQUEST_SCOPE_SIGNAL, + .audit =3D { + .type =3D LSM_AUDIT_DATA_TASK, + .u.tsk =3D tsk, + }, + }; bool is_scoped =3D false; =20 /* Lock already held by send_sigio() and send_sigurg(). */ @@ -349,8 +395,12 @@ static int hook_file_send_sigiotask(struct task_struct= *tsk, is_scoped =3D domain_is_scoped(dom, landlock_get_task_domain(tsk), LANDLOCK_SCOPE_SIGNAL); rcu_read_unlock(); - if (is_scoped) + if (is_scoped) { + request.layer_plus_one =3D + landlock_match_layer_level(dom, signal_scope) + 1; + landlock_log_denial(dom, &request); return -EPERM; + } =20 return 0; } --=20 2.47.1