btf: Take instruction size into account when handling poison relocation#1351
btf: Take instruction size into account when handling poison relocation#1351lmb merged 2 commits intocilium:mainfrom
Conversation
|
Thanks for diagnosing this!
P.S. The reason we don't adjust automatically for this is because the offset is encoded in the instruction stream. Does the jump instruction in the ELF carry a relocation to an Lines 258 to 260 in e4ec617 |
I came up with this myself, I didn't think to look at libbpf's approach. They seem to emit 2 call instructions in this case: We could just copy that.
Yea, ofcourse.
It does, but I think the current fix is good enough? |
Yeah let's do that. The call instruction is already confusing enough. |
e43a484 to
36e4a6b
Compare
A CO-RE relocation might be poisoned, in such cases we write a "bogus" instruction to the relocation target. This can still result in working code if that instruction turns out to be in a dead code branch due to other CO-RE logic. Currently this bogus instructions is always a function call to a non-existing function. This is a problem when the original instruction is a dword load immediate, which takes 2 instructions worth of space. When we replace this with a function call, we shrink the instruction stream which throws off offsets and instruction metadata. So this commit makes makes the CO-RE logic check if we are dealing with a dword load immediate, and if so, we replace it with a dword imm load of 0xbad2310 to R10, which is illigal and will trip the verifier if evaluated. Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
Added a test which makes sure we do not mess up offsets when replacing a ld64imm with poisoned instructions. Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
36e4a6b to
fe3cc27
Compare
|
From discussion on Slack: going with the write to RFP trick, since that means we can avoid breaking API. |
A CO-RE relocation might be poisoned, in such cases we write a "bogus" instruction to the relocation target. This can still result in working code if that instruction turns out to be in a dead code branch due to other CO-RE logic.
Currently this bogus instructions is always a function call to a non-existing function. This is a problem when the original instruction is a dword load immediate, which takes 2 instructions worth of space. When we replace this with a function call, we shrink the instruction stream which throws off offsets and instruction metadata.
So this commit makes makes the CO-RE logic check if we are dealing with a dword load immediate, and if so, we replace it with a dword imm load of 0xbad2310 to R10, which is illigal and will trip the verifier if evaluated.
Fixes: #1348