From: He Fengqing <hefengqing@huawei.com>
To: <ast@kernel.org>, <daniel@iogearbox.net>, <andrii@kernel.org>,
<kafai@fb.com>, <songliubraving@fb.com>, <yhs@fb.com>,
<john.fastabend@gmail.com>, <kpsingh@kernel.org>
Cc: <davem@davemloft.net>, <kuba@kernel.org>,
<netdev@vger.kernel.org>, <bpf@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: [bpf-next 2/3] bpf: Fix a memory leak in an error handling path in 'bpf_patch_insn_data()'
Date: Wed, 7 Jul 2021 04:38:10 +0000 [thread overview]
Message-ID: <20210707043811.5349-3-hefengqing@huawei.com> (raw)
In-Reply-To: <20210707043811.5349-1-hefengqing@huawei.com>
In bpf_patch_insn_data function, if adjust_insn_aux_data() return error,
we need to free new_prog.
Signed-off-by: He Fengqing <hefengqing@huawei.com>
---
kernel/bpf/verifier.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index be38bb930bf1..41109f49b724 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -11501,8 +11501,11 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 of
env->insn_aux_data[off].orig_idx);
return NULL;
}
- if (adjust_insn_aux_data(env, new_prog, off, len))
+ if (adjust_insn_aux_data(env, new_prog, off, len)) {
+ if (new_prog != env->prog)
+ bpf_prog_clone_free(new_prog);
return NULL;
+ }
adjust_subprog_starts(env, off, len);
adjust_poke_descs(new_prog, off, len);
return new_prog;
--
2.25.1
next prev parent reply other threads:[~2021-07-07 3:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-07 4:38 [bpf-next 0/3] potential memleak and use after free in bpf verifier He Fengqing
2021-07-07 4:38 ` [bpf-next 1/3] bpf: Move bpf_prog_clone_free into filter.h file He Fengqing
2021-07-07 7:02 ` Song Liu
2021-07-07 4:38 ` He Fengqing [this message]
2021-07-07 4:38 ` [bpf-next 3/3] bpf: Fix a use after free in bpf_check() He Fengqing
2021-07-07 7:25 ` Song Liu
2021-07-08 3:00 ` He Fengqing
2021-07-08 3:09 ` Alexei Starovoitov
2021-07-09 11:11 ` He Fengqing
2021-07-09 15:12 ` Alexei Starovoitov
2021-07-12 2:17 ` He Fengqing
2021-07-13 23:17 ` Alexei Starovoitov
2021-07-14 1:53 ` He Fengqing
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=20210707043811.5349-3-hefengqing@huawei.com \
--to=hefengqing@huawei.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--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