Skip to content

Commit

Permalink
landlock: Fix non-TCP sockets restriction
Browse files Browse the repository at this point in the history
Use sk_is_tcp() to check if socket is TCP in bind(2) and connect(2)
hooks.

SMC, MPTCP, SCTP protocols are currently restricted by TCP access
rights.  The purpose of TCP access rights is to provide control over
ports that can be used by userland to establish a TCP connection.
Therefore, it is incorrect to deny bind(2) and connect(2) requests for a
socket of another protocol.

However, SMC, MPTCP and RDS implementations use TCP internal sockets to
establish communication or even to exchange packets over a TCP
connection [1]. Landlock rules that configure bind(2) and connect(2)
usage for TCP sockets should not cover requests for sockets of such
protocols. These protocols have different set of security issues and
security properties, therefore, it is necessary to provide the userland
with the ability to distinguish between them (eg. [2]).

Control over TCP connection used by other protocols can be achieved with
upcoming support of socket creation control [3].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/

Closes: landlock-lsm/linux#40
Fixes: fff69fb ("landlock: Support network rules with TCP bind and connect")
Signed-off-by: Mikhail Ivanov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[mic: Format commit message to 72 columns]
Signed-off-by: Mickaël Salaün <[email protected]>
  • Loading branch information
sm1ling-knight authored and l0kod committed Feb 14, 2025
1 parent 192b7ff commit 854277e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions security/landlock/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ static int current_check_access_socket(struct socket *const sock,
if (WARN_ON_ONCE(dom->num_layers < 1))
return -EACCES;

/* Checks if it's a (potential) TCP socket. */
if (sock->type != SOCK_STREAM)
if (!sk_is_tcp(sock->sk))
return 0;

/* Checks for minimal header length to safely read sa_family. */
Expand Down

0 comments on commit 854277e

Please sign in to comment.