All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: selinux@vger.kernel.org
Subject: Re: [PATCH] selinux: fix uninit-value in selinux_socket_connect_helper()
Date: Mon, 30 Nov 2026 17:06:41 +0000	[thread overview]
Message-ID: <sashiko-outbox-241660@kernel.org> (raw)
In-Reply-To: <20261130165425.79011-1-petrvaganoff@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selinux: redundant addrlen checks left in
  selinux_socket_connect_helper()
--

commit 63970c8ae1c49270fad79b5cf3317b0f3db75e72
Author: Petr Vaganov <petrvaganoff@gmail.com>

selinux: fix uninit-value in selinux_socket_connect_helper()

This commit adds address length checks for AF_INET and AF_INET6 in
selinux_socket_connect_helper() before the TCP/SCTP check so that
netlbl_conn_setattr() does not read uninitialized memory on short UDP or
RAW socket connect() calls.

> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 30776b0107f29..add34952116c0 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -5281,6 +5281,17 @@ static int selinux_socket_connect_helper(struct sock *sk,
>  	if (address->sa_family == AF_UNSPEC)
>  		return 0;
>  
> +	switch (address->sa_family) {
> +	case AF_INET:
> +		if (addrlen < sizeof(struct sockaddr_in))
> +			return -EINVAL;
> +		break;
> +	case AF_INET6:
> +		if (addrlen < SIN6_LEN_RFC2133)
> +			return -EINVAL;
> +		break;
> +	}
> +
>  	/*
>  	 * If a TCP or SCTP socket, check name_connect permission
>  	 * for the port.

[Severity: Low]
Can the duplicate addrlen checks for AF_INET and AF_INET6 inside the
SECCLASS_TCP_SOCKET / SECCLASS_SCTP_SOCKET block right below be removed
now that they are checked unconditionally here?

security/selinux/hooks.c:selinux_socket_connect_helper() {
    ...
		switch (address->sa_family) {
		case AF_INET:
			addr4 = (struct sockaddr_in *)address;
			if (addrlen < sizeof(struct sockaddr_in))
				return -EINVAL;
			snum = ntohs(addr4->sin_port);
			break;
		case AF_INET6:
			addr6 = (struct sockaddr_in6 *)address;
			if (addrlen < SIN6_LEN_RFC2133)
				return -EINVAL;
			snum = ntohs(addr6->sin6_port);
			break;
    ...
}

Those inner branches are now unreachable dead code.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130165425.79011-1-petrvaganoff@gmail.com?part=1

      reply	other threads:[~2026-11-30 17:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:54 [PATCH] selinux: fix uninit-value in selinux_socket_connect_helper() Petr Vaganov
2026-11-30 17:06 ` sashiko-bot [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=sashiko-outbox-241660@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=selinux@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.