From: John Johansen <john.johansen@canonical.com>
To: Michail Andreas Michalopoulos <mike.michalo@gmail.com>,
Georgia Garcia <georgia.garcia@canonical.com>
Cc: apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] apparmor: check address length before reading AF_UNSPEC bind address
Date: Mon, 26 Oct 2026 12:48:21 -0700 [thread overview]
Message-ID: <598098fe-c598-4a67-a60e-849141d27ac1@canonical.com> (raw)
In-Reply-To: <20261020140030.92643-1-mike.michalo@gmail.com>
On 10/20/26 07:00, Michail Andreas Michalopoulos wrote:
> bind_map_addr() handles AF_UNSPEC on an IPv4 socket by reading
> addr4->sin_addr.s_addr to check for INADDR_ANY. At that point the only
> length check done is addrlen >= offsetofend(struct sockaddr, sa_family),
> i.e. 2 bytes, while sin_addr sits at offset 4. move_addr_to_kernel()
> copies only addrlen bytes into the on-stack sockaddr_storage, so a
> bind() with a short AF_UNSPEC address makes AppArmor branch on bytes the
> caller never supplied.
>
> Depending on those bytes, a confined task gets -EAFNOSUPPORT instead of
> the -EINVAL that inet_bind_sk() returns for the same request. Kernels
> built with CONFIG_INIT_STACK_ALL_ZERO read zeroes and happen to behave
> correctly.
>
> Check the length first, as inet_bind_sk() does, and as the AF_INET6
> case above already does for inet6_bind_sk().
>
> Fixes: 89ac6aa752ec ("apparmor: push inet mediation into profile callbacks, and improve auditing")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Michail Andreas Michalopoulos <mike.michalo@gmail.com>
sorry for the lateness of the reply,
Acked-by: John Johansen <john.johansen@canonical.com>
> ---
> Tested on v7.3 built with CONFIG_INIT_STACK_NONE in QEMU, with a task
> confined by a profile allowing all network access, calling bind() on an
> AF_INET UDP socket with {.sa_family = AF_UNSPEC} and addrlen 2 and 4
> (200 times each, after leaving a non-zero address in the kernel buffer):
> unpatched returns -EAFNOSUPPORT every time, patched returns -EINVAL
> every time, matching unconfined tasks. Other AF_UNSPEC, AF_INET and
> AF_INET6 bind cases behave identically with and without the patch.
> ---
> security/apparmor/af_inet.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/security/apparmor/af_inet.c b/security/apparmor/af_inet.c
> index 516c9016537c..a617f8058634 100644
> --- a/security/apparmor/af_inet.c
> +++ b/security/apparmor/af_inet.c
> @@ -196,6 +196,9 @@ static int bind_map_addr(const struct sock *sk, struct sockaddr *addr,
> * AF_UNSPEC if the address is INADDR_ANY
> */
> addr4 = (struct sockaddr_in *)addr;
> + /* Length check from inet_bind_sk() */
> + if (addrlen < sizeof(struct sockaddr_in))
> + return -EINVAL;
> if (addr4->sin_addr.s_addr != htonl(INADDR_ANY))
> return -EAFNOSUPPORT;
> family = AF_INET;
prev parent reply other threads:[~2026-10-26 19:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 14:00 Michail Andreas Michalopoulos
2026-10-26 19:48 ` John Johansen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=598098fe-c598-4a67-a60e-849141d27ac1@canonical.com \
--to=john.johansen@canonical.com \
--cc=apparmor@lists.ubuntu.com \
--cc=georgia.garcia@canonical.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mike.michalo@gmail.com \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®