diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-11-25 21:57:38 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-11-25 21:57:38 -0800 |
| commit | 25faec9ce61c01fb45abf812a222c5b43c3cd5c5 (patch) | |
| tree | 70a9f3c047abdff8d72ef8ff8f32f4a3146184f4 /security/selinux | |
| parent | 40212b29a6f718d4e7fb3275cede181cb8e137cf (diff) | |
This commit came about because I locally had a build with COMPILE_TEST
and various runtime hardening features (that don't make sense for a pure
build test anyway) disabled - and objtool complained about some of the
code as a result:
drivers/net/ethernet/freescale/dpaa2/fsl-dpaa2-eth.o: warning: objtool: dpaa2_eth_add_bufs+0x3f8: stack state mismatch: reg1[15]=-1+0 reg2[15]=-2-208
The reason seems to be that without the hardening features, objtool
notices that gcc is doing really odd things with the 'page' variable,
which is uninitialized in the path where 'ch->xsk_zc' is true.
Now, this seems to be just objtool becoming confused about some ugly
code, but that code is _also_ actively buggy in a different way, so
let's just fix this all.
What confuses objtool seems to be the stack slot for the uninitialized
'page' variable - for the case where that variable isn't actually used.
There is some shared error handling code that frees the previously
allocated page or xsk buffers depending on previous state.
That code is ugly and worth fixing: just free the page or buffers in the
context where they are actually allocated, not at some common point
where you have to wonder "which one is it I'm supposed to free again?".
That gets rid of the objtool warning, because now gcc doesn't take messy
and incomprehensible source code and turn it into messy and even more
incomprehensible object code any more. No more questionable stack
frames with CFI information that blows objtool's little mind.
But fixing that then makes a real bug more obvious: the freeing of the
xsk buffers is buggy. It frees the buffers that never got mapped:
for (; i < batch; i++)
xsk_buff_free(xdp_buffs[i]);
and that looks sane enough: iterate over the unused part of the batch.
But it's horrendously wrong, because it updates 'i'.
And 'i' isn't some harmless little local loop counter. It's the
variable that is supposed to contain how many buffers have been
successfully mapped. So now that 'free the buffers we didn't map' loop
ends up updating that counter, and after the loop 'i' will be the whole
batch we allocated.
So that loop first freed the buffers that failed to map, and then as a
side effect said "all these buffers I just freed were successfully
mapped" and they would be released to hardware.
So objtool didn't actually find a real bug. It just found code that was
so ugly that it triggered a false positive. And as is often the case
with ugly code: people hadn't understood it either, and it was buggy.
It's worth noting that the code is still ugly. A variable name like 'i'
is perfectly fine for some random anonymous loop iterator that is just
that. But when it has serious meaning outside the loop, you should give
it a serious name that makes sense non-locally.
This does not fix that kind of ugliness. This is just the minimal fix
for the objtool warning and the entirely incidental bug it then
uncovered. They had nothing in common except for the obfuscated C code
contest entry.
Fixes: 48276c08cf5d ("net: dpaa2-eth: AF_XDP RX zero copy support")
Cc: Robert-Ionut Alexa <robert-ionut.alexa@nxp.com>
Cc: Ioana Ciornei <ioana.ciornei@nxp.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'security/selinux')
0 files changed, 0 insertions, 0 deletions
