From patchwork Fri Dec 29 17:19:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= X-Patchwork-Id: 13506576 X-Patchwork-Delegate: paul@paul-moore.com Received: from smtp-8fae.mail.infomaniak.ch (smtp-8fae.mail.infomaniak.ch [83.166.143.174]) (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 6839812B7C for ; Fri, 29 Dec 2023 17:37:29 +0000 (UTC) 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="rqYSV7Fm" Received: from smtp-2-0000.mail.infomaniak.ch (unknown [10.5.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4T1sYt6LzBzMq3Zg; Fri, 29 Dec 2023 17:19:30 +0000 (UTC) Received: from unknown by smtp-2-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4T1sYt382bzMpnPj; Fri, 29 Dec 2023 18:19:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1703870370; bh=iWCTq4r7MX4ixyXArvXbHN6AigAhBSm8EYAy6EQT7W0=; h=From:To:Cc:Subject:Date:From; b=rqYSV7FmBZU+E8lgAQ41Q6PuW8Q6DFArB7erNQZInrox7viDZqKZ89Lo1MYdPZCRS NY4o/srb0qg5YEi0lcx4a7elODyZon+76D/QIjymVQ2y3fdZP6EGQd4pVPrAC2r0oj pyx8hMr4IJ+r9WNV9eIYTxu3EbTfWGxzej1lN9AI= From: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= To: Eric Paris , Paul Moore , Stephen Smalley Cc: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , =?utf-8?q?G?= =?utf-8?q?=C3=BCnther_Noack?= , Konstantin Meskhidze , Muhammad Usama Anjum , linux-security-module@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2] selinux: Fix error priority for bind with AF_UNSPEC on AF_INET6 socket Date: Fri, 29 Dec 2023 18:19:22 +0100 Message-ID: <20231229171922.106190-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Infomaniak-Routing: alpha The IPv6 network stack first checks the sockaddr length (-EINVAL error) before checking the family (-EAFNOSUPPORT error). This was discovered thanks to commit a549d055a22e ("selftests/landlock: Add network tests"). Cc: Eric Paris Cc: Konstantin Meskhidze Cc: Paul Moore Cc: Stephen Smalley Reported-by: Muhammad Usama Anjum Closes: https://lore.kernel.org/r/0584f91c-537c-4188-9e4f-04f192565667@collabora.com Fixes: 0f8db8cc73df ("selinux: add AF_UNSPEC and INADDR_ANY checks to selinux_socket_bind()") Signed-off-by: Mickaël Salaün --- Changes since v1: https://lore.kernel.org/r/20231228113917.62089-1-mic@digikod.net * Use the "family" variable (suggested by Paul). --- security/selinux/hooks.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index feda711c6b7b..748baa98f623 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4667,6 +4667,9 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in return -EINVAL; addr4 = (struct sockaddr_in *)address; if (family_sa == AF_UNSPEC) { + if (family == AF_INET6 && + addrlen < SIN6_LEN_RFC2133) + return -EINVAL; /* see __inet_bind(), we only want to allow * AF_UNSPEC if the address is INADDR_ANY */