Skip to content

x86-64 Pjmptbl: normalize the argument before indexing into the jump table - #595

Open
xavierleroy wants to merge 3 commits into
masterfrom
x86_64-jmptbl
Open

x86-64 Pjmptbl: normalize the argument before indexing into the jump table#595
xavierleroy wants to merge 3 commits into
masterfrom
x86_64-jmptbl

Conversation

@xavierleroy

Copy link
Copy Markdown
Contributor

The index argument of Pjmptbl is an unsigned 32-bit integer, not a 64-bit integer, so it must be converted to 64 bits (by zeroing the top 32 bits) before being used as an index into the jump table.

Issue reported by Christos Papakonstantinou (Cantina Security).

…p table

The index argument of Pjmptbl is an unsigned 32-bit integer, not a 64-bit
integer, so it must be converted to 64 bits (by zeroing the top 32 bits)
before it can be used as an index into the jump table.
…mp table

The index argument of Pbtbl is an unsigned 32-bit integer.  However, RV64
stores it sign-extended in a 64-bit register.  This can cause an
incorrect access in the jump table in the unlikely case where the jump
table has 2^31 entries or more.  This commit uses two shifts instead of one
so as to zero-extend the index while multiplying it by 4.
@xavierleroy

Copy link
Copy Markdown
Contributor Author

It turns out that RISC-V 64 bits has a similar issue, although much less serious: the 32-bit index argument is implicitly extended to a signed 64-bit integer. So, in the unlikely case where the jump table has more than 2^31 entries, we're addressing the wrong entry. Commit bc5a65f proposes to fix this by zero-extending the index while multiplying it by 4. It adds one shift-right instruction to the code generated for Pbtbl. The alternative would be to reject jump tables with more than 2^31 entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant