All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Geliang Tang <geliang@kernel.org>, Matthieu Baerts <matttbe@kernel.org>
Cc: mptcp@lists.linux.dev, Mat Martineau <martineau@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Mykola Lysenko <mykolal@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Daniel Xu <dxu@dxuuu.xyz>, Manu Bretelle <chantra@meta.com>
Subject: Re: [PATCH bpf-next v4 2/2] selftests/bpf: Add mptcp subflow subtest
Date: Mon, 19 Aug 2024 16:28:37 -0700	[thread overview]
Message-ID: <40a2828d-1881-416f-94ad-595b85b8dd84@linux.dev> (raw)
In-Reply-To: <db295f729981cd0eaebb93c5939b515f50882c11.camel@kernel.org>

On 8/17/24 7:13 PM, Geliang Tang wrote:
>> Take a look at a recent example [0]. The mptcp test is under a cgroup
>> already
>> and has the cgroup setup. An extra "cgroup/getsockopt" prog should be
>> enough.
>> That prog can walk the msk->conn_list and use bpf_rdonly_cast (or the
 >> bpf_core_cast macro in libbpf) to cast a pointer to tcp_sock for

[ ... ]

> SEC("cgroup/getsockopt")
> int _getsockopt(struct bpf_sockopt *ctx)
> {
>          struct mptcp_sock *msk = bpf_core_cast(ctx->sk, struct
> mptcp_sock);
>          struct mptcp_subflow_context *subflow;
>          __u32 token = 0;
> 
>          if (!msk || ctx->level != SOL_TCP ||
> 			ctx->optname != TCP_CONGESTION)
>                  return 1;
> 
>          subflow = list_first_entry(&msk->conn_list,
> 			struct mptcp_subflow_context, node);
>          token = subflow->token;
>          bpf_trace_printk(fmt, sizeof(fmt), msk, token);
> 
>          return 1;
> }
> 
> And got some access errors:
> 
> ; token = subflow->token; @ mptcp_subflow.c:92
> 13: (61) r4 = *(u32 *)(r1 +524)
> access beyond struct list_head at off 524 size 4

Similar to your bpf_core_cast() usage earlier that casts a sock ptr to 
mptcp_sock ptr. r1 is in list_head ptr type. It needs to cast to 
mptcp_subflow_context ptr.

The same cast to tcp_sock is needed when you try to get the tcp_sock ptr from 
subflow->tcp_sock which is in "struct sock *" type in the kernel instead of 
"struct tcp_sock *".


  reply	other threads:[~2024-08-19 23:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-05  9:52 [PATCH bpf-next v4 0/2] selftests/bpf: new MPTCP subflow subtest Matthieu Baerts (NGI0)
2024-08-05  9:52 ` [PATCH bpf-next v4 1/2] selftests/bpf: Add mptcp subflow example Matthieu Baerts (NGI0)
2024-08-05  9:52 ` [PATCH bpf-next v4 2/2] selftests/bpf: Add mptcp subflow subtest Matthieu Baerts (NGI0)
2024-08-14  1:12   ` Martin KaFai Lau
2024-08-14 10:04     ` Matthieu Baerts
2024-08-14 22:37       ` Martin KaFai Lau
2024-08-15 20:57         ` Matthieu Baerts
2024-08-15 21:00         ` Matthieu Baerts
2024-08-18  2:13         ` Geliang Tang
2024-08-19 23:28           ` Martin KaFai Lau [this message]
2024-08-21 20:32     ` Manu Bretelle
2024-08-22  9:13       ` Matthieu Baerts
2024-08-14 22:16   ` 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=40a2828d-1881-416f-94ad-595b85b8dd84@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chantra@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=dxu@dxuuu.xyz \
    --cc=eddyz87@gmail.com \
    --cc=geliang@kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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.