* [PATCH] bpf: fix a missing check of return value
@ 2018-12-20 19:45 Kangjie Lu
2018-12-20 19:58 ` Alexei Starovoitov
0 siblings, 1 reply; 2+ messages in thread
From: Kangjie Lu @ 2018-12-20 19:45 UTC (permalink / raw)
To: kjlu; +Cc: pakki001, Alexei Starovoitov, Daniel Borkmann, netdev, linux-kernel
check_reg_arg() may fail and not mark correct data in "env". This
fix inserts a check that ensures check_reg_arg() is successful, and
if it is not, the fix stops further operations and returns an error
upstream.
Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
kernel/bpf/verifier.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 51ba84d4d34a..ced8cc6470b1 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2619,7 +2619,9 @@ static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
/* after the call registers r0 - r5 were scratched */
for (i = 0; i < CALLER_SAVED_REGS; i++) {
mark_reg_not_init(env, caller->regs, caller_saved[i]);
- check_reg_arg(env, caller_saved[i], DST_OP_NO_MARK);
+ err = check_reg_arg(env, caller_saved[i], DST_OP_NO_MARK);
+ if (err)
+ return err;
}
/* only increment it after check_reg_arg() finished */
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] bpf: fix a missing check of return value
2018-12-20 19:45 [PATCH] bpf: fix a missing check of return value Kangjie Lu
@ 2018-12-20 19:58 ` Alexei Starovoitov
0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2018-12-20 19:58 UTC (permalink / raw)
To: Kangjie Lu
Cc: pakki001, Alexei Starovoitov, Daniel Borkmann, netdev, linux-kernel
On Thu, Dec 20, 2018 at 01:45:56PM -0600, Kangjie Lu wrote:
> check_reg_arg() may fail and not mark correct data in "env". This
> fix inserts a check that ensures check_reg_arg() is successful, and
> if it is not, the fix stops further operations and returns an error
> upstream.
>
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
> kernel/bpf/verifier.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 51ba84d4d34a..ced8cc6470b1 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -2619,7 +2619,9 @@ static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
> /* after the call registers r0 - r5 were scratched */
> for (i = 0; i < CALLER_SAVED_REGS; i++) {
> mark_reg_not_init(env, caller->regs, caller_saved[i]);
> - check_reg_arg(env, caller_saved[i], DST_OP_NO_MARK);
> + err = check_reg_arg(env, caller_saved[i], DST_OP_NO_MARK);
> + if (err)
> + return err;
it cannot fail here.
we have the same pattern in few other places where we know it cannot fail.
I prefer to leave the code as-is.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-12-20 19:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-20 19:45 [PATCH] bpf: fix a missing check of return value Kangjie Lu
2018-12-20 19:58 ` Alexei Starovoitov
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).