From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D08FB13342F; Tue, 23 Jan 2024 00:18:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969131; cv=none; b=iAUuWNP2Fy6r3X22fBogCz3iefPATKSgidH1pzBzlOnHohfJek3ki62fK+VEpFJEcNWbfSRrO+Cxikw5SUCSiMwQNQK5iDX1eumSyzs6Az2rurnRSBZXt8DtKz8/5dgYu/hIwpVArlCkPRrUM6AaOqp+NTQLirAOewAq61Qu8oQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969131; c=relaxed/simple; bh=4j5uJPv9a6Z6ZKrKerju5VuoJzFAMLD0B7Bd8Cgv8K4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U+FgmvIsZ1Usm1dkspuAIxjBwZEjgJ7+xqOdPfhPCveSLHsliAFJOd6vP3xed5mlvUGGfEtAdNjA0Lar2DDRNrChGOLEZfwRJeG1wa/1a5TWqhGonRyYMXh2JNVOVwavxjfCFit8W2/r/UeKYrpMK/a1M89t/JMp5imoCWbzoqM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LZHDozmg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LZHDozmg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 754D8C433C7; Tue, 23 Jan 2024 00:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705969131; bh=4j5uJPv9a6Z6ZKrKerju5VuoJzFAMLD0B7Bd8Cgv8K4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LZHDozmgH9/MHr6qTcQ+W03hHikEOJDn7W1FItDAtd2LXYbufP2YuUBR8DBmy7tMl TzM+rxXgywpjbhUFglZ/RMz2teKQdH1Ux4LM3X+32v7iLiZHPCMztCuXHZ9jYhMyxI 7iP9MNOtD6pPQBxccJ6CSj5Y23AF+7EC97zr4/cU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Paris , Konstantin Meskhidze , Paul Moore , Stephen Smalley , Muhammad Usama Anjum , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Sasha Levin Subject: [PATCH 6.7 042/641] selinux: Fix error priority for bind with AF_UNSPEC on PF_INET6 socket Date: Mon, 22 Jan 2024 15:49:06 -0800 Message-ID: <20240122235819.399059111@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235818.091081209@linuxfoundation.org> References: <20240122235818.091081209@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mickaël Salaün [ Upstream commit bbf5a1d0e5d0fb3bdf90205aa872636122692a50 ] 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 Tested-by: Muhammad Usama Anjum Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- security/selinux/hooks.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 340b2bbbb2dd..0fb890bd72cb 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -4661,6 +4661,13 @@ 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 == PF_INET6) { + /* Length check from inet6_bind_sk() */ + if (addrlen < SIN6_LEN_RFC2133) + return -EINVAL; + /* Family check from __inet6_bind() */ + goto err_af; + } /* see __inet_bind(), we only want to allow * AF_UNSPEC if the address is INADDR_ANY */ -- 2.43.0