From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796098907; b=BGSxXMRZanMA+0PAgx6xei3Vx6NVYLSmb7uReg4adu7JKHxIEDM5zocpSLCHC0RdJF2k MbzZF2NIP6urk5KamaPElJXMEiIwDafMtdV3An0lhuwbRkhJkYIwE+sUAw+PM9J/EAUbF Z06HwGpwHNkCWODqH9Nb+w+97RBsrWmmh+0UYhj62bnxrqm/bbRNBOaGOtRafKTum+1Fc PNVK8kdF2Lefi0rZEmelQV601t8oMPhP8FJcAdAWvjhwOWcQiun7SkLUNWJEvgbQujRrR x0fMDlV7Ka22VtgHhkF/0XtDlI+QYkIqlWLrGEjc2MoKokiDuc+59FQZtZY8bVIilYg== 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=MdkH90zLKUZZXv2wStqMDcYRbsSr/gHFKSS0fORiUyowpelsc1LKQM3vu/UBAbJNasx5 PydjjKG8vAmt+g2tqLvEg0hXrSE1tucUk3gFx9xq03tIEdDQu2qhrXpqyETNx8fHig4dG LeRV600rJxctCD1Ah1lUocbJJ8108bpYkLvUxpEwsN3VBTi6IEVcJOuoZOz550oFGQkeu vI5FSovKMSqPBGQ0KphbcI8VlW6a6vwLccOJ2zzHI5aOB4QTgFwGU/Xx7f+LtP5r5ZNrK IGJGghiByfuM1G5mXhUEe05vk3dGIo0eVNpItk7Ulu7Ns+sDvuv3RMtZ9ccrSPDp8Gg== 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.179 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 D4C3E606A325 for ; Tue, 1 Dec 2026 04:21:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D4C3E606A325 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-f179.google.com with SMTP id d2e1a72fcca58-8a06e79e152so5435306b3a.0 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=wRgdIqY8DxBeBMrbxcY1ep4AcxbnAruBckYbbwfjFBTDHUQqtb4wR4onoL4TpIdnMJ 22gdFKesddhVD9M0uhwADai5TA4K83RkVULHcqiAFTe7vzOY+s6TyQdPZEDVdsCYQM3X e1q/3c+bnHeABlM7aUg83c8MsB9IfvXUYS/Opk1CPYWWlI6p2zfUsuqUmaiSjlpjv/ri XKJhcUxdNdW32FTq34hrtXvOLFlTS+tSODl6lw+AG0oTIK2YA5kfblmXy5wlz6W6UIYY qjq+7O72qk0ur73DWTV2cWsmqW2zq7pxha615V9u7Ni7Kkwi2CEX6m2tIC+C/r4LlNMH WhCg== X-Forwarded-Encrypted: i=1; AL+hErEx2wG4VdOKmMZNhXwSRsGGLudG4k8g8TzPXoYfPgsyLKix6H2NQt0u84Ux8FrE+tx1J27PpmQv4xtFRG6y0ng=@vger.kernel.org X-Gm-Message-State: APuU4Z+3aRKM5ZpoYDZri9Tb6ZpL8k32IMf0nw9UbvP10idiCp+vXmHA 33llfcDKiM7DuKIIShyG1+iBjXyhI71MRW9EKck1++Ld09E9HvOud/J8 X-Gm-Gg: AZFdTZdDn5m1JbWaNnTxoEJrKQXGKUcdy8JdPcZjTwhCwgwUN0/UM3zBY4/+0edrrUP MdWypOew4NBKU2jIs9GcP2c2OoRU58sivH6vrl1MH+C6QdyzS62o0jrE9ZJlsKf+frLUlv2CEdd LgO6CywAjtshIrdfm46aCkfJliASVssu495vXSPm1bElWvThcJ3KMRwNUERaCtuyImQejWOpXyq RkCehG+LxGCNChWaZy2Z0lJ+/5jjrM7ePAS6PYUMHteuXFngb+3WYH+UNzosmtbzJcbjbaeZScb 6DRtsJ3f7xc6u4xfk88sLHPKkrCJCPkBBB8424Q7eHx9ggK7yyX1T+ejC7KNDrQnJkGGFGuZoHS DOVlggG6pWwv7jVUF2KLKyBDAHrJVK0LHGsqTxM+Lzbg3Gwc8I/Lf3aOdJ5bg7MTpefC1go4vad XYqDlafcWeUhgYsboejzHAaeQClngUjv74e7EpgWFAJyBLe9L3Kw7hONfsVIPWMNZXz1vj9+zMM cA/nbLg1aQ/1sUC8CASx1vGvOp3oVslTuR67/ck7IfLs+H+ZP5l+LU04E2L4h9hzs76VC2GGNnw QGpEUVLnxsEz+wOxjgsHYFbjutUGzYzt+rS3S0TYl9jbCqm9nAoEkTOQbl2n9S7APMlvU5HJ9Af CDYHWJHV2MMhZRN2K1PFhNXCfSgmC281gnjEV/bxUfY87FfIGrN2otHM= 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-kselftest@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