Hi Glider, thank you for the quick answer.
I've some doubt, correct me if I'm wrong.

> No, right now it's not possible. ASan instrumentation doesn't distinguish 
between a read and a write. 

if ((addr >> 3) + offset) __asan_report_load8(addr);
This is inserted before loads, a quick implementations would be a simple

void __asan_report_load8(uptr add) {

  if (((addr >> 3) + offset == ASAN_USER_RDONLY_SHADOW) return;

  // .. old __asan_report_load 

}

And the same for all other variants like __asan_load8 , __asan_report_loadN 
etc...


> 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(). 

The libdislocator approach doesn't work if a want a single byte read only 
inside a RW region


Il giorno giovedì 12 dicembre 2019 13:08:19 UTC+1, Glider ha scritto:
>
> On Thu, Dec 12, 2019 at 1:03 PM Andrea Fioraldi 
> <[email protected] <javascript:>> 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 [email protected] <javascript:>. 
> > 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/address-sanitizer/fd668973-ffba-421c-b890-866f95f86174%40googlegroups.com.

Reply via email to