Skip to content

Commit d2c5759

Browse files
deepak0414alistair23
authored andcommitted
target/riscv: fixes a bug against ssamoswap behavior in M-mode
Commit f06bfe3 ("target/riscv: implement zicfiss instructions") adds `ssamoswap` instruction. `ssamoswap` takes the code-point from existing reserved encoding (and not a zimop like other shadow stack instructions). If shadow stack is not enabled (via xenvcfg.SSE) and effective priv is less than M then `ssamoswap` must result in an illegal instruction exception. However if effective priv is M, then `ssamoswap` results in store/AMO access fault. See Section "22.2.3. Shadow Stack Memory Protection" of priv spec. Fixes: f06bfe3 ("target/riscv: implement zicfiss instructions") Reported-by: Ved Shanbhogue <[email protected]> Signed-off-by: Deepak Gupta <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
1 parent 86c78b2 commit d2c5759

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

target/riscv/insn_trans/trans_rvzicfiss.c.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
* You should have received a copy of the GNU General Public License along with
1616
* this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
18+
19+
#define REQUIRE_ZICFISS(ctx) do { \
20+
if (!ctx->cfg_ptr->ext_zicfiss) { \
21+
return false; \
22+
} \
23+
} while (0)
24+
1825
static bool trans_sspopchk(DisasContext *ctx, arg_sspopchk *a)
1926
{
2027
if (!ctx->bcfi_enabled) {
@@ -77,6 +84,11 @@ static bool trans_ssrdp(DisasContext *ctx, arg_ssrdp *a)
7784
static bool trans_ssamoswap_w(DisasContext *ctx, arg_amoswap_w *a)
7885
{
7986
REQUIRE_A_OR_ZAAMO(ctx);
87+
REQUIRE_ZICFISS(ctx);
88+
if (ctx->priv == PRV_M) {
89+
generate_exception(ctx, RISCV_EXCP_STORE_AMO_ACCESS_FAULT);
90+
}
91+
8092
if (!ctx->bcfi_enabled) {
8193
return false;
8294
}
@@ -97,6 +109,11 @@ static bool trans_ssamoswap_d(DisasContext *ctx, arg_amoswap_w *a)
97109
{
98110
REQUIRE_64BIT(ctx);
99111
REQUIRE_A_OR_ZAAMO(ctx);
112+
REQUIRE_ZICFISS(ctx);
113+
if (ctx->priv == PRV_M) {
114+
generate_exception(ctx, RISCV_EXCP_STORE_AMO_ACCESS_FAULT);
115+
}
116+
100117
if (!ctx->bcfi_enabled) {
101118
return false;
102119
}

0 commit comments

Comments
 (0)