From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "MahnurA" <s.mahnur.a@gmail.com>, <bpf@vger.kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>, "Song Liu" <song@kernel.org>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"John Fastabend" <john.fastabend@gmail.com>,
"Stanislav Fomichev" <sdf@fomichev.me>
Subject: Re: [BUG] KASAN: slab-use-after-free in bpf_skc_to_* via fexit on sk_common_release
Date: Tue, 01 Dec 2026 03:20:14 +0000 [thread overview]
Message-ID: <DN92M6I4LTVS.G22ON77JZ6KQ@gmail.com> (raw)
In-Reply-To: <20261130151212.504961-1-s.mahnur.a@gmail.com>
Not a new issue. I guess it's time to close it.
How about something like this:
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 50b3f8ab9720..5562e5d746e7 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -1739,6 +1739,7 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
const struct bpf_prog *tgt_prog,
u32 btf_id,
struct bpf_attach_target_info *tgt_info);
+bool bpf_prog_args_freed(const struct bpf_prog *prog);
int bpf_check_ext_prologue(struct bpf_verifier_log *log,
const struct bpf_prog *tgt_prog, u32 btf_id);
void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab);
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index f2d2f4fdeca5..0e400d63a994 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -7285,6 +7285,40 @@ static bool prog_args_trusted(const struct bpf_prog *prog)
}
}
+/* Functions that can free the socket that they take as an argument */
+static const char * const sk_free_funcs[] = {
+ "__sk_free",
+ "__vsock_release",
+ "dgram_close",
+ "l2tp_ip6_close",
+ "l2tp_ip_close",
+ "mctp_sk_close",
+ "pep_sock_close",
+ "ping_close",
+ "pn_sock_close",
+ "raw_close",
+ "rawv6_close",
+ "sctp_close",
+ "sk_common_release",
+ "sk_destruct",
+ "sk_free",
+ "sk_prot_free",
+ "sock_gen_put",
+ "udp_lib_close",
+ "unix_release_sock",
+};
+
+bool bpf_prog_args_freed(const struct bpf_prog *prog)
+{
+ enum bpf_attach_type atype = prog->expected_attach_type;
+
+ if (prog->type != BPF_PROG_TYPE_TRACING || prog->aux->saved_dst_prog_type ||
+ (atype != BPF_TRACE_FEXIT && atype != BPF_TRACE_FSESSION))
+ return false;
+ return match_string(sk_free_funcs, ARRAY_SIZE(sk_free_funcs),
+ prog->aux->attach_func_name) >= 0;
+}
+
int btf_ctx_arg_offset(const struct btf *btf, const struct btf_type *func_proto,
u32 arg_no)
{
@@ -7680,6 +7714,8 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
info->reg_type = PTR_TO_BTF_ID;
if (prog_args_trusted(prog))
info->reg_type |= PTR_TRUSTED;
+ else if (bpf_prog_args_freed(prog))
+ info->reg_type |= PTR_UNTRUSTED;
if (btf_param_match_suffix(btf, &args[arg], "__nullable"))
info->reg_type |= PTR_MAYBE_NULL;
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index facb0d6d2e8d..ec4dd50d2f1a 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2881,6 +2881,8 @@ static u64 bpf_prog_hook_key(const struct bpf_prog *fp)
{
if (IS_ENABLED(CONFIG_BPF_SYSCALL) && fp->aux->attach_btf_trace)
return btf_raw_tp_null_mask(fp);
+ if (IS_ENABLED(CONFIG_BPF_SYSCALL) && bpf_prog_args_freed(fp))
+ return U64_MAX;
if (fp->type == BPF_PROG_TYPE_TRACING && fp->expected_attach_type != BPF_TRACE_ITER)
return fp->aux->saved_dst_ctx_type;
if (fp->type == BPF_PROG_TYPE_TRACING || fp->type == BPF_PROG_TYPE_LSM)
prev parent reply other threads:[~2026-12-01 3:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 15:12 [BUG] KASAN: slab-use-after-free in bpf_skc_to_* via fexit on sk_common_release MahnurA
2026-12-01 3:20 ` Alexei Starovoitov [this message]
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=DN92M6I4LTVS.G22ON77JZ6KQ@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=s.mahnur.a@gmail.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.