diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-15 18:50:55 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-11-15 18:50:55 +0100 |
| commit | b1034b86023672e6750da49b01a7d429cd8339d0 (patch) | |
| tree | 6147dac325b2bb062bfb35e0aa09d81f7e5758fe /src/interp/linear/load.c | |
| parent | 0b2a1fd9439d5ab1cdc076d7b9f1e763c4900b74 (diff) | |
| download | nanowasm-b1034b86023672e6750da49b01a7d429cd8339d0.tar.gz | |
Check memory linear accesses are within bounds
WebAssembly defines how many pages of linear memory are owned by the
instance on startup. This limit can then be bumped via the grow_memory
operator.
Therefore, accesses outside the defined bounds are considered an
exception.
Diffstat (limited to 'src/interp/linear/load.c')
| -rw-r--r-- | src/interp/linear/load.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/interp/linear/load.c b/src/interp/linear/load.c index afc6154..38294c4 100644 --- a/src/interp/linear/load.c +++ b/src/interp/linear/load.c @@ -9,6 +9,7 @@ #include <nanowasm/nw.h> #include <nanowasm/linear.h> +#include <nw/linear.h> #include <nw/interp.h> #include <nw/mem.h> #include <nw/log.h> @@ -17,7 +18,21 @@ enum nw_state nwp_linear_load(struct nw_interp *const i, struct nw_sm_io *const io, const unsigned long offset) { const struct nw_interp_cfg *const cfg = &i->cfg; - const enum nw_state n = nwp_mem_load(&cfg->linear, io, offset, cfg->user); + enum nw_state n; + + if (nwp_linear_check(i, offset, io->n)) + { + static const char *const exc = "out-of-bounds read access to " + "linear memory"; + +#ifdef NW_LOG + nwp_log("%s, addr=%#lx, sz=%#lx\n", exc, offset, io->n); +#endif + i->exception = exc; + return NW_FATAL; + } + + n = nwp_mem_load(&cfg->linear, io, offset, cfg->user); if (n == NW_FATAL) { |
