public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Daan De Meyer <daan.j.demeyer@gmail.com>
Cc: kernel-team@meta.com, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 3/9] bpf: Add bpf_sock_addr_set() to allow writing sockaddr len from bpf
Date: Tue, 29 Aug 2023 23:28:17 -0700	[thread overview]
Message-ID: <9b84dc6f-2723-a3c0-7eba-143c4fd9c30b@linux.dev> (raw)
In-Reply-To: <20230829101838.851350-4-daan.j.demeyer@gmail.com>

On 8/29/23 3:18 AM, Daan De Meyer wrote:
> +__bpf_kfunc int bpf_sock_addr_set_addr(struct bpf_sock_addr_kern *sa_kern,
> +				       const u8 *addr, u32 addrlen__sz)
> +{
> +	struct sockaddr *sa = sa_kern->uaddr;
> +	struct sockaddr_in *sa4;
> +	struct sockaddr_in6 *sa6;
> +	struct sockaddr_un *un;
> +
> +	switch (sa->sa_family) {

The sa_family could be AF_UNSPEC here for inet addr (eg. take a look at 
__inet_bind checking AF_UNSPEC). Test the sa_kern->sk->sk_family instead.

> +	case AF_INET:
> +		if (addrlen__sz != 4)
> +			return -EINVAL;
> +		sa4 = (struct sockaddr_in *)sa;
> +		sa4->sin_addr.s_addr = *(__be32 *)addr;
> +		break;
> +	case AF_INET6:
> +		if (addrlen__sz != 16)
> +			return -EINVAL;
> +		sa6 = (struct sockaddr_in6 *)sa;
> +		memcpy(sa6->sin6_addr.s6_addr, addr, 16);
> +		break;
> +	default:
> +		WARN_ON_ONCE(1);

The above switch case will test sk_family instead, so this WARN should never 
happen and should be removed.

> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
>   __diag_pop();


  parent reply	other threads:[~2023-08-30  6:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-29 10:18 [PATCH bpf-next v3 0/9] Add cgroup sockaddr hooks for unix sockets Daan De Meyer
2023-08-29 10:18 ` [PATCH bpf-next v3 1/9] selftests/bpf: Add missing section name tests for getpeername/getsockname Daan De Meyer
2023-08-29 10:18 ` [PATCH bpf-next v3 2/9] bpf: Propagate modified uaddrlen from cgroup sockaddr programs Daan De Meyer
2023-08-30  6:21   ` Martin KaFai Lau
2023-08-29 10:18 ` [PATCH bpf-next v3 3/9] bpf: Add bpf_sock_addr_set() to allow writing sockaddr len from bpf Daan De Meyer
2023-08-29 17:42   ` Alexei Starovoitov
2023-08-30  6:28   ` Martin KaFai Lau [this message]
2023-08-29 10:18 ` [PATCH bpf-next v3 4/9] bpf: Implement cgroup sockaddr hooks for unix sockets Daan De Meyer
2023-08-29 10:18 ` [PATCH bpf-next v3 5/9] libbpf: Add support for cgroup unix socket address hooks Daan De Meyer
2023-08-29 10:18 ` [PATCH bpf-next v3 6/9] bpftool: " Daan De Meyer
2023-08-29 16:27   ` Quentin Monnet
2023-08-29 10:18 ` [PATCH bpf-next v3 7/9] documentation/bpf: Document " Daan De Meyer
2023-08-29 10:18 ` [PATCH bpf-next v3 8/9] selftests/bpf: Make sure mount directory exists Daan De Meyer
2023-08-30  6:32   ` Martin KaFai Lau
2023-08-29 10:18 ` [PATCH bpf-next v3 9/9] selftests/bpf: Add tests for cgroup unix socket address hooks Daan De Meyer
2023-08-30  6:51   ` Martin KaFai Lau

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=9b84dc6f-2723-a3c0-7eba-143c4fd9c30b@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=bpf@vger.kernel.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=kernel-team@meta.com \
    /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