From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=178.21.23.139 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795946078; b=mjc9xp7DnmstBI5+oXYj3UVPj2OR6DLELuyjjxPWEoBXdTeojE3AT9cWRkrBGEJjEUxA hTpt3tJcPGvyZnxVlOoEy95c54Q5TjfdrI5IHNqUaTB8Vr/PrfTWqwBgG45T5Z247FkXF hMyUrNYMgiL9ypuTmKZ2OYGFfU1uXRkR8PnG3TRS2pJ3WiroLu49thJ5DuOxXYCeahOsR tZTF1mpyXbcEQ4wwqrpSelq0d8IyIRmWdpk4z2/cYaivBvp0+DOB9GbyMxXTVU/GD7W/o Mj1Sz+LM7TpupvjVsE/A2QQQHoybKe27L0+SWUT69pOcXBnX2ITUG+4934y3dDlxhXA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795946078; h=DMARC-Filter:Received:X-Virus-Scanned:Received:DKIM-Signature: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=/xgAJwB2XrMFf1XH5Vrn8K20vFycWmm4ztFZm1H+uKI=; b=fvMQg4VVSwCEldSYU9ud0S62JA3NKQmZc/jUZkzRbVYbr9dSeTTDxarGrxnz6ksFx43O FRqTX3P+XoIkWPLWeOhznn4FhrgvjkhpZToWBgUN/ZwOefGabdMcTfAgn6reATfIaqLzq qFvrIW5b8YChj7++4INcTlGc1oiDdyJHL/7ysV8ehfOGXJUuDyTTuODDCusm6eRMf+0I2 +4e9xhd6/mAhFOPU9bzljPmun36gdz5wRtco6fuk0PTwjGSQIal2cqt+CxPAdvEf4UUPD YhdjcqW/nvlmnm0LTzeIgYu1e/iDPcFixCKqB7EgmuOK7LMCBUzu9JJf8uhsF96hZ3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=disroot.org; spf=pass smtp.mailfrom=disroot.org; dkim=pass header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b="CkE/wY08"; arc=none smtp.remote-ip=178.21.23.139 Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D695606A31C for ; Sun, 29 Nov 2026 09:54:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4D695606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=disroot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=CkE/wY08 Received: from mail01.layka.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 5664C806DC; Sun, 29 Nov 2026 10:54:35 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id M4kmpQcmlYQs; Sun, 29 Nov 2026 10:54:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1795946074; bh=MV4GmX7ejff7vPXiqVTwAk1tZgaFmWsl1FRhTVc0HdM=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=CkE/wY08OELElXqq4oQK93L/l4YkvivSdfDNScV9tAIh32X+DMVKfqhtoGgiSmGuv BM5yg1vv0uOBuyiPnNamzH69EU5ssXpywOCHs6Wr/pLaCsjeyDVcJmn3s/UmoFCZcV OsPzkqWydbEES/WodRFghQ7JyfK+XxwtnCTPWVvss3/M5mnTq4NgKVZ1cSSxpoSSDl kWOnHjKOX/13qmeUUnib5R0N6uVZEUYrk2rtKKOZr4PLOsZPslE0EA/5mC3O50D6T8 fWGh5M1Oz7zSNAUojpLmgoxmTh4c5oxDhJH2e0UIcOYt6XT5p+o6rYP20tsww0XJe6 ZmwSgsP3wGVGg== Message-ID: <057537e6-9ae1-4918-9052-0589590892c1@disroot.org> Date: Sun, 29 Nov 2026 09:54:28 +0000 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH sched_ext/for-7.4-fixes] sched_ext: Fix kernel OOB memory read in scx_bpf_x_bstr kfuncs To: sched-ext@lists.linux.dev Cc: tj@kernel.org, void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, linux-kernel@vger.kernel.org References: <20261129093555.3890002-1-maghasi@disroot.org> Content-Language: en-US From: Masoud Aghasi In-Reply-To: <20261129093555.3890002-1-maghasi@disroot.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 29/11/2026 09:35, Masoud Aghasi wrote: > For scx_bpf_exit_bstr(), scx_bpf_error_bstr(), scx_bpf_dump_bstr() > and scx_bpf_sub_kill_bstr() kfuncs, fmt parameter is defined as a > dynamic string pointer which could be of any length. This causes a > kernel out-of-bound memory read inside the bpf_bprintf_prepare() > for loop, when passing strings with lengths higher than INT_MAX. > > This patch fixes the bug by adding the __str suffix to the fmt > parameter definition so the verifier could reject invalid strings. > I prepared the example bpf and user-space programs that reproduces the bug. bpf program: ```c #include struct { __uint(type, BPF_MAP_TYPE_ARRAY); __uint(max_entries, 3); __type(key, __u32); __type(value, char[1000000000]); } strings SEC(".maps"); void BPF_STRUCT_OPS(bpf_sched_test_str_enqueue, struct task_struct *p, u64 enq_flags) { __u32 key = 0; char *fmt = bpf_map_lookup_elem(&strings, &key); if (!fmt) { return; } unsigned long long params[] = {}; scx_bpf_exit_bstr(0, fmt, params, 0); } SEC(".struct_ops") struct sched_ext_ops bpf_sched_test_str_ops = { .enqueue = (void *)bpf_sched_test_str_enqueue, .name = "sched_test_str", }; char LICENSE[] SEC("license") = "GPL"; ``` userspace program: ```c #include #include #include #include #include #include #include #include #include #include #include static volatile sig_atomic_t exiting; static void handle_signal(int signal) { (void)signal; exiting = 1; } int main(int argc, char **argv) { const char *object_path = "bpf_sched_test_str.bpf.o"; struct bpf_object *obj = NULL; struct bpf_map *ops_map = NULL; struct bpf_link *link = NULL; int err = 0; if (argc > 1) object_path = argv[1]; signal(SIGINT, handle_signal); signal(SIGTERM, handle_signal); libbpf_set_strict_mode(LIBBPF_STRICT_ALL); printf("Opening BPF object: %s\n", object_path); obj = bpf_object__open_file(object_path, NULL); err = libbpf_get_error(obj); if (err) { obj = NULL; fprintf(stderr, "Failed to open BPF object: %s\n", strerror(-err)); goto cleanup; } err = bpf_object__load(obj); if (err) { fprintf(stderr, "Failed to load BPF object: %s\n", strerror(-err)); goto cleanup; } struct bpf_map *str_map = bpf_object__find_map_by_name(obj, "strings"); if (!str_map) { err = -ENOENT; fprintf(stderr, "Failed to find strings map\n"); goto cleanup; } #define VALUE_SIZE 1000000000 char *value = malloc(VALUE_SIZE); memset(value, 'A', VALUE_SIZE); for (__u32 i = 0; i < 3; i++) { __u32 key = i; err = bpf_map__update_elem(str_map, &key, 4, value, VALUE_SIZE, BPF_ANY); if (err) { fprintf(stderr, "bpf_map_update_elem failed\n"); goto cleanup; } } ops_map = bpf_object__find_map_by_name(obj, "bpf_sched_test_str_ops"); if (!ops_map) { err = -ENOENT; fprintf(stderr, "Failed to find sched_ext struct_ops map\n"); goto cleanup; } link = bpf_map__attach_struct_ops(ops_map); err = libbpf_get_error(link); if (err) { link = NULL; fprintf(stderr, "Failed to attach scheduler: %s\n", strerror(-err)); goto cleanup; } err = 0; printf("Press Ctrl+C to detach.\n"); while (!exiting) pause(); printf("Detaching scheduler...\n"); cleanup: if (link) bpf_link__destroy(link); if (obj) bpf_object__close(obj); return err ? 1 : 0; } ```