From: Geliang Tang <geliang@kernel.org>
To: Gregory Detal <gregory.detal@gmail.com>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next] Squash to "mptcp: add bpf_mptcp_sched_ops" -- fix bpf access
Date: Sun, 5 May 2024 07:58:18 +0800 [thread overview]
Message-ID: <ZjbLmo80HWM4YO70@T480> (raw)
In-Reply-To: <20240503-bpf_fix_access-v1-1-5a714318ea64@gmail.com>
Hi Gregory,
On Fri, May 03, 2024 at 07:33:25PM +0000, Gregory Detal wrote:
> The current behavior allows to write to mptcp_sock at offset that is
> defined in mptcp_subflow_context and vice versa.
>
> This fixes this by splitting the checks for each struct type.
>
> Signed-off-by: Gregory Detal <gregory.detal@gmail.com>
Thanks for this fix. Looks good to me.
Reviewed-by: Geliang Tang <geliang@kernel.org>
-Geliang
> ---
> net/mptcp/bpf.c | 42 +++++++++++++++++++++++++-----------------
> 1 file changed, 25 insertions(+), 17 deletions(-)
>
> diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
> index 208e5d3f066f..57c47bb430b1 100644
> --- a/net/mptcp/bpf.c
> +++ b/net/mptcp/bpf.c
> @@ -47,24 +47,32 @@ static int bpf_mptcp_sched_btf_struct_access(struct bpf_verifier_log *log,
> size_t end;
>
> t = btf_type_by_id(reg->btf, reg->btf_id);
> - if (t != mptcp_sock_type && t != mptcp_subflow_type) {
> - bpf_log(log, "only access to mptcp sock or subflow is supported\n");
> - return -EACCES;
> - }
>
> - switch (off) {
> - case offsetof(struct mptcp_sock, snd_burst):
> - end = offsetofend(struct mptcp_sock, snd_burst);
> - break;
> - case offsetof(struct mptcp_subflow_context, scheduled):
> - end = offsetofend(struct mptcp_subflow_context, scheduled);
> - break;
> - case offsetof(struct mptcp_subflow_context, avg_pacing_rate):
> - end = offsetofend(struct mptcp_subflow_context, avg_pacing_rate);
> - break;
> - default:
> - bpf_log(log, "no write support to %s at off %d\n",
> - t == mptcp_sock_type ? "mptcp_sock" : "mptcp_subflow_context", off);
> + if (t == mptcp_sock_type) {
> + switch (off) {
> + case offsetof(struct mptcp_sock, snd_burst):
> + end = offsetofend(struct mptcp_sock, snd_burst);
> + break;
> + default:
> + bpf_log(log, "no write support to mptcp_sock at off %d\n",
> + off);
> + return -EACCES;
> + }
> + } else if (t == mptcp_subflow_type) {
> + switch (off) {
> + case offsetof(struct mptcp_subflow_context, scheduled):
> + end = offsetofend(struct mptcp_subflow_context, scheduled);
> + break;
> + case offsetof(struct mptcp_subflow_context, avg_pacing_rate):
> + end = offsetofend(struct mptcp_subflow_context, avg_pacing_rate);
> + break;
> + default:
> + bpf_log(log, "no write support to mptcp_subflow_context at off %d\n",
> + off);
> + return -EACCES;
> + }
> + } else {
> + bpf_log(log, "only access to mptcp sock or subflow is supported\n");
> return -EACCES;
> }
>
>
> ---
> base-commit: 56030f9d3812071365435354c0eb5ffb3504e58a
> change-id: 20240503-bpf_fix_access-a360b88c1534
>
> Best regards,
> --
> Gregory Detal <gregory.detal@gmail.com>
>
next prev parent reply other threads:[~2024-05-04 23:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-03 19:33 [PATCH mptcp-next] Squash to "mptcp: add bpf_mptcp_sched_ops" -- fix bpf access Gregory Detal
2024-05-03 20:22 ` MPTCP CI
2024-05-04 23:58 ` Geliang Tang [this message]
2024-05-06 8:33 ` Matthieu Baerts
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=ZjbLmo80HWM4YO70@T480 \
--to=geliang@kernel.org \
--cc=gregory.detal@gmail.com \
--cc=mptcp@lists.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.