From nobody Tue Nov 26 04:22:25 2024 Received: from smtp-190d.mail.infomaniak.ch (smtp-190d.mail.infomaniak.ch [185.125.25.13]) (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 434B01BDA85; Tue, 22 Oct 2024 16:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.25.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729613441; cv=none; b=QRXbZeF7AAC/JJSQxTReeOPOm/CBoBiypjANvzWAwNb9TGCSF2m+nX+9D/HGkN7xsBN0+npw0oD02QyQYmC6iZs4T+LGAyCopWOHf+La/2Y3LbjgSeEIQJc1wbqZFUe5kAPD2uEc7uA9gbvWRAHSqADijQcYDJ63VMsoNQ+TlgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729613441; c=relaxed/simple; bh=rlNg5xRtAk/fMeKAFzaVUpBQpvdKcN3yBcGs9kIU4is=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NmkCK3+hNeowvWVuNJyU+CvTAwtV9VuEGiLwpn1shbb/ab3IHyErxEf+4da0NgnbrsISef9zvLaIZSnJPjlPScEuT37zr58PuCec7wkNIO3b/y1cT2vV3JvBBE5vqxCS1bPW/MwODFjLSccT0oOvC27Bxhplyl1+TAZGtBREn2k= 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=L1L1LnKf; arc=none smtp.client-ip=185.125.25.13 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="L1L1LnKf" Received: from smtp-4-0001.mail.infomaniak.ch (smtp-4-0001.mail.infomaniak.ch [10.7.10.108]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4XXxws2SYtz19l7; Tue, 22 Oct 2024 18:10:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1729613437; bh=5q+SMXfS7orwC9ZKwlMlPSsCzyX9dmv07VXZUyHdcYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1L1LnKfBUVWY4s5szp1XEk/qkhAtcVRHfQZ4iqStkVQqdEyk9Vl8iEvwT+kE71G2 cjJzaQiZLYyLvoEYeYfya6zD979fwbY7/c8zIas04+z9uJq3EG8dy0ljbCC1DetBSu xWJF7hbdGa2TitGp0O9xOLqVe0LxzY3lsKCrGjiA= Received: from unknown by smtp-4-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4XXxwr38Wmz57j; Tue, 22 Oct 2024 18:10:36 +0200 (CEST) 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 , James Morris , Jann Horn , Jeff Xu , Jorge Lucangeli Obes , Kees Cook , Konstantin Meskhidze , Matt Bobrowski , Mikhail Ivanov , Praveen K Paladugu , Robert Salvet , Shervin Oloumi , Song Liu , Tahera Fahimi , audit@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [RFC PATCH v2 13/14] landlock: Log scoped denials Date: Tue, 22 Oct 2024 18:10:08 +0200 Message-ID: <20241022161009.982584-14-mic@digikod.net> In-Reply-To: <20241022161009.982584-1-mic@digikod.net> References: <20241022161009.982584-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. Audit record sample: DENY: domain=3D4533720578 blockers=3Dscope_abstract_unix_socket path= =3D00666F6F SYSCALL: arch=3Dc000003e syscall=3D42 success=3Dno exit=3D-1 ... Cc: G=C3=BCnther Noack Cc: Tahera Fahimi Signed-off-by: Micka=C3=ABl Sala=C3=BCn Link: https://lore.kernel.org/r/20241022161009.982584-14-mic@digikod.net --- 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 c31a4a8719ee..b551812b8bc9 100644 --- a/security/landlock/audit.c +++ b/security/landlock/audit.c @@ -69,6 +69,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 1075b0c8401f..1e0a9164bacc 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 8c4468fb86bf..ddcb993bd53a 100644 --- a/security/landlock/task.c +++ b/security/landlock/task.c @@ -262,13 +262,27 @@ static int hook_unix_stream_connect(struct sock *cons= t sock, { const struct landlock_ruleset *const dom =3D landlock_match_ruleset( 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; } @@ -278,6 +292,16 @@ static int hook_unix_may_send(struct socket *const soc= k, { const struct landlock_ruleset *const dom =3D landlock_match_ruleset( 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; @@ -289,8 +313,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; } @@ -305,6 +333,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. */ @@ -322,8 +357,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; } @@ -332,6 +371,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(). */ @@ -347,8 +393,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.0