From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Wang Nan <wangnan0@huawei.com>
Cc: acme@kernel.org, ast@kernel.org, linux-kernel@vger.kernel.org,
pi3orama@163.com, lizefan@huawei.com,
Arnaldo Carvalho de Melo <acme@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
Wu Fengguang <fengguang.wu@intel.com>
Subject: Re: [net-next PATCHv2] bpf: Output error message to logbuf when loading failure
Date: Mon, 26 Oct 2015 20:26:30 -0700 [thread overview]
Message-ID: <20151027032628.GB26748@Alexeis-MacBook-Pro.local> (raw)
In-Reply-To: <1445843588-143137-1-git-send-email-wangnan0@huawei.com>
On Mon, Oct 26, 2015 at 07:13:08AM +0000, Wang Nan wrote:
> Many reasons can make bpf_prog_load() return EINVAL. This patch utilizes
> logbuf to deliver the actual reason of the failure.
>
> Without this patch, it is very easy for user to pass an object with
> "version" section not match the kernel version code, and the problem
> is hard to determine from return code (EINVAL).
>
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Wu Fengguang <fengguang.wu@intel.com>
NACK
for both implementation and design.
> + /* Don't need care the copying result too much */
> + WARN(copy_to_user(log_ubuf, log_buf, log_size),
> + KERN_WARNING "Failed to copy BPF error note '%s' to log buffer\n",
> + log_buf);
unprivilged user will be spamming kernel logs?!
> - if (attr->insn_cnt >= BPF_MAXINSNS)
> + if (attr->insn_cnt >= BPF_MAXINSNS) {
> + bpf_prog_load_note(attr, "Too many instructions: %d > %d\n",
> + attr->insn_cnt, BPF_MAXINSNS);
> return -EINVAL;
if user space did that, it's wrong and can detect it
on its own.
> if (type == BPF_PROG_TYPE_KPROBE &&
> - attr->kern_version != LINUX_VERSION_CODE)
> + attr->kern_version != LINUX_VERSION_CODE) {
> + bpf_prog_load_note(attr,
> + "Kernel version mismatch: 0x%x != 0x%x\n",
> + attr->kern_version, LINUX_VERSION_CODE);
> return -EINVAL;
user space (perf) could have checked that on its own
without kernel changes.
> /* find program type: socket_filter vs tracing_filter */
> err = find_prog_type(type, prog);
> - if (err < 0)
> + if (err < 0) {
> + bpf_prog_load_note(attr, "Invalid program type: %d\n", type);
> goto free_prog;
same here.
In general syscalls muxing different error conditions into EINVAL
is a kernel wide problem and should be solved for all.
next prev parent reply other threads:[~2015-10-27 3:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-26 6:36 [net-next PATCH] bpf: Output error message to logbuf when loading Wang Nan
2015-10-26 6:48 ` Wangnan (F)
2015-10-26 6:50 ` kbuild test robot
2015-10-26 7:13 ` [net-next PATCHv2] bpf: Output error message to logbuf when loading failure Wang Nan
2015-10-27 3:26 ` Alexei Starovoitov [this message]
2015-10-27 3:42 ` Wangnan (F)
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=20151027032628.GB26748@Alexeis-MacBook-Pro.local \
--to=alexei.starovoitov@gmail.com \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=ast@kernel.org \
--cc=davem@davemloft.net \
--cc=fengguang.wu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=pi3orama@163.com \
--cc=wangnan0@huawei.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;
as well as URLs for NNTP newsgroup(s).