On Tue, Jan 23, 2024 at 09:46:35AM +0000, Mark Rutland wrote: > With that in mind, I note that this patch primarily modifies addition > operations, but leaves subtraction operations unchanged (even though those > permit the value to go below the minimum, or above the maximum if a negative > value is used as the subtrahend).
Right, this was kind of a "first pass" on what I'd found so far. > Shouldn't we address both at the same time? I'll note that in many places the > same logic is used for both the add and sub, and can legitimately overflow or > underflow; I hope that whatever we use to suppress overflow warnings also > ignores underflow. > > [...] > > Looking at the diffstat, I think you've missed a few places: > > [...] > > This misses the include/asm-generic/{atomic,atomic64}.h implementations. > > This also misses the include/linux/atomic/atomic-arch-fallback.h > implementations. Those are generated from the scripts/atomic/fallbacks/* > templates, and you'll need to adjust at least fetch_add_unless and > inc_unless_negative. As noted on other patches, my preference is to use > add_wrap() in those. > [...] > This misses lib/atomic64.c. Thanks! I'll take a closer look at places we can use the helpers on the atomics. -Kees -- Kees Cook