Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796393947; b=S0gjHFrn0o7yWr5BKDr60jfeSGrMRGjCDfbmazMQT2NLpy7i7jJyxxhfVs8KEXvm/qTB RH/iGe/brr49enyA3x6+k9bhgvvAxBGni40pSzZL9CQ7q6zMtQ/cYb/ISsvhY8ZL8hn6p 6BXDGsAlotIXLIJewENWM0WoH4wI60owbwXOFpHpCLO16dKMAAlg4qW5Q6GfORRWuzFgM 2vJNZiUHtDZnKaJ0YkYXVDah+F+M3bTRdjB61mgvzy6uMjTKCEuMksSsdh+mgN8gwyPil EZkpJDuy2BkJytFwmYk82hMpWRQTuhXR3nWE/HWIyPaHVgwUOK1A1d5UM211ZX43DJw== 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=WOfPoX4x4Q3at0QIq+JBhcTm33j0c8cuCPW6LhGZUbhBX4qL+dICwXdbGlD3bWXJER1v HPwwwEpA1e5Ov3yeMdIHVRb5ZhUr7IxjhrYkh0t6TTEbnZLylZl+LXUP+OqodumDKuMID 2/fem+3Ujx58fBnyn3VNGFpwh1DcBzuR33jS78TtZuZoH9cIAtVkK6y05ge0MqI0+xXn9 o/ye5Cqh6XuZP+Q55gPVcYabFSY4kCbZ1jeB47sggjz2vBJQbOns3d/LwF0LOQp8XQ9S9 Z6LNYvaM6uxlu0dy2zdvasTdGfalzeTPxZmcw1zM3MwImtjyzburH4uinTXJo5bgRDA== 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.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 467A0606A32F for ; Fri, 4 Dec 2026 14:19:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 467A0606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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 Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4bb606491faso4558925e9.3 for ; Fri, 04 Dec 2026 06:19:07 -0800 (PST) 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=bPIM00AIWc2G2cdWkJlsh0IDwbPYOxva4sysHgSJYBIspzJ8EfbxH2owUx/wpruf9g ANUU4QUn9/eozncyFlklo5fduw9Y8zO1WsfVyDt1hTJFIU7A8gJ274I+QZZG52DwDI8W uSQWi2Mj6sPxn9G0egjYr4rOmw8vkfZAAD6t97CGoM6cvQBB21zhKnisDWZ4+fvPOmDp z4x6wUpdLEEiVXXX1it0jOVo1ZR/5bSGpNc1SqZ0S/7peFNV4+M9rTU9LwlbSQQMk3/g 3udqxIQT5I2xVHEJXpvFsn1y41tlw7ISoOsN9lguAKeaEZpy5WPQFSeOb2ilRKtYMJCE CVoQ== X-Forwarded-Encrypted: i=1; AL+hErEyLRFIJ2yX0W2VMeTDKWhl1Arh62jPA0utuk20qMq7WHYXECpW7uwVhSuzSgXR+VdS8iQ=@vger.kernel.org X-Gm-Message-State: APuU4Z990vWvJ2ad4YZZcSvd4t6vfHlgt+MGKNq9cSrCLxPkm9p7vCuT VL487/sjdtZ5GrMEmQvKcIiVREn/iI8js/GhIdl323hWywpAryNRyHkB X-Gm-Gg: AZFdTZfieau85N5rYhHd/9FlP72EcXXd9qnOU8uyG/RbEUFye1Nxtdaw3HMnwYLQdrE HCoBSAOti/NlExAToismxLlX0r8v1GDSTovOrXArz3lGg9GRCRKMYX4K9UownHpjmyZPrApDuYG tnlf29jmN+V2Taq5m+G+cudRxyFi52LMg2cD70MqzZowTKx0CGQoh2z8EfiQ53wimzGCAD8liBr bUfD4DP/pL8Wt1bA+l+ev7FGC62YLPFNL1BCB9fdpLxHYHFgsk80rZN25nVXi6kd0FRDyS2707w SL4QXlkwY/PHF5m7b2lbF90SWrG84MbLYnYUTyzHAzfv1OVLis46gVztopA5M6VU5jU15yo/KPr 3fJy/gyWnpAe358l4z10LXSvJqHFez85TK66Uzvz/DUJWool1k8ImOM+c2XegVRZDqhTfBAlZv9 8AmNF5Vs8mZPF3L/UmpgIcu3cegglvFLxkhCH2XZg8TU+BzmFgvhdF8BOlS5amYK6S2G5YC6u7D 08R/foT189hj2DRWMdfLzMDkEdBQ8uJesk/5pNn1XiC2PbQ6r+B8yYjxNN26QeyDrWxtgFpdVOI jwHTBfeZVJLPzSnRckCMSnzhFcG5F86vnpWt5rJL 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) 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) From: MahnurA To: alexei.starovoitov@gmail.com, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, bpf@vger.kernel.org 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 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 Message-ID: <20261204141902.605584-1-s.mahnur.a@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.