public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Jeff Law <law@redhat.com>, Jakub Jelinek <jakub@redhat.com>,
	Aldy Hernandez <aldyh@redhat.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: protected alloca class for malloc fallback
Date: Wed, 17 Aug 2016 13:39:00 -0000	[thread overview]
Message-ID: <57B46917.7030900@gmail.com> (raw)
In-Reply-To: <CAFiYyc1zOOVwySZ23GWEKjWzQT5Q1f0ZWvs6i=+e8aELP2J7gw@mail.gmail.com>

On 08/17/2016 02:27 AM, Richard Biener wrote:
> On Tue, Aug 16, 2016 at 7:54 PM, Martin Sebor <msebor@gmail.com> wrote:
>> On 08/16/2016 10:47 AM, Jeff Law wrote:
>>>
>>> On 08/16/2016 10:44 AM, Jakub Jelinek wrote:
>>>>
>>>> On Tue, Aug 16, 2016 at 10:27:58AM -0600, Jeff Law wrote:
>>>>>
>>>>> I think you're being rather short-sighed here.  GCC is being used in
>>>>> ways we
>>>>> can't necessarily predict -- which might include compile servers,
>>>>> JITs, web
>>>>> services, etc.
>>>>
>>>>
>>>> For compile server/web services one needs to add the protection
>>>> outside of
>>>> gcc (sandboxing, containers, SELinux, limiting CPU and/or memory, etc.),
>>>> because even with very short testcases e.g. in C/C++ one can eat
>>>> arbitrary
>>>> amounts of stack even without any uses of alloca in the compiler, simply
>>>> through deep recursion in the parsers etc.
>>>
>>> Agreed.  However, that doesn't mean we should not be locking down things
>>> like alloca and other attack vectors.
>>
>>
>> I think I made this suggestion when Aldy posted his first patch
>> but it didn't get much traction so let me try again.  Since the
>> concern is alloca calls with excessively large arguments, would
>> transforming those (determined both at compile time and at run
>> time) into pairs of malloc/free calls be an acceptable compromise?
>>
>> It would seem like a natural complement to the transformation
>> in the opposite direction, brought up back then, of turning calls
>> to malloc with small (compile-time) arguments into alloca.
>>
>> I would expect the malloc optimization to more than outweigh
>> the performance cost of the alloca to malloc transformation.
>> Perhaps even to the point to obviate the need for any explicit
>> alloca calls at all.  With the optimization in place, it seems
>> that it should even be possible to transparently transform at
>> least the most basic uses of some C++ containers written in
>> terms of operator new and delete to use alloca instead when
>> their sizes were known and under the alloca to malloc threshold.
>
> Please instead work on sth like -fstack-protector for alloca -- it should
> be straight-forward to add a runtime test on the stack adjustment
> being performed against some magic bound (yeah, needs more than
> only GCC support here).

I agree that would be a useful first step, and certainly a more 
attainable goal.  The C++ patch that handled the VLA part (bug
69517) had to be reverted just before 6.1 was released but it's
still on my to do list to add to it a knob to adjust the bound
at runtime and resubmit it.  It should be straightforward to
extend a similar approach to alloca and do the same thing in C
(except with trapping rather than throwing an exception).

Martin

      reply	other threads:[~2016-08-17 13:39 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04 11:30 Aldy Hernandez
2016-08-04 12:58 ` Richard Biener
2016-08-04 15:19   ` Aldy Hernandez
2016-08-04 19:24     ` Jeff Law
2016-08-05 14:37       ` Aldy Hernandez
2016-08-05 15:15         ` Pedro Alves
2016-08-05 16:23         ` Jeff Law
2016-08-05 17:48           ` Richard Biener
2016-08-05  8:17     ` Richard Biener
2016-08-04 19:06 ` Pedro Alves
2016-08-04 19:16   ` Jeff Law
2016-08-04 19:22     ` Pedro Alves
2016-08-04 19:26       ` Jeff Law
2016-08-04 19:31         ` Pedro Alves
2016-08-05  2:10 ` Martin Sebor
2016-08-05 14:42   ` Aldy Hernandez
2016-08-05 17:56     ` Richard Biener
2016-08-05 18:16       ` Oleg Endo
2016-08-05 20:07         ` Richard Biener
2016-08-06 10:09           ` Aldy Hernandez
2016-08-06 10:15           ` Aldy Hernandez
2016-08-06 15:08             ` Richard Biener
2016-08-08 17:00               ` Jeff Law
2016-08-08 17:32                 ` Trevor Saunders
2016-08-08 19:03                   ` Richard Biener
2016-08-09 11:34                   ` Oleg Endo
2016-08-09 17:34                     ` Trevor Saunders
2016-08-10 17:03                       ` Oleg Endo
2016-08-11  1:23                         ` Trevor Saunders
2016-08-11 12:18                           ` Oleg Endo
2016-08-11 17:55                             ` Trevor Saunders
2016-08-20  2:29                         ` Mike Stump
2016-08-21 20:00                           ` C++11? (Re: protected alloca class for malloc fallback) Pedro Alves
2016-08-22  7:10                             ` Trevor Saunders
2016-08-22  7:28                               ` Richard Biener
2016-08-22 12:02                             ` Eric Gallager
2016-08-22 12:58                               ` Manuel López-Ibáñez
2016-08-22 22:08                               ` Mike Stump
2016-08-23 23:17                                 ` Eric Gallager
2016-08-09 13:17       ` protected alloca class for malloc fallback Aldy Hernandez
2016-08-09 13:21         ` Bernd Schmidt
2016-08-10 10:04         ` Richard Biener
2016-08-10 10:12           ` Aldy Hernandez
2016-08-10 10:39             ` Richard Biener
2016-08-10 18:00           ` Jeff Law
2016-08-10 18:33             ` Richard Biener
2016-08-16 16:28               ` Jeff Law
2016-08-16 16:44                 ` Jakub Jelinek
2016-08-16 16:47                   ` Jeff Law
2016-08-16 17:54                     ` Martin Sebor
2016-08-17  8:27                       ` Richard Biener
2016-08-17 13:39                         ` Martin Sebor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57B46917.7030900@gmail.com \
    --to=msebor@gmail.com \
    --cc=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=law@redhat.com \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).