This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/5] __FD_ELT: Implement correct buffer overflow check
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: KOSAKI Motohiro <kosaki dot motohiro at gmail dot com>
- Cc: libc-alpha <libc-alpha at sourceware dot org>, "libc-ports at sourceware dot org" <libc-ports at sourceware dot org>
- Date: Wed, 01 May 2013 10:42:15 -0400
- Subject: Re: [PATCH 2/5] __FD_ELT: Implement correct buffer overflow check
- References: <1365900451-19026-1-git-send-email-kosaki dot motohiro at gmail dot com> <1365900451-19026-3-git-send-email-kosaki dot motohiro at gmail dot com> <518080FD dot 1090402 at redhat dot com> <CAHGf_=pDgABHdv5RKd6U870J1t1gM6GhbDpxGoQMjJEsMPHgLQ at mail dot gmail dot com>
On 05/01/2013 02:28 AM, KOSAKI Motohiro wrote:
>>> + ? __fdelt_buffer_warn(__d, __bos0 (s)) \
>>
>> Space between function and bracket e.g. foo () not foo().
>
> ah, ok.
>
>>
>>> + : __fdelt_buffer_chk(__d, __bos0 (s)) \
>>> + : __d / __NFDBITS; \
>>
>> I'm not happy that this isn't very conservative.
>>
>> If __bos0 fails should we fall back to static FD_SETSIZE checking
>> e.g. "__fdelt_buffer_warn (__d, FD_SETSIZE)"?
>>
>> It seems that that would be better than no checking.
>
> Hmm.. This doesn't cross my mind. All other buffer boundary checks
> of _FORTIFY_SOURCE fall back no checking. compiler may fails to
> determine a right buffer size in various reasons. at that time, I don't
> want to kill innocent applications.
>
>> I know why you want to fall back to no check, because that
>> way you don't require any kind of new flag to disable the
>> check in the event it triggers when you don't want it to
>> (when __bos0 fails).
>
> If you like flag, I'm not putting objection. but if making flag, a lot
> of libraries need
> to turn on "no check" mode because when a buffer is allocated from applications,
> library code can't know a buffer size at least at compile time.
>
>
>> Does compiling ruby (or similar code) with this header
>> result in calls to __fdelt_buffer_warn or __fdelt_buffer_chk?
>
> Unfortunately, No. __builtin_object_size() require compiler know the
> buffer size.
> In the other words, it doesn't work if an allocate function and
> FD_{SET,CLR} functions
> doesn't exist in the same place. This is the same limitation with
> other string buffer
> overflow checks.
Then we need a flag, and ruby needs to use the flag to disable the
check on Linux.
The fundamental truth is that glibc implements POSIX, not "Linux."
And in POSIX there is a limit of FD_SETSIZE.
The default checking should be for POSIX.
We should provide a way to disable _FORTIFY_SOURCE checks that
are POSIX-only.
I still think your current macro is *better* because if __bos0
works then you have a dynamic check that is better than a static
check.
Thus the final solution is a combination of your new __bos0
changes and a flag to disable the check in the event that __bos0
fails.
What do you think?
Cheers,
Carlos.