🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26971

Re: [BUG] KASAN: slab-use-after-free in bpf_skc_to_* via fexit on sk_common_release

#26971
From: MahnurA
Date: Fri, 04 Dec 2026 14:19
100 lines
14643 bytes
On Fri Aug 21, 2026 at 7:30 PM CEST, Andrii Nakryiko wrote:
> +/* 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;

This plugs the hole temporarily. Not sure if this is the right way or what could be a better way. The list of functions is probably not exhaustive(?), and will need to be updated in line with the kernel. I also think that a bunch of such untrusted pointers probably occur in some way with other helpers and normal kernel functioning so it is a bit of a whack-a-mole situation. The verifier is correctly rejecting the program, but now the error message is not clear enough I think to highlight that this is an attachment point issue specifically. An example below:

libbpf: prog 'bpf_prog0': -- BEGIN PROG LOAD LOG --
0: R1=ctx() R10=fp0
; int BPF_PROG(bpf_prog0, struct sock *sk) { @ bpf_prog0.c:7
0: (79) r1 = *(u64 *)(r1 +0)
func 'sk_common_release' arg0 has btf_id 145052 type STRUCT 'sock'
1: R1=untrusted_ptr_sock()
; bpf_skc_to_tcp_sock(sk); @ bpf_prog0.c:11
1: (85) call bpf_skc_to_tcp_sock#137
R1 type=untrusted_ptr_ expected=sock_common, sock, tcp_sock, xdp_sock, ptr_, trusted_ptr_

Verification failed: Call Type Safety: Invalid call argument

Reason:
  The first argument (R1) to bpf_skc_to_tcp_sock does not satisfy the verifier contract: it has type
  untrusted_ptr_, but this argument accepts sock_common, sock, tcp_sock, xdp_sock, ptr_,
  trusted_ptr_.

At:
  bpf_prog0 @ bpf_prog0.c:11:5
  Source context:
       9 | ...
      10 | ...
  >>> 11 |     bpf_skc_to_tcp_sock(sk);
         |     ^-- error: invalid first argument (R1) for bpf_skc_to_tcp_sock
      12 | ...
      13 | ...
  Instruction context:
      0 | (79) r1 = *(u64 *)(r1 +0)
  >>> 1 | (85) call bpf_skc_to_tcp_sock#137
      2 | (b7) r0 = 0
      3 | (95) exit

Causal path:
  bpf_prog0 @ bpf_prog0.c:7:5
  Source context:
      5 | ...
      6 | ...
  >>> 7 | int BPF_PROG(bpf_prog0, struct sock *sk) {
        | ^-- update: R1 changed from context pointer at offset 0 to untrusted_ptr_ type=(struct
        |     sock) at offset 0
      8 | ...
      9 | ...
  Instruction context:
  >>> 0 | (79) r1 = *(u64 *)(r1 +0)
      1 | (85) call bpf_skc_to_tcp_sock#137
      2 | (b7) r0 = 0

Suggestion:
  Pass a value with one of the accepted pointer or scalar types for this call.
Technical Details
Message-ID: <20261204141902.605584-1-s.mahnur.a@gmail.com>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377407-linux-kernel-netdev=dewy.ru
References: <DN92M6I4LTVS.G22ON77JZ6KQ@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377407-linux-kernel-netdev=dewy.ru
From: s.mahnur.a@gmail.com (MahnurA)
Newsgroups: linux.kernel.netdev
Subject: Re: [BUG] KASAN: slab-use-after-free in bpf_skc_to_* via fexit on sk_common_release
Date: Fri,  4 Dec 2026 15:19:02 +0100
Organization: Usenet Network
Message-ID: <20261204141902.605584-1-s.mahnur.a@gmail.com>
References: <DN92M6I4LTVS.G22ON77JZ6KQ@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2782174"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:yCUN39bIH7eK5cca/j0ulaqd7XA= sha256:ovw92452TRDaNQc6X5UFCUnvAN+Up9flnMXOKDrhADc=
	sha1:wOmdsVzrH60hbRlA+0JGjDF7fGU= sha256:sRsPWbQ+g/Nk0jcv5s/7PZ0XGCEdG0pqyJBK4AI2v8g=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 13B1E117C23; Fri,  4 Dec 2026 17:19:30 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.297
X-Spam-Status: No, score=-3.297 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.001,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 4BMqS5QCLIKh;
	Fri,  4 Dec 2026 17:19:27 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-377407-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 5E294117C1C; Fri,  4 Dec 2026 17:19:16 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id EF7FC2B9CF; Fri,  4 Dec 2026 14:19:12 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796393948;
	b=jhJSXh8z5TifzQQGU7FrbBg24I5xGuCpDNKWn0NKX5W/Z14R1zaiHx53/2l8+6/89N15
	 b04XJLR1BymnuxYvhvb8QjfLBC4iGiTwQ5yqcAzIjPR/EsO5EhXNy11xZlKDu+WcJKNCy
	 z+kASHEHZsnfyF+b3BxnmWYGhclfl2ifiw5uLJ5TAE32DGoFKADx1+DXBiTLMdC2t0wHo
	 O+5/k6TWCwl71przjJr2mvJRlGG+Bzwu7eil5CdsZ8WjhT33PNVFmidKH9Qaop0XXPpTo
	 xgZCFK03CzhUP9cEUuoayVqqTpejQX8CGRwH0casFQjEalj6qoELHNuNtcgCOdPbPcg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796393948;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding;
	bh=sEvQKqYs7/4uCVbMQ9qEmjEtrxQ91k/h7PNK+Isj0HY=;
	b=E+bDPn4gARXMsoRxFjYx43Q4y1r6pINhiiZ8YYSz3rV702OxR+3mhaB+88V6pDtQHdga
	 PgcXKCwOq4MAYBVnU++OOKgym+o8hNqWuPKsSxCOFw3pONWyJ1XSGPhPR+Wm0mhkgv+rh
	 Sb3BNDuHJj6/f/0cXizyWv0OczQyEuxUCyy5Dr1wtq5NyJj60+JQYeFSA9Qcgnun1i1Zs
	 ctzMVV8upUiEZ/Ttqsl1Is45ZzREIgvqT3X155XqHTVMAsRtNZORlNRBzd1Fv3PIm6CKX
	 +SEPiRHo/7kCM+pzI9PmFroI/4gJJ2mQRFsvKA3oZh8x5SCkVTvYVB6ge8iP5VEV4bQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=vaHQtzGE;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 808F1606A32F;
	Fri,  4 Dec 2026 14:19:08 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=vaHQtzGE
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.49
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796393947;
	b=aGwn0PQSnHFfSaSJHd0iHUCSHI8lWM2OeG7IIVrzQ/3i/vkioPrCTVZFZTwvWp80SliG
	 Sk9wEdWGm6w48BA6DPwOGl7b/N/zdy3qAxWjDcUNLryotkHI7ECwvMlVG0knMVRbbKmMa
	 RstzC/bWlQAsrVD9s2lEGwRdzSTkSR/74tAoof08Vnr9g3q0g4ahvqZYCI1pp4tKuBuJy
	 V2Sw7cMSY8JXnlFpnngNOeYEPACRX6wuTlXEbNe8ILhW/H8NC0CeMVNvgUKHFen6tif15
	 IchTJoIuDDZRMuqCUtLRUM1BhzHdxs7EjSwwSs3ACaOmQByEsvdGiUN5U9aRjh0p5hQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796393947;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 MIME-Version:Content-Transfer-Encoding;
	bh=sEvQKqYs7/4uCVbMQ9qEmjEtrxQ91k/h7PNK+Isj0HY=;
	b=icsXGtFX31QVswpYTgdC6r4SNYZZDDQ5I8BBi3KWgPzq5HZsZjA/q5bh5f22hFFhfG3r
	 clr30xw2WbqZLpr+/P0r71Bgnh5ucrrdmQffWhusgvuMc1CdtCcg25Un6bHjVgwNNhrqp
	 t4beM7r96ADyAZ6VwkIcD9gPKV22HcYoykrb3o3mzQ+3GcFyajpnskQiOYbZsX1viuMvS
	 OqTAzzk8Ew2TFpkMk3XGtz7jSpRDZuFsWbb5f56mp61xunlAQODlTC7yiyCz9XNxtKMSR
	 vGtrKmqCM04wlVCliF3kwEQRz3IMzc/UE8Hyf+7BJZDAcfdKW+BpUYEmFVOF4lYHsDA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=vaHQtzGE;
	arc=none smtp.remote-ip=209.85.128.49
X-Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 585D2606A322
	for <netdev@vger.kernel.org>; Fri,  4 Dec 2026 14:19:07 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 585D2606A322
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4bb70074ab2so6642845e9.0
        for <netdev@vger.kernel.org>; Fri, 04 Dec 2026 06:19:07 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1796393946; x=1796998746; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=sEvQKqYs7/4uCVbMQ9qEmjEtrxQ91k/h7PNK+Isj0HY=;
        b=vaHQtzGEoB14HFqp35yNNBi54ODSRn/sucqHvRFMDjb8mtpurO8cUt/03Y2MCKHQjw
         k5ctiKOjH2ReWbrwc8A8UZKu2aCP/cP5LcwMFULXgi/Ltp4ZpArXaFCRYthWEHfzsi2I
         FAjEZjnapKiBq9VjDAyEMEiXGaqRDpvR2rIUQVxgKzMXyJp04OXRH32QLV/uoMKR2jOn
         hVPLuJWnj1aJX9Wkz/ZM0XZ1nOd2P8TiJ2/h+em+mynAOwk0uUOD4BbDqUrBQC+ZPtwb
         W9rDP3jsmJdAVzYM95j7mQWbXC5RU3wKOBzSkw21tqyUdxQJ3hBHuQO9FLEgmQ/qgRYG
         4WdA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796393946; x=1796998746;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=sEvQKqYs7/4uCVbMQ9qEmjEtrxQ91k/h7PNK+Isj0HY=;
        b=jyJXwr2jzXc79cahLNOf7wHidrvJvkqJUGDZksVZC4irajOzQ+liXFboFG/r7k7Xp1
         xCWBD8c1Cgrz1j1mJyF0EZA3Fl8du8bXXQp+6psozlKU8opFzqL//vQ2jSsNXo4mbzcn
         vtFNjxPmMJ/KpigBIlJOaKWyVIbT4Q95/+tEi96aq6wNpQmEDrlZ3dv3J8NFcRJEFAJn
         HID6wcKnmh4/2z4zrxVLbTjqvpOmnZj9aqrjaDCcFUKUzFkEInZ0HqTFHQ+44ouOM9CR
         9fiJlUSImwtTSpBDGGMSlEymONem2UUPNzlG2Z59lB6b+Byt9dG7NsFLAhz2MtSaF8Th
         zyBQ==
X-Forwarded-Encrypted: i=1; AL+hErHofeJA3ggDN0yxFEk/OBRQlSViI2Vl2ZRm78LjPARN3OR8jaSwjxodTp7jSI9GP8FELuPMOHg=@vger.kernel.org
X-Gm-Message-State: APuU4Z9eMh4M5+zj7WZEk8DDF7Y407yKRvR4Iav8IW9wK2eyl7kMzf0s
	NOtzVeFFniwSabl1RqKfnIS+kJo+KTj14dCv5cb662OwMz7ul8IH7G+x
X-Gm-Gg: AZFdTZcZWtnSi4YUxcX4YCc9m8B4Jb73fQ3nukLNNazgemDLUPAr7a/ydhN4d5H2U2F
	66TtnDZBwVcQBQ7VhPM7Xfz61XJysRXodNb2w/wsTwJIGXzuThcuub75OJ6e2RyvfVor48q9usu
	8H4NZ5HrVP8V8S5rDBkh4UF1S+UaPlAz0KSbvxyqKiYi3MEXXTXV4TdIdT+0HEP31yWSKEfLwO7
	zzQI/BcR/3BAycjCMx6s7sWyLbOFxAboNJf9s7XxisD6yBFbMIYLIKoK3gYNsAUb/FLEoBfcY57
	k0oRqFEhEMXdhtZrsKfq6htATEgvpyh31j7uk1hcjROMO1Tb51oNLfwo2xdlAW6aVnCASmtud1q
	CmwI0amRbV+azdbeXPqLQVgTWhX2P9ftIXQLqYqgdDFgdmm1q2ZIa/81a6YRMIpvBlPfw7UUgCm
	534CpiX1aEM4iQnYhC3dg66RS1kDw+37OXrR31fX+pU5JSMf1KI5Lg3qNSOU3HplsLkWSqLl0SQ
	2NwGbdSb4PJDS4BD28+YPyRmzptnKUTjZIadQwdpl2Uw1PmX4XU1gPvGkzrLEVgktrhIBP6EQsw
	a1T21baYmUGGbqZkY2yIZElXadILmbSdd7Za5idG
X-Received: by 2002:a05:600c:8888:b0:4a2:1612:6367 with SMTP id 5b1f17b1804b1-4bbeb8cdd71mr32404555e9.15.1796393945489;
        Fri, 04 Dec 2026 06:19:05 -0800 (PST)
X-Received: from runham-think.mpi-sp.org ([141.5.46.6])
        by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea29f9fesm54627025e9.10.2026.12.04.06.19.03
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 04 Dec 2026 06:19:04 -0800 (PST)
X-Cc: linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org,
	emil@etsalapatis.com,
	ihor.solodrai@linux.dev,
	john.fastabend@gmail.com,
	jolsa@kernel.org,
	martin.lau@linux.dev,
	s.mahnur.a@gmail.com,
	sdf@fomichev.me,
	song@kernel.org,
	yonghong.song@linux.dev
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <DN92M6I4LTVS.G22ON77JZ6KQ@gmail.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list