From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA1593AEF2D; Sat, 17 Oct 2026 17:31:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792258281; cv=none; b=qMXU6dQjuVMKSPQT2SN6rEwruV3eUrvb8FicIaJWfYW+nR9NWkQlksIYl/nnGFhyDqVHHqw1XNRWXz2joFI5Oz5aUfrZCfPFaRdSv+CESjt8vBHkRuJ297MyBxTwaZbb7fGR5KXKtJfSvNlVx3CAjsoAu08iBwumh2s51K/xzXM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792258281; c=relaxed/simple; bh=GVOfoEjy5J5hK+ddntxMtJ1zvbvDwYMK51b+aIPKnTc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CB7nX+yjVOJaKLi4JRutxUvKAwmuezJYBscP/HP35giFDpIqpcih9u18cR9IYf3YY2F83Tfi6JjZPJHfk5r1+52yV97m3YBnQowKwh1B5ykyFRUKtaDYIsunHoiVRNTa4c3xDfE9erGpNdCDgvJZoIraHAfo7CQuAkJIavNPoKQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MJx3WT3a; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MJx3WT3a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11C261F000C4; Sat, 17 Oct 2026 17:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792258280; bh=NE1+aIjGGRWN+46F6LLhH0IWEEZkQN4R/VqWFsrlYAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MJx3WT3a8+d7shBsXIsAGuOsyVASokdATVLlUz/dqP3gD4EjUw8er2AI/eSg+gqBv MROefTk24PXUcveeZk04Fyoh9uIfqRa4GxkQoUuwDB3ihJnSFxgRaggeWdkHsEEmmJ 8VYOBvFiRBePamumDCTxXZhz73hcO4wZvIA5XKpU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+c9b724fbb41cf2538b7b@syzkaller.appspotmail.com, Arnaud Lecomte , Andrii Nakryiko , Yonghong Song , Song Liu , Sasha Levin Subject: [PATCH 6.6 0831/1674] bpf: Fix stackmap overflow check in __bpf_get_stackid() Date: Sat, 17 Oct 2026 17:51:43 +0200 Message-ID: <20261017160452.456801080@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Sasha Levin --- kernel/bpf/stackmap.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index a330f38ae7335..2f89588872a50 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -216,7 +216,7 @@ static long __bpf_get_stackid(struct bpf_map *map, 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; bool user = flags & BPF_F_USER_STACK; u64 *ips; bool hash_matches; @@ -225,7 +225,10 @@ static long __bpf_get_stackid(struct bpf_map *map, /* skipping more than usable stack trace */ return -EFAULT; - trace_nr = trace->nr - skip; + max_depth = map->value_size / stack_map_data_size(map) + skip; + if (max_depth > sysctl_perf_event_max_stack) + max_depth = sysctl_perf_event_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 +357,11 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bpf_perf_event_data_kern *, ctx, 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 +372,10 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bpf_perf_event_data_kern *, ctx, flags = (flags & ~BPF_F_SKIP_FIELD_MASK) | skip; ret = __bpf_get_stackid(map, trace, flags); } + + /* restore nr */ + trace->nr = nr; + return ret; } -- 2.53.0