* [PATCH v3] bpf: Annotate bpf_obj_memcpy with data_race
@ 2026-08-22 6:55 Quanye Yang via B4 Relay
2026-08-23 19:40 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Quanye Yang via B4 Relay @ 2026-08-22 6:55 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
Emil Tsalapatis
Cc: bpf, linux-kernel, syzbot+44044637ef892e79ca2b, Quanye Yang,
Ihor Solodrai
From: Quanye Yang <quanyeyang@proton.me>
syzbot reported KCSAN write-write races when two tasks concurrently
update the same map value. Both accesses reach the ordinary memcpy()
paths in bpf_obj_memcpy() through copy_map_value().
Unlocked in-place updates of published map values are intentionally not
serialized and may produce torn values. Callers requiring consistency
must provide synchronization appropriate for the map type.
bpf_long_memcpy() already annotates the same behavior for long-aligned
copies.
Annotate the ordinary memcpy() sites in bpf_obj_memcpy() with
data_race(), matching bpf_long_memcpy(). This documents the existing
concurrency semantics and suppresses KCSAN reports for these intentional
races without changing synchronization or map update behavior.
Reported-by: syzbot+44044637ef892e79ca2b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=44044637ef892e79ca2b
Signed-off-by: Quanye Yang <quanyeyang@proton.me>
---
The annotations remain in the common bpf_obj_memcpy() helper, matching
bpf_long_memcpy(). This keeps the existing copy helper interfaces
unchanged. A narrower annotation would require propagating the
concurrency context through copy_map_value() or introducing separate
copy helpers.
The following checkpatch warnings are expected:
- DATA_RACE is reported for the three annotations because checkpatch
only recognizes an immediately adjacent comment.
- MISSING_FIXES_TAG is reported because the commit references syzkaller.
No Fixes tag is included because this documents long-standing
intentional lockless semantics rather than a regression introduced
by a particular commit.
---
Changes in v3:
- Restore the original bpf_obj_memcpy() comment as suggested by Andrii.
- Use the properly cased full name for authorship and Signed-off-by.
- Link to v2: https://patch.msgid.link/20260820-bpf-kcsan-obj-memcpy-v2-1-672517a3145f@proton.me
Changes in v2:
- Drop the BPF_F_LOCK recommendation because it is unavailable for
per-CPU maps.
- Scope the concurrency description to unlocked in-place updates of
published map values.
- Fold the redundant commit message paragraphs.
- Link to v1:
https://patch.msgid.link/20260820-bpf-kcsan-obj-memcpy-v1-1-372c59462268@proton.me
To: Alexei Starovoitov <ast@kernel.org>
To: Daniel Borkmann <daniel@iogearbox.net>
To: Andrii Nakryiko <andrii@kernel.org>
To: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>
To: Song Liu <song@kernel.org>
To: Yonghong Song <yonghong.song@linux.dev>
To: Jiri Olsa <jolsa@kernel.org>
To: Emil Tsalapatis <emil@etsalapatis.com>
To: John Fastabend <john.fastabend@gmail.com>
To: Ihor Solodrai <ihor.solodrai@linux.dev>
Cc: bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
include/linux/bpf.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index b7dbf3d9b5c0..6248ff2f506d 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -572,7 +572,7 @@ static inline void bpf_obj_memcpy(struct btf_record *rec,
if (long_memcpy)
bpf_long_memcpy(dst, src, size);
else
- memcpy(dst, src, size);
+ data_race(memcpy(dst, src, size));
return;
}
@@ -580,10 +580,10 @@ static inline void bpf_obj_memcpy(struct btf_record *rec,
u32 next_off = rec->fields[i].offset;
u32 sz = next_off - curr_off;
- memcpy(dst + curr_off, src + curr_off, sz);
+ data_race(memcpy(dst + curr_off, src + curr_off, sz));
curr_off += rec->fields[i].size + sz;
}
- memcpy(dst + curr_off, src + curr_off, size - curr_off);
+ data_race(memcpy(dst + curr_off, src + curr_off, size - curr_off));
}
static inline void copy_map_value(struct bpf_map *map, void *dst, void *src)
---
base-commit: 75b0a6db4300e4c2c9e97a0848deaa7acfb42fb7
change-id: 20260819-bpf-kcsan-obj-memcpy-67042b1fce7d
Best regards,
--
Quanye Yang <quanyeyang@proton.me>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] bpf: Annotate bpf_obj_memcpy with data_race
2026-08-22 6:55 [PATCH v3] bpf: Annotate bpf_obj_memcpy with data_race Quanye Yang via B4 Relay
@ 2026-08-23 19:40 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-08-23 19:40 UTC (permalink / raw)
To: Quanye Yang
Cc: ast, daniel, john.fastabend, andrii, eddyz87, memxor, martin.lau,
song, yonghong.song, jolsa, emil, bpf, linux-kernel,
syzbot+44044637ef892e79ca2b, ihor.solodrai
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Kumar Kartikeya Dwivedi <memxor@gmail.com>:
On Sat, 22 Aug 2026 14:55:33 +0800 you wrote:
> From: Quanye Yang <quanyeyang@proton.me>
>
> syzbot reported KCSAN write-write races when two tasks concurrently
> update the same map value. Both accesses reach the ordinary memcpy()
> paths in bpf_obj_memcpy() through copy_map_value().
>
> Unlocked in-place updates of published map values are intentionally not
> serialized and may produce torn values. Callers requiring consistency
> must provide synchronization appropriate for the map type.
> bpf_long_memcpy() already annotates the same behavior for long-aligned
> copies.
>
> [...]
Here is the summary with links:
- [v3] bpf: Annotate bpf_obj_memcpy with data_race
https://git.kernel.org/bpf/bpf-next/c/5e289c5a4a52
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-23 19:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-22 6:55 [PATCH v3] bpf: Annotate bpf_obj_memcpy with data_race Quanye Yang via B4 Relay
2026-08-23 19:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox