RFC exec/memory: Experimental API to catch unaligned accesses
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest12 patches 3 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/12 | exec/memory_ldst: Use correct type sizesinclude/ memory_ldst.c.inc | +18 | 0 replies | |
| 2/12 | exec/memattrs: Add attribute/error for address alignmentinclude/ | +3 | 1 reply | |
| 3/12 | exec/memory_ldst: Return MEMTX_UNALIGNED_ERROR for unaligned addressesmemory_ldst.c.inc | +49 | 0 replies | |
| 4/12 | exec/memory_ldst_cached: Sort declarationsinclude/ | +23 | 0 replies | |
| 5/12 | exec/memory_ldst_cached: Use correct type sizeinclude/ | +2 | 0 replies | |
| 6/12 | exec/memory_ldst_cached: Set MemTxResult on successinclude/ | +18 | 0 replies | |
| 7/12 | exec/memory_ldst_cached: Document aligned addresses are expectedinclude/ | +6 | 0 replies | |
| 8/12 | exec/memory_ldst_cached: Check address alignment if requestedinclude/ | +42 | 0 replies | |
| 9/12 | hw/virtio: Use correct type sizesinclude/ | +2 | 0 replies | |
| 10/12 | hw/virtio: Extract virtio_lduw_phys_cached_with_attrs()include/ | +31 | 0 replies | |
| 11/12 | hw/virtio: Have vring_avail_flags() return a boolean valuehw/ | +9 | 0 replies | |
| 12/12 | hw/virtio: Display error if vring flag field is not alignedhw/ | +11 | 1 reply |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC PATCH 00/12] exec/memory: Experimental API to catch unaligned accesses
Hi,
This series is an experiment after chatting with Stefan and having received review from Peter / Richard on an orthogonal series aiming to handle unaligned pointers (atomically):
https://www.mail-archive.com/[email protected]/msg808954.html
Here we don't aim to fix unatomic accesses, however we are interested in catching malicious unaligned accesses from guests.
For that we introduce the MemTxAttrs::aligned field which allow accessors to return MEMTX_UNALIGNED_ERROR early enough, instead of trying the unaligned access which can potentially trigger a SIGBUS and abort the process.
To be able to pass/return alignment information we modify the memory load/store cached API, then add the virtio_ld/st*_phys_cached_with_attrs() handler (we only implement lduw for this experiment).
Finaly we modify vring_avail_flags() to return whether the guest requested an illegal (unaligned) memory access.
Note: The current virtio_ld/st*_phys_cached_with_attrs() API returns the value, and take the MemTxResult as argument, so I choose to return -1 (marked with /* XXX */ comment. We should switch to using an API which returns a MemTxResult and takes the value accessed as argument, this way we don't have to return random meaningless value.
But this is beyond the scope of this experiment, here we want to emphasize the introduction of the MemTxAttrs::aligned field and the MEMTX_UNALIGNED_ERROR return value.
Regards,
Phil.
Philippe Mathieu-Daudé (12):
exec/memory_ldst: Use correct type sizes
exec/memattrs: Add attribute/error for address alignment exec/memory_ldst: Return MEMTX_UNALIGNED_ERROR for unaligned addresses exec/memory_ldst_cached: Sort declarations exec/memory_ldst_cached: Use correct type size exec/memory_ldst_cached: Set MemTxResult on success exec/memory_ldst_cached: Document aligned addresses are expected exec/memory_ldst_cached: Check address alignment if requested hw/virtio: Use correct type sizes
hw/virtio: Extract virtio_lduw_phys_cached_with_attrs() hw/virtio: Have vring_avail_flags() return a boolean value hw/virtio: Display error if vring flag field is not aligned
include/exec/memattrs.h | 3 + include/hw/virtio/virtio-access.h | 39 +++++++-- include/exec/memory_ldst.h.inc | 16 ++-- include/exec/memory_ldst_cached.h.inc | 114 ++++++++++++++++++++------ hw/virtio/virtio.c | 22 ++++- memory_ldst.c.inc | 69 +++++++++++++--- 6 files changed, 211 insertions(+), 52 deletions(-)
Signature · 1 line
2.26.3