From: Daniel Borkmann <daniel@iogearbox.net>
To: David Miller <davem@davemloft.net>, ast@fb.com
Cc: alexei.starovoitov@gmail.com, netdev@vger.kernel.org
Subject: Re: [PATCH 3/5] bpf: Add strict alignment flag for BPF_PROG_LOAD.
Date: Thu, 11 May 2017 14:53:58 +0200 [thread overview]
Message-ID: <59145EE6.3030409@iogearbox.net> (raw)
In-Reply-To: <20170510.150951.1359250469075249855.davem@davemloft.net>
On 05/10/2017 09:09 PM, David Miller wrote:
>
> Add a new field, "prog_flags", and an initial flag value
> BPF_F_STRCIT_ALIGNMENT.
>
> When set, the verifier will enforce strict pointer alignment
> regardless of the setting of CONFIG_EFFICIENT_UNALIGNED_ACCESS.
>
> The verifier, in this mode, will also use a fixed value of "2" in
> place of NET_IP_ALIGN.
>
> This facilitates test cases that will exercise and validate this part
> of the verifier even when run on architectures where alignment doesn't
> matter.
>
> Signed-off-by: David S. Miller <davem@davemloft.net>
[...]
> @@ -833,10 +838,12 @@ static int check_val_ptr_alignment(const struct bpf_reg_state *reg,
> return 0;
> }
>
> +static bool strict_alignment;
> +
> static int check_ptr_alignment(const struct bpf_reg_state *reg,
> int off, int size)
> {
> - bool strict = false;
> + bool strict = strict_alignment;
>
> if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS))
> strict = true;
> @@ -3574,6 +3581,10 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr)
> } else {
> log_level = 0;
> }
> + if (attr->prog_flags & BPF_F_STRICT_ALIGNMENT)
> + strict_alignment = true;
> + else
> + strict_alignment = false;
Just minor nit: Can we move this into struct bpf_verifier_env
here instead of global var? The only change it would need is
in check_ptr_alignment() to pass the env from check_mem_access().
check_ptr_alignment() can then infer this from env.
> ret = replace_map_fd_with_map_ptr(env);
> if (ret < 0)
> @@ -3679,6 +3690,7 @@ int bpf_analyzer(struct bpf_prog *prog, const struct bpf_ext_analyzer_ops *ops,
> mutex_lock(&bpf_verifier_lock);
>
> log_level = 0;
> + strict_alignment = false;
>
> env->explored_states = kcalloc(env->prog->len,
> sizeof(struct bpf_verifier_state_list *),
Rest looks good:
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
next prev parent reply other threads:[~2017-05-11 12:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-10 19:09 [PATCH 3/5] bpf: Add strict alignment flag for BPF_PROG_LOAD David Miller
2017-05-11 12:53 ` Daniel Borkmann [this message]
2017-05-11 14:53 ` David Miller
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=59145EE6.3030409@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=alexei.starovoitov@gmail.com \
--cc=ast@fb.com \
--cc=davem@davemloft.net \
--cc=netdev@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).