From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com,
yhs@fb.com, jose.marchesi@oracle.com
Subject: Re: [PATCH bpf-next 1/3] bpf: allow ctx writes using BPF_ST_MEM instruction
Date: Sat, 04 Mar 2023 00:56:30 +0200 [thread overview]
Message-ID: <de93e249059f45d7ca36846ae177c2259cab3919.camel@gmail.com> (raw)
In-Reply-To: <20230303202104.zoldj5z3m35ikkv2@MacBook-Pro-6.local>
On Fri, 2023-03-03 at 12:21 -0800, Alexei Starovoitov wrote:
> On Fri, Mar 03, 2023 at 12:55:05AM +0200, Eduard Zingerman wrote:
> > - prev_src_type = &env->insn_aux_data[env->insn_idx].ptr_type;
> > -
> > - if (*prev_src_type == NOT_INIT) {
> > - /* saw a valid insn
> > - * dst_reg = *(u32 *)(src_reg + off)
> > - * save type to validate intersecting paths
> > - */
> > - *prev_src_type = src_reg_type;
> > -
> > - } else if (reg_type_mismatch(src_reg_type, *prev_src_type)) {
> > - /* ABuser program is trying to use the same insn
> > - * dst_reg = *(u32*) (src_reg + off)
> > - * with different pointer types:
> > - * src_reg == ctx in one branch and
> > - * src_reg == stack|map in some other branch.
> > - * Reject it.
> > - */
> > - verbose(env, "same insn cannot be used with different pointers\n");
> > - return -EINVAL;
>
> There is a merge conflict with this part.
> LDX is now handled slightly differently comparing to STX.
I changed save_aux_ptr_type() as below:
static int save_aux_ptr_type(struct bpf_verifier_env *env, enum bpf_reg_type type,
bool allow_trust_missmatch)
{
enum bpf_reg_type *prev_type = &env->insn_aux_data[env->insn_idx].ptr_type;
...
if (*prev_type == NOT_INIT) {
...
} else if (reg_type_mismatch(type, *prev_type)) {
/* Abuser program is trying to use the same insn
* ...
*/
if (allow_trust_missmatch &&
base_type(type) == PTR_TO_BTF_ID &&
base_type(*prev_type) == PTR_TO_BTF_ID) {
/*
* Have to support a use case when one path through
* the program yields TRUSTED pointer while another
* is UNTRUSTED. Fallback to UNTRUSTED to generate
* BPF_PROBE_MEM.
*/
*prev_type = PTR_TO_BTF_ID | PTR_UNTRUSTED;
} else {
verbose(env, "same insn cannot be used with different pointers\n");
return -EINVAL;
}
}
return 0;
}
But I don't understand why is it allowed to dereference untrusted
pointers for LDX but not for ST/STX.
[...]
next prev parent reply other threads:[~2023-03-03 22:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 22:55 [PATCH bpf-next 0/3] bpf: allow ctx writes using BPF_ST_MEM instruction Eduard Zingerman
2023-03-02 22:55 ` [PATCH bpf-next 1/3] " Eduard Zingerman
2023-03-03 20:21 ` Alexei Starovoitov
2023-03-03 21:17 ` Eduard Zingerman
2023-03-03 22:56 ` Eduard Zingerman [this message]
2023-03-02 22:55 ` [PATCH bpf-next 2/3] selftests/bpf: test if pointer type is tracked for BPF_ST_MEM Eduard Zingerman
2023-03-02 22:55 ` [PATCH bpf-next 3/3] selftests/bpf: Disassembler tests for verifier.c:convert_ctx_access() Eduard Zingerman
2023-03-03 20:28 ` Alexei Starovoitov
2023-03-03 21:24 ` Eduard Zingerman
2023-03-03 21:35 ` Alexei Starovoitov
2023-03-03 21:42 ` Eduard Zingerman
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=de93e249059f45d7ca36846ae177c2259cab3919.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jose.marchesi@oracle.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--cc=yhs@fb.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