mallocForeignPtrArray with check against buffer overflows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

mallocForeignPtrArray with check against buffer overflows

Henning Thielemann

I like to test whether some low-level routines overwrite non-allocated
memory area. On the Amiga there was the program Mungwall that surrounded
memory blocks with some byte patterns at allocation and checked the
integrity of those patterns at deallocation. This would also be possible
in Haskell with a modified mallocForeignPtrArray. Has someone already
implemented this idea? If yes, how could I easily switch between the
mallocForeignPtrArray version with such debugging support and the plain
function? It would be unfeasible to re-compile a lot of packages only for
debugging. Ideally the test-suite of a package would use the debugging
version of mallocForeignPtrArray and the library part would use plain
allocation.

I thought about using valgrind but I remember this often gave many false
positive bug reports for Haskell programs.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: mallocForeignPtrArray with check against buffer overflows

Henning Thielemann

On Thu, 26 Apr 2018, Henning Thielemann wrote:

> I like to test whether some low-level routines overwrite non-allocated
> memory area. On the Amiga there was the program Mungwall that surrounded
> memory blocks with some byte patterns at allocation and checked the
> integrity of those patterns at deallocation.

It seems that electric-fence is the counterpart to Mungwall on Linux. Any
experiences how to use that in Haskell?
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: mallocForeignPtrArray with check against buffer overflows

David Feuer
In reply to this post by Henning Thielemann
For debugging, this sounds like overkill to me. Can't you write
bounds-checking versions of your primitives that are turned on with
some CPP? Data.HashMap.Array does this sort of thing, although I don't
think it checks everything it really should. In the back of my mind,
I've been thinking it would be really nice to be able to tell GHC to
use checked versions of its primops. That's seems a bit tricky, since
the SomeException type is at a much higher level, but maybe there's
some way to make it work.

On Thu, Apr 26, 2018 at 2:50 AM, Henning Thielemann
<[hidden email]> wrote:

>
> I like to test whether some low-level routines overwrite non-allocated
> memory area. On the Amiga there was the program Mungwall that surrounded
> memory blocks with some byte patterns at allocation and checked the
> integrity of those patterns at deallocation. This would also be possible in
> Haskell with a modified mallocForeignPtrArray. Has someone already
> implemented this idea? If yes, how could I easily switch between the
> mallocForeignPtrArray version with such debugging support and the plain
> function? It would be unfeasible to re-compile a lot of packages only for
> debugging. Ideally the test-suite of a package would use the debugging
> version of mallocForeignPtrArray and the library part would use plain
> allocation.
>
> I thought about using valgrind but I remember this often gave many false
> positive bug reports for Haskell programs.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: mallocForeignPtrArray with check against buffer overflows

David Feuer
I just opened https://ghc.haskell.org/trac/ghc/ticket/15092 to
consider such options.

On Thu, Apr 26, 2018 at 6:30 PM, David Feuer <[hidden email]> wrote:

> For debugging, this sounds like overkill to me. Can't you write
> bounds-checking versions of your primitives that are turned on with
> some CPP? Data.HashMap.Array does this sort of thing, although I don't
> think it checks everything it really should. In the back of my mind,
> I've been thinking it would be really nice to be able to tell GHC to
> use checked versions of its primops. That's seems a bit tricky, since
> the SomeException type is at a much higher level, but maybe there's
> some way to make it work.
>
> On Thu, Apr 26, 2018 at 2:50 AM, Henning Thielemann
> <[hidden email]> wrote:
>>
>> I like to test whether some low-level routines overwrite non-allocated
>> memory area. On the Amiga there was the program Mungwall that surrounded
>> memory blocks with some byte patterns at allocation and checked the
>> integrity of those patterns at deallocation. This would also be possible in
>> Haskell with a modified mallocForeignPtrArray. Has someone already
>> implemented this idea? If yes, how could I easily switch between the
>> mallocForeignPtrArray version with such debugging support and the plain
>> function? It would be unfeasible to re-compile a lot of packages only for
>> debugging. Ideally the test-suite of a package would use the debugging
>> version of mallocForeignPtrArray and the library part would use plain
>> allocation.
>>
>> I thought about using valgrind but I remember this often gave many false
>> positive bug reports for Haskell programs.
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: mallocForeignPtrArray with check against buffer overflows

Joachim Durchholz
In reply to this post by Henning Thielemann
Am 26.04.2018 um 08:50 schrieb Henning Thielemann:
>
> I like to test whether some low-level routines overwrite non-allocated
> memory area. On the Amiga there was the program Mungwall that surrounded
> memory blocks with some byte patterns at allocation and checked the
> integrity of those patterns at deallocation.
Today, it's called a "canary value". Most C compilers have an option to
activate this mode for all allocations.
I don't know whether GHC's native backend has such an option, but the
LLVM backend should.

Regards,
Jo
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: mallocForeignPtrArray with check against buffer overflows

Henning Thielemann
In reply to this post by David Feuer

On Thu, 26 Apr 2018, David Feuer wrote:

> For debugging, this sounds like overkill to me. Can't you write
> bounds-checking versions of your primitives that are turned on with some
> CPP?

I call foreign functions from LAPACK that fill the arrays and I have not
control over its primitives.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.