From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796098907; b=hiuACEt4umc6UYeYpmuSvj1+WOAbf2blzl8i725folg1/QEMsNRI/2wcAioEHnpew6W1 +VBxMU38ifj9ljilsSdiKipZUj1qhiSS5i0+TzS5C1Y/4raJk0oi0bxXwyH30GoBITxZv wU6YchPcfz/98Lz16RNIWF5JwzSa5N2hskQOYC9YK/58g+aCdpuY8hRxzgGWRVVxLJ/ud uGU836eS1K+YPbau8JNjknjMw120rzX+ucqx6ZsegJbUNhtYrmvw/e/Eb45c1EEHPBquk 2yXT62Wkq9jhoPYY4ZerO68xnT70AoyuW8O25jwiVNkueVjZfRSKXfQpLCEh/mDOQfg== 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-Forwarded-Encrypted: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=lru8JyhwMRhghz0wMwL7q42BV4fIwk9HEfhU0KahblUD4NCe065aiqJiv+7NcNNvslnY YVDHxJuehaOyfj94GwvZeBov1xQIp2y9CNaXtYA+j9tlXWGDovL2eDpIxSh7sK4aI28Bc U6rU0iftKJjm4XhuH9XLyasj2x1dHxTXw0laCEf8Xora7iV1yvmlZ0YKJIHGYAfNTQxfu vuR7wlyj5mwnrR9q8rCG8U4WthASS18g/3b2rGyF/XdwuSdiY62pesyMCcXwlDJDBeBLa Ja5vKoSSofbKak8sp2nKEv2sUqLR7YKfvPiaJnWjS1ZRR3vr9HQz2UoEbEgYb8TzJFQ== 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.182 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 CEA96606A320 for ; Tue, 1 Dec 2026 04:21:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CEA96606A320 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-f182.google.com with SMTP id d2e1a72fcca58-8b3577deeb0so5063151b3a.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=bItd9/ejOoVqo/pyKsMTQspKpbwKO+yG3HDOWK0UnlzVPoq9iEj5cDsmsQnk6VyO4I srG9CpvTKY1bH6Shih6D6rtBjBmgJtwqlKpfuFBnuQb1IclcbdQAerB/gJetr8jMgihE 3EAg1XiCdkKXeNZdb9UY3onmHhWQgdol/plynjxgOcc3ZV0ogyIDfmouNnVtJ3WlnLez GyuP6gNUPIdbLlA+hrT9DHFmdCxMyuUpUydCPQB/chc+SLygv+Y7R6ew5SgD5zuMRnWP rhwRkHzFROKxhcSiksrFExMvuACsWt2177nTlZp6SnKeP08nhOMUUm+qfw5soYXrSs/y ODZw== X-Forwarded-Encrypted: i=1; AL+hErHwypPDJfvWMZvLliHD05R56vigWt+b3cK1LIHBAHX6tSovwfeHhcI3xCNeJh0cLYPoHUxGmvFRpPN3Ruw=@vger.kernel.org X-Gm-Message-State: APuU4Z816Hpp8nTYYWbl8vLXPC+JvSBOehT2xhzCYqpubd8FsvcYiZva WVbMKwGG4v31MBdMmQWVpWTiTIqjl8SViae2nhwlDxJLV3xwtpX0I9cc X-Gm-Gg: AZFdTZewd2Os+aU7arqGOI5uSMDWEa+YvRw7zGJNUp6nvRH+WliX+Sutw4dB0MEbhMr N65nxc9Bar94+mQvFOYHUE+BfEZ2wYXNJgXesBfeTJhoyc8oJiqNetpXxJCWTKBPmwCGmrETb4G mwpdhx+HXJD9siE/01NjzGLxdXSGMyLvyuBgAlV68XbYrS3kwTnNG5WxZ3SBgZkatfmq53TaV/2 OZ65sX4tF5t8katNfQpJyk9k8FlBw44FT/baeT5kpG9GhdylramSqkuKlFcCowj+RFTAkZ/CtBs bGK6X+Pe1dAjDoC1xRkk9LQZHIpNibxUbF1DZt+XWv/JuYRCVXBH4O+hhJPQK7QHsJaJW88XXEI dn+iggFqvtmXFVxrghpB2WvNF8i3Jw5xEWRuerZs7JxWE/kWHTBIGHHzEOrb7v8a/n5a3Z/fwwY xPMYCfqMJCfycNAOJlKcPvX3Ioew6EEPMk2E0m8Ot+ZWShonVRhl9gNBFsFQgLY0b2nN1VRpgbA MktxCVFS9W3Wb9rmqhbZLo63tpau/lQDcGLYCECw+4V1G+WGpi9r4ssQt/v3u7K2h5XcBkGTHZF cO+oAn3l24N6xYZbP7rrFfBMkWfUYQks9O6FdpE3MXOnE0+59ZH+0UspWRITnhpJDlrILhX1qF5 Bu5AJ5KY62eJc1/XQh3XyIZ9BpGj8JG582AkYtvJjT9sIcaP/CS1IMq0= 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: linux-kernel@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