On Thu, Dec 12, 2019 at 1:03 PM Andrea Fioraldi
<andreafiora...@gmail.com> wrote:
>
> Hi to all,

Hi Andrea,

> there is a way to poison bytes as read-only in the ASAN runtime?
> For instance, I have a type field in a dynamic allocated structure that is 
> assigned only at creation
> and I want to mark it as read-only after the first assignment to detect 
> type-confusions.
> I found nothing searching about it in compiler-rt and so this is more a 
> feature request, but maybe I missed it and already exists.

No, right now it's not possible. ASan instrumentation doesn't
distinguish between a read and a write.
This can be done on LLVM side, but additional complication doesn't
sound necessary, especially given that there won't be any automated
way to mark data read-only.
Without that this feature will have limited use.

If you need a one-off solution for marking some small amount of data
read-only, you can allocate a page-aligned memory chunk with mmap(),
store your data in it and seal it with mprotect().

HTH,
Alex

>
> Something like the following snippet would be useful:
>
> enum {
>   IS_INT,
>   IS_FLOAT
> };
> struct foo {
>   int type;
>   union { int i; float f };
> };
>
> struct foo* create_int_foo(int i) {
>   struct foo * f = malloc(sizeof(struct foo));
>   f->i = i;
>   f->type = IS_INT;
>   ASAN_POISON_RDONLY_MEMORY_REGION(&f->type, sizeof(int));
> }
>
> Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "address-sanitizer" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to address-sanitizer+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/address-sanitizer/29bb9619-d1ba-4426-8eaf-068b3c795337%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"address-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to address-sanitizer+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/address-sanitizer/CAE4VGWyCbLLW9bYn96KZUyQTtEa38m9ASY2yuEm614Q9bEz-cQ%40mail.gmail.com.

Reply via email to