From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796098907; b=YsEzsmpqmuNwybj9SAbBSbV44GwpUxuGG8HuL4dzzgRnRiQxpU6HE4wRDFdoKgvuzPBH qNERA2FodHxVh0wxnEFiRkxVKl1suM51fxcS5D2ohCT3w5uLSLASxZ0mgqnQuahYjHohg fxkpR4tXX5iSV6ko8dHhrH5tyzRnlpgXCp5+9tRV9oRfD9dBIcF0ubNfIay2zdDjdoU5S Wognzsu0MtgC7fYyzV7ENU0qJGvvSOoONu6Bckcm1sZ25OigwAJ/TWQif5QYnY1pG03nB x7bro1q9ZLKqchjFMvo1RY0P0R1kbwh06KVu1Awzir1iLG78h59b8Wu1h4aLn0CuSTw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796098907; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Content-Type:Date: Message-Id:To:Cc:Subject:From:In-Reply-To:References: Content-Transfer-Encoding:MIME-Version; bh=/DnStxuhVL1DDQtYZHeuHMBoZJvj9VScKGuo/tWISHQ=; b=4p1w/2zHlV7XssrJ2Lh5SslNjyzMds6dIOT4wuDlTjKmCwjOV3pJvc3w9uiDWnD8Ci6+ AUKJ4dd/1H+6LvPmLDQepfleWQltGmLplfb0W7ehLSTHGJOfi6luJ41JGx6+ilTuAUo3G jjt3sE3AL+jVw04FNrqpXs5ELvlCuMLE5nKTRVmVgYyOO7MHkq5SxNNLoTPNz4GH2tR0Z wlxgRInykmclSdBV/bTX1F+B6iPnICQR0d6/x34lol76ahdniXhJuf/h+GWO9LSiU4zFq yiQlX/4Ew1y6iNeqsO8bCd14blUk0WkGWmbrue+c11ch663RJ1dvI8UO9aw2dSFua9w== 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=dMsc8EiX; arc=none smtp.remote-ip=209.85.210.181 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 CD855606A31A for ; Tue, 1 Dec 2026 04:21:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CD855606A31A 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=dMsc8EiX Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-8b3577deeb0so5063152b3a.3 for ; Mon, 30 Nov 2026 20:21:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796098906; x=1796703706; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:references:in-reply-to:from :subject:cc:to:message-id:date:content-type:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/DnStxuhVL1DDQtYZHeuHMBoZJvj9VScKGuo/tWISHQ=; b=dMsc8EiXolvb7kcqdAQKP0bSZFqglEP6RnZG5rYxYpJAJBLrslIV/QzUuTzb7Fsudl HvAHRfY4xx8BfLowf8pUvI3IWTXafzhHXsQg8o9KoZn2WeIok0G9Kk5KU9NtGH2rzu+l BoC0kXPVNZgpbir+T2J8Tf59l3AXUegiDoL67Z9Slr4AWW7t4T+zJZurmZE1kAUWGqeX CiqKa68PHPr1v0sBDQWIMnMO8jW+GC0vi+Dy6Ktu34PkbH6VPvsCSV51M2k1RDh1UTQq nNKXaekc0yXN6nYBIXJz8NxhQbBToVwlmxib9zlyHYXVCi5yBVL0qR4tzrnRa1HhybbJ WFEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796098906; x=1796703706; h=mime-version:content-transfer-encoding:references:in-reply-to:from :subject:cc:to:message-id:date:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=/DnStxuhVL1DDQtYZHeuHMBoZJvj9VScKGuo/tWISHQ=; b=WTtpLNXYvd/6wDeSXUv4SrrtBRZpGA5MS0zoITOjy9mO+m5LyyQmPrc/dmT/dJmALv F3XTvzhxtrszfE3W4cV97MhWOBUZPTWYuJnS/Xv+IAF2r9SGfGK3aZEQMVsloNA0fhgY Zvakbeg5ECgXfKhz+2sOZVQxgvyigj5fQqHgG9mWyDzvSa6EGORSmMw5wf/CcQzsNsQ/ Nb01qolgbRThOl2QN/jjdCZW64nN8kVK/uWmlI/IniQSW85MnEfMQaKw+KSdxOmBiarx scdaWpoSsIy/+O2oj+gmKXsys+BGXCNyQGXUBNyppz6BePfpqtcmYIxvtRw0gAFDlZYq qUuQ== X-Gm-Message-State: APuU4Z/PsL3gOyf4tr8AwoWeRzUJMSnmXTeqJRclG4tD8cEXAVRDJpWs eM6flzz4veo04/pNOPIJN/S+Ka2HKuhKu49+bkpfyDQPZmkq984CuFwf X-Gm-Gg: AZFdTZesQanu5/99NirhOmBVYSpkAoDg1UiDktgstYn/oqg03MZsP5RymNd4Oy0YO2Z DEhXIsCGDpiHXVM40GlouAWdrRRN61x+t+foD9KxKII58tHAWTGG64HAzLrRvOo/LJTDq7709gI PM8WC7PZ38aVhbhOy2Zroi37x3uzu612hiO53oZvGo2lx9MkIFEIzwhImNdWuFOXy9iRSCgKSH2 oFQ2pRdyNyoM4yJKhVZVsnUm3RcsBepXnZstrpViHikzu1lF28f1qctRGKn+7UINlJJl/bOwxti 1anw9N9zkBQrAEwDlBdsvgCjIWXpXR/6f7PmfXIKa3GJ3vC9hr2BHXetuDVE+N4yFBnukOB7Pz3 mA5PlpxGTPa/9ErbqzVa803LTMvxC0G6HJH9Vd0SQr9qXUJ4DBIaSDQRVUd1EeTEa57FKJLy8/u 68I0GQpv8Xr2a6rT595l0o+CcRRMrYnlprhDMzjnpoN3OeDQE+qkQFrSmZeGmVVvtakmLXEvup/ TgFBi65LG+C61RJoGB2yIhRTP4NCIE4mAi8222kwH9RBHBuTkdXKKLj5BbX2aGwwVzq12gWg6Vj nQxkSqidFq+vAQqcGDBHHwsojkOPYvXAJe+ndthObmq7jV/xlMqBHMIU8OCct1QmNVr0SD3UaNq q+grDZ2LX8oe8uoWLAAetSPFKMIswYpEhAZfKo4H7zPtg6xK9YoeEqhc= X-Received: by 2002:a05:6a00:b56:b0:881:8b53:f64 with SMTP id d2e1a72fcca58-8c87d9fbdd0mr33369932b3a.59.1796098905894; Mon, 30 Nov 2026 20:21:45 -0800 (PST) Received: from localhost ([153.61.198.255]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87077bff6sm18805448b3a.3.2026.11.30.20.21.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 20:21:45 -0800 (PST) Content-Type: text/plain; charset=UTF-8 Date: Tue, 01 Dec 2026 04:21:44 +0000 Message-Id: To: "Siddharth Nayyar" , "Daniel Borkmann" , "John Fastabend" , "Andrii Nakryiko" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" , "Ihor Solodrai" , "Quentin Monnet" , "Shuah Khan" Cc: , , , "Anton Protopopov" , "Giuliano Procida" , "Neill Kapron" , =?utf-8?q?Thi=C3=A9baud_Weksteen?= , "Maxime Ripard" Subject: Re: [PATCH bpf-next v2 1/4] bpf: Support struct_ops with object BTF From: "Alexei Starovoitov" In-Reply-To: <20261130-lskel-struct-ops-v2-1-8b76e65073ab@google.com> References: <20261130-lskel-struct-ops-v2-0-8b76e65073ab@google.com> <20261130-lskel-struct-ops-v2-1-8b76e65073ab@google.com> Content-Transfer-Encoding: 8bit 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 On Mon, Nov 30, 2026 at 01:44 PM Siddharth Nayyar wrote: > - BPF_MAP_UPDATE_ELEM: When local_type is set on the map, accept a value > with the local struct's size and layout, validate member types, sizes, > and zeroed padding holes, skip zeroed members absent from the running > kernel, and copy each member into the kernel struct_ops value buffer. > + const void *src = data + __btf_member_bit_offset(t, member) / 8; > + > + if (__btf_member_bitfield_size(t, member) || > + IS_ERR(btf_resolve_size(btf, btf_type_by_id(btf, member->type), &size))) > + goto err; My diff had this bug and the next one, sorry. The size is compared with the size of the kernel member only. Nothing checks that the member fits into the local struct. btf_int_check_member() bounds an int by nr_bits, not by its size. BPF_BTF_LOAD accepts this: INT 'u64' size=8 nr_bits=8 STRUCT 'sched_ext_ops' size=192 'name' char[128] bits_offset=0 'hotplug_seq' u64 bits_offset=1528 Then CAP_BPF reads the kernel heap: map_update_elem() kvmemdup_bpfptr(uvalue, 192) local_to_kern_value() src = data + 191, size = 8, kern_size = 8 memcpy() copies 7 bytes past the end of data BPF_MAP_LOOKUP_ELEM returns them in hotplug_seq When the kernel doesn't have the member the size can be anything. memchr_inv(src, 0, size) runs off the buffer as well. Reject size > t->size - offset before src is read. > + value_id = bpf_find_btf_id(name, BTF_KIND_STRUCT, kern_btf); > + if (value_id < 0) > + return ERR_PTR(value_id); > + st_ops_desc = bpf_struct_ops_find_value(*kern_btf, value_id); This races with module init. bpf_find_btf_id() sees the BTF of a module since MODULE_STATE_COMING. struct_ops_tab starts with 4 slots. bpf_testmod registers 5 struct_ops. bpf_struct_ops_resolve_attach() bpf_testmod_init() st_ops_desc = &tab->ops[0] btf_add_struct_ops() krealloc(tab) st_ops_desc->type <- use after free check_struct_ops_btf_id() and bpf_struct_ops_map_alloc() call btf_try_get_module() first. Do it in find_desc_by_local_type() before the lookup. > + if (btf_type_is_ptr(mtype) && > + !!btf_type_resolve_func_ptr(btf, member->type, NULL) != > + !!btf_type_resolve_func_ptr(kern_btf, kern_member->type, NULL)) > + goto err; > + err = check_zero_holes(btf, t, data); No need for these two. The holes of the local struct are not copied. __bpf_struct_ops_map_update_elem() checks pointers by the kernel type. A NULL 'void *' callback loads with a regular skeleton and fails here. pw-bot: cr