From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C026E253B73 for ; Fri, 16 Oct 2026 02:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792117952; cv=none; b=HDxXgsrrT7kPdBNIGs4CUrLzwB488Y6uEM/LAzMlcymkwYwg4t8GFaqlmYYTawesY6arKikNFcYcCQim/09ketXPF1deWml0EKVcrfv8R6M3pRTIRc18HK1t4Efs8d7gZvH0mK6ZVAJBE8HLtquw+NPPOTPHFiyUrBfH26i804E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792117952; c=relaxed/simple; bh=Jwbt4sna4q8SKqLdUWxKiDuVxC9GU3p1BMahIzU/F2A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oRFQt2f305vKf6FWhe5+NMY/F4nmZN0IevAZrZ2VQ7IYajmJs441q7WiVqekIx2mRNT9GSzApVpIXAjTU47YBUhPPHzp1KKwfR7+JfHhi7B/j91XHfGt4UkXpaTmZ2qbaV6N+WN9Gqlt6blrXRJcfJjoBIgRKyztmagugGEV63k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=ihfPfg1D; arc=none smtp.client-ip=74.125.82.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="ihfPfg1D" Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-17bc533fda3so2911562c88.1 for ; Thu, 15 Oct 2026 19:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1792117950; x=1792722750; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=B9xTWWD9mfzJtMcAru9lP6tSUbC9S1bscJnItCWs39w=; b=ihfPfg1DOeIlqGcgUwVDOXhrTBDxBBdUFyXNgVcKv0evpDlm0VwnnPBM3v9CkDpfDb b0VFEVLcuo8frMM2nZBGRUu5vr1UQ/kqVZeyrNqND2cSy5Gpt4kxYbeDSmub2frUQTFk 21SHyDQ72+CZEMbzC/LLvmXKyBZe6vyXQK9Sq3sT69TiMa5VsA5hpLice1AmsvNzldAW end3lw5NHaVorHfSVxIiltN1FKZi3nK4y8o8xuy30llVPjrpYJDwd+p0DRDH1+M3Th3/ JM5csGr4LgYDFNvMtt0lJFLpoWFTGLuUahfnje5Itq/8T8PVNHHt7sgirhb4BCMr2m71 Swpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792117950; x=1792722750; h=content-transfer-encoding:mime-version: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=B9xTWWD9mfzJtMcAru9lP6tSUbC9S1bscJnItCWs39w=; b=iZJlNan0Wc+dCj9XDG5jck7qeAoKspUZ28XbD/p60E6tmJ8Md6absbHoNqPp0ALJN/ FtzzjIMCO0C4oS7QJ14+BysF/XPOzQ5jx7GlajHMzyFWa5HorWp3Ay2TSb4UTLoqIxJH 4p5m60/1FZpJrguxyweBqwWWiaaPqkM9O7CR/Qk1gdQBWbvzX8Mqi1ShPTJigBNQ9lct S039d0UuzqgHzu1nxLf1Qq9n4ChTFqZ3KFiRUX9SluA9A9wwz2kQRU0Gi4jN5S1XE1OQ Wr2RpPf8J+dPS/kuPB12eWAbRdVDSxnot1WrxqXIJHVyfSXNN282R/1WGkSXsce1CxRq hCLw== X-Forwarded-Encrypted: i=1; AKwUvBwZ+67imLEfxoXibbPx+Y/MHOZKQBMi7V127VwlHW22SwzZgmmhmaqcknH+V4CPuYxNAPtlQT+WWy0l3FI=@vger.kernel.org X-Gm-Message-State: AFq9FYJ+GbyE35/Qy35WyP9w14O5A3fKNZdBbLBgwbK/yH5QKMqNO6nU CSpLi/5bnwmcNQwgQiT/8NUNZEXXv/a09EHjGn4q1YYaEhIuy6ViOsSf/0KKbuT17a4= X-Gm-Gg: AYBFou2AiOuLkxLDgK7K4wh+O+xZDonMCWoRpPSmu6aTWaNvZKwZXL27oCJAmWHgU9n HEhHAIjGP4+CJNfRdl+uJywXWlraFr9cItfGbY2p+hNWIZYAWSOnACYl2pL0z9MhGjmOOvd65UN 3aX/6s0g9LhSpS6YgUusx6Gtg6ZYb9xVZQWGfLSiR9XUdQRW+pr1t00QD1obwf5sQJTgk4L2vdU F1lxYX+TPboammRhWN0c5G8h3lejeQnCjNGmiDQTHyox/Vpt/uZkxjU3VHSIIaQvjIhg8isTojF aBH9e+rFD8V5DJCOj2K3ZdEhqcC1mPKrqtRAck3AzYOi5LIzqaSPKI0m3ETO6IBLJKOIVSltild sz3aBr1AaMH6W1iKK4vxpheC1n6SdVRMe4UZ1DNDzNg0m1BG1vIadUoakXzyRNUq0f9BEDbezZt TCa5KCbAknFzxDUwqwG6YYIHH6NRoZJv+NF7DWp5dnx1ZXTLIioGylkSI1rPvH9LqdcXgN59RIB cpCGOw/A68zojNNTALwEvD4PTiLu15nU097lLtSN25iN+qnhnM4EW+Xr4nzggv/RPiA9g== X-Received: by 2002:a05:7022:171c:b0:14f:8e70:fad0 with SMTP id a92af1059eb24-16a6090d024mr26389777c88.33.1792117949507; Thu, 15 Oct 2026 19:32:29 -0700 (PDT) Received: from localhost.localdomain ([2603:8001:5f01:8bab:d66:d0e8:dae3:3257]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-360813b6791sm2233692eec.6.2026.10.15.19.32.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 15 Oct 2026 19:32:28 -0700 (PDT) From: Artem Dinaburg To: stable@vger.kernel.org Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org, contact@arnaud-lcm.com, daniel@iogearbox.net, eddyz87@gmail.com, emil@etsalapatis.com, ihor.solodrai@linux.dev, jolsa@kernel.org, linux-kernel@vger.kernel.org, martin.lau@linux.dev, memxor@gmail.com, song@kernel.org, yonghong.song@linux.dev Subject: [PATCH 6.6.y] bpf: Fix stackmap overflow check in __bpf_get_stackid() Date: Thu, 15 Oct 2026 22:32:25 -0400 Message-ID: <20261016023225.19034-1-artem@trailofbits.com> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Arnaud Lecomte [ Upstream commit 23f852daa4bab4d579110e034e4d513f7d490846 ] Syzkaller reported a KASAN slab-out-of-bounds write in __bpf_get_stackid() when copying stack trace data. The issue occurs when the perf trace contains more stack entries than the stack map bucket can hold, leading to an out-of-bounds write in the bucket's data array. Fixes: ee2a098851bf ("bpf: Adjust BPF stack helper functions to accommodate skip > 0") Reported-by: syzbot+c9b724fbb41cf2538b7b@syzkaller.appspotmail.com Signed-off-by: Arnaud Lecomte Signed-off-by: Andrii Nakryiko Acked-by: Yonghong Song Acked-by: Song Liu Link: https://lore.kernel.org/bpf/20251025192941.1500-1-contact@arnaud-lcm.com Closes: https://syzkaller.appspot.com/bug?extid=c9b724fbb41cf2538b7b Assisted-by: LLM [ Backport to 6.6.y: stack_map_calculate_max_depth() was introduced by e17d62fedd10 ("bpf: Refactor stack map trace depth calculation into helper function"), which is not in 6.6.y; open-code the same computation in __bpf_get_stackid(). ] Signed-off-by: Artem Dinaburg --- Hi, Please consider this backport of the fix for CVE-2025-68378 to 6.6.y. The only difference from upstream is that the stack_map_calculate_max_depth() helper, which 6.6.y lacks, is open-coded in __bpf_get_stackid(). The complete fix is already present in 6.12.y, 6.18.y and 7.2.y. Build-tested only as part of a cumulative 6.6.y series on x86_64 (allmodconfig, CONFIG_WERROR=y); no runtime testing. Thanks, Artem Dinaburg kernel/bpf/stackmap.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -216,7 +216,8 @@ struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map); struct stack_map_bucket *bucket, *new_bucket, *old_bucket; u32 skip = flags & BPF_F_SKIP_FIELD_MASK; - u32 hash, id, trace_nr, trace_len; + u32 hash, id, trace_nr, trace_len, max_depth; + u32 curr_sysctl_max_stack; bool user = flags & BPF_F_USER_STACK; u64 *ips; bool hash_matches; @@ -225,7 +226,12 @@ /* skipping more than usable stack trace */ return -EFAULT; - trace_nr = trace->nr - skip; + curr_sysctl_max_stack = READ_ONCE(sysctl_perf_event_max_stack); + max_depth = map->value_size / stack_map_data_size(map); + max_depth += skip; + if (max_depth > curr_sysctl_max_stack) + max_depth = curr_sysctl_max_stack; + trace_nr = min_t(u32, trace->nr - skip, max_depth - skip); trace_len = trace_nr * sizeof(u64); ips = trace->ip + skip; hash = jhash2((u32 *)ips, trace_len / sizeof(u32), 0); @@ -354,15 +360,11 @@ return -EFAULT; nr_kernel = count_kernel_ip(trace); + __u64 nr = trace->nr; /* save original */ if (kernel) { - __u64 nr = trace->nr; - trace->nr = nr_kernel; ret = __bpf_get_stackid(map, trace, flags); - - /* restore nr */ - trace->nr = nr; } else { /* user */ u64 skip = flags & BPF_F_SKIP_FIELD_MASK; @@ -373,6 +375,10 @@ flags = (flags & ~BPF_F_SKIP_FIELD_MASK) | skip; ret = __bpf_get_stackid(map, trace, flags); } + + /* restore nr */ + trace->nr = nr; + return ret; }