[PATCH] Linux: Add fortify wrapper for getdents64

Florian Weimer fweimer@redhat.com
Fri Jun 21 12:22:00 GMT 2019


* Wilco Dijkstra:

> Hi Florian,
>
>> > Do we really need to add to this broken feature? The fortify feature should have
>> > been retired decades ago, it's not useful or secure at all.
>> >
>> > If we actually want to detect buffer overflows the correct approach is to add
>> > runtime checks in GCC as that's the place where you have the right info about
>> > variables and array sizes. The current implementation is completely broken
>> > in that it doesn't do buffer overflow checks even in the most trivial cases, and
>> > fails to inline or optimize checks. It just adds duplicate entry points which are
>> > inefficient and are mostly unused... (and you get people adding ifuncs for them
>> > functions just for fun)
>> 
>> I don't understand this.  Why do you think it does not work?  The check
>> is based on GCC, and GCC passing its analysis results to glibc, so that
>> GCC does not know which arguments are buffer pointers and their sizes,
>> and that the actual check does not have to be inlined in the caller.
>
> It's based on preprocessing magic, which isn't handled correctly. GCC
> doesn't end up doing the right thing in most cases. What happens is that
> only the most basic cases end up getting checked. Passing something
> like &array[0] as an argument or a constant offset like array + 1 will not get
> checked, and it cannot handle anything using a temporary even if it is set
> to a fixed offset in an array immediately before it. These are all cases
> compilers can trivially handle.

There may be limitations, but it's not based on preprocessing magic.
Simple pointer arithmetic on the buffer is handled correctly.  I think
you are confusing this with something else.

Thanks,
Florian



More information about the Libc-alpha mailing list