From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jiri Olsa <jolsa@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Sasha Levin <sashal@kernel.org>,
netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 05/39] bpf: Forbid trampoline attach for functions with variable arguments
Date: Thu, 3 Jun 2021 13:07:55 -0400 [thread overview]
Message-ID: <20210603170829.3168708-5-sashal@kernel.org> (raw)
In-Reply-To: <20210603170829.3168708-1-sashal@kernel.org>
From: Jiri Olsa <jolsa@kernel.org>
[ Upstream commit 31379397dcc364a59ce764fabb131b645c43e340 ]
We can't currently allow to attach functions with variable arguments.
The problem is that we should save all the registers for arguments,
which is probably doable, but if caller uses more than 6 arguments,
we need stack data, which will be wrong, because of the extra stack
frame we do in bpf trampoline, so we could crash.
Also currently there's malformed trampoline code generated for such
functions at the moment as described in:
https://lore.kernel.org/bpf/20210429212834.82621-1-jolsa@kernel.org/
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210505132529.401047-1-jolsa@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/bpf/btf.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index ed7d02e8bc93..aaf2fbaa0cc7 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -4960,6 +4960,12 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
m->ret_size = ret;
for (i = 0; i < nargs; i++) {
+ if (i == nargs - 1 && args[i].type == 0) {
+ bpf_log(log,
+ "The function %s with variable args is unsupported.\n",
+ tname);
+ return -EINVAL;
+ }
ret = __get_type_size(btf, args[i].type, &t);
if (ret < 0) {
bpf_log(log,
@@ -4967,6 +4973,12 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
tname, i, btf_kind_str[BTF_INFO_KIND(t->info)]);
return -EINVAL;
}
+ if (ret == 0) {
+ bpf_log(log,
+ "The function %s has malformed void argument.\n",
+ tname);
+ return -EINVAL;
+ }
m->arg_size[i] = ret;
}
m->nr_args = nargs;
--
2.30.2
next parent reply other threads:[~2021-06-03 17:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210603170829.3168708-1-sashal@kernel.org>
2021-06-03 17:07 ` Sasha Levin [this message]
2021-06-03 17:07 ` [PATCH AUTOSEL 5.10 06/39] net/nfc/rawsock.c: fix a permission check bug Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 10/39] bpf: Add deny list of btf ids check for tracing programs Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 16/39] isdn: mISDN: netjet: Fix crash in nj_probe: Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 17/39] bonding: init notify_work earlier to avoid uninitialized use Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 18/39] netlink: disable IRQs for netlink_lock_table() Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 19/39] net: mdiobus: get rid of a BUG_ON() Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 22/39] net/qla3xxx: fix schedule while atomic in ql_sem_spinlock Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 23/39] RDS tcp loopback connection can hang Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 24/39] net:sfc: fix non-freed irq in legacy irq mode Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 29/39] net: macb: ensure the device is available before accessing GEMGXL control registers Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 30/39] net: appletalk: cops: Fix data race in cops_probe1 Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 31/39] net: dsa: microchip: enable phy errata workaround on 9567 Sasha Levin
2021-06-03 17:08 ` [PATCH AUTOSEL 5.10 35/39] bnx2x: Fix missing error code in bnx2x_iov_init_one() Sasha Levin
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=20210603170829.3168708-5-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stable@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).