[GH-ISSUE #1195] memdbg should never return memory aligned better than requested #749

Closed
opened 2026-10-14 03:22:16 +07:00 by bsakaguchi · 13 comments
Owner

Originally created by @magnumripper on GitHub (Apr 9, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1195

Maybe this is already implemented? If not, it's probably a good idea for catching bugs.

Originally created by @magnumripper on GitHub (Apr 9, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1195 Maybe this is already implemented? If not, it's probably a good idea for catching bugs.
bsakaguchi 2026-10-14 03:22:16 +07:00
  • closed this issue
  • added the
    testing
    label
Author
Owner

@magnumripper commented on GitHub (Apr 12, 2015):

Blocked by #1200

<!-- gh-comment-id:91951052 --> @magnumripper commented on GitHub (Apr 12, 2015): Blocked by #1200
Author
Owner

@magnumripper commented on GitHub (May 22, 2015):

This is no longer completely still blocked by #1200. But anyway, we can implement this in mem_alloc_tiny() right away.

So how do we go about doing it? For mem_alloc_tiny() it should be easy:

  • Original request is size, align.
  • We do size += align.
  • We alloc as usual.
  • We check alignment. If it's better than requested, we bump the pointer with align.
  • Done.

I need to think this over. Is it this simple? I think it is.

<!-- gh-comment-id:104747280 --> @magnumripper commented on GitHub (May 22, 2015): This is ~~no longer completely~~ still blocked by #1200. But anyway, we can implement this in mem_alloc_tiny() right away. So how do we go about doing it? For mem_alloc_tiny() it should be easy: - Original request is _size_, _align_. - We do `size += align`. - We alloc as usual. - We check alignment. If it's better than requested, we bump the pointer with _align_. - Done. I need to think this over. Is it this simple? I think it is.
Author
Owner

@magnumripper commented on GitHub (May 22, 2015):

Done! Works like a champ. Probably very wasteful but who cares, it's debug code!

<!-- gh-comment-id:104754656 --> @magnumripper commented on GitHub (May 22, 2015): Done! Works like a champ. Probably very wasteful but who cares, it's debug code!
Author
Owner

@magnumripper commented on GitHub (May 22, 2015):

Not sure if we can do this at all in memdbg, without completely changing how it does things. OTOH that will be needed for #1200 anyway.

<!-- gh-comment-id:104754765 --> @magnumripper commented on GitHub (May 22, 2015): Not sure if we can do this at all in memdbg, without completely changing how it does things. OTOH that will be needed for #1200 anyway.
Author
Owner

@magnumripper commented on GitHub (May 22, 2015):

Not a single salt/binary align bug found. We must have fixed the last one JUST before implementing this! Like in c98950f9 or something. Doh! But we'll find them easily in the future.

<!-- gh-comment-id:104756326 --> @magnumripper commented on GitHub (May 22, 2015): Not a single salt/binary align bug found. We must have fixed the last one JUST before implementing this! Like in c98950f9 or something. Doh! But we'll find them easily in the future.
Author
Owner

@jfoug commented on GitHub (May 22, 2015):

I am planning on revamp of memdbg. I will do this with 2 headers. The first header will have a magic value, a pointer to the 2Nd header, and a fence post. The fence post will butt up to the start of the memory. There will be at least 4 bytes of fence post, possibly more. The pointer will be 16 byte aligned. And at least 4 bytes preceeding the memory buffer. Computing the location of this pointer can be done only knowing the iser memory ponter. Just before this pointer is anouther magic value that will validate the pointer as not being overwritten. There will likely be memory allocated in front of this header. That memory is unused. Trailing the user memory will be a fence post. Following the fence post, on an even 16 byte offset will be header 2. This header will be similar to the current first header, but it will also have a pointer to the actual allocated buffer, ie, somewhere in front of the first header.

Simple stuff, but may take a bit of debugging to get everything working right. But with this new design, we can get the user memory to start at any offset, since the first header is no longer fixed size

<!-- gh-comment-id:104770996 --> @jfoug commented on GitHub (May 22, 2015): I am planning on revamp of memdbg. I will do this with 2 headers. The first header will have a magic value, a pointer to the 2Nd header, and a fence post. The fence post will butt up to the start of the memory. There will be at least 4 bytes of fence post, possibly more. The pointer will be 16 byte aligned. And at least 4 bytes preceeding the memory buffer. Computing the location of this pointer can be done only knowing the iser memory ponter. Just before this pointer is anouther magic value that will validate the pointer as not being overwritten. There will likely be memory allocated in front of this header. That memory is unused. Trailing the user memory will be a fence post. Following the fence post, on an even 16 byte offset will be header 2. This header will be similar to the current first header, but it will also have a pointer to the actual allocated buffer, ie, somewhere in front of the first header. Simple stuff, but may take a bit of debugging to get everything working right. But with this new design, we can get the user memory to start at any offset, since the first header is no longer fixed size
Author
Owner

@frank-dittrich commented on GitHub (May 23, 2015):

On 05/22/2015 10:06 PM, magnum wrote:

Not a single salt/binary align bug found. We must have fixed the last
one JUST before implementing this! Doh! But we'll find them easily in
the future.

Did you test on non-x86?

<!-- gh-comment-id:104935852 --> @frank-dittrich commented on GitHub (May 23, 2015): On 05/22/2015 10:06 PM, magnum wrote: > Not a single salt/binary align bug found. We must have fixed the last > one JUST before implementing this! Doh! But we'll find them easily in > the future. Did you test on non-x86?
Author
Owner

@magnumripper commented on GitHub (May 23, 2015):

Did you test on non-x86?

No, but few formats differ in binary/salt.

<!-- gh-comment-id:104955031 --> @magnumripper commented on GitHub (May 23, 2015): > Did you test on non-x86? No, but few formats differ in binary/salt.
Author
Owner

@jfoug commented on GitHub (May 27, 2015):

This should be fixed (I think) in 20ce8fe

There is a #define in john.c (at the very start of main) that should test memdbg. It simple tests all alignments from 1 to 256. It checks that the alignment is correct. It also tests that the pointer/align is not %=0 to the alignment. The only one that 'is' %=0 to alignment is alignment 1.

After this change, I see no salt() misalignments. They should show up now.

<!-- gh-comment-id:106075988 --> @jfoug commented on GitHub (May 27, 2015): This should be fixed (I think) in 20ce8fe There is a #define in john.c (at the very start of main) that should test memdbg. It simple tests all alignments from 1 to 256. It checks that the alignment is correct. It also tests that the pointer/align is not %=0 to the alignment. The only one that 'is' %=0 to alignment is alignment 1. After this change, I see no salt() misalignments. They should show up now.
Author
Owner

@magnumripper commented on GitHub (May 27, 2015):

Cool. These things will make our annual Sparc sessions much shorter :)

<!-- gh-comment-id:106095353 --> @magnumripper commented on GitHub (May 27, 2015): Cool. These things will make our annual Sparc sessions much shorter :)
Author
Owner

@jfoug commented on GitHub (May 27, 2015):

The biggest thing is where there is insufficient salt/binary alignment. Say it is 1, but needs to be sizeof(int) or something.

On -test=0, xsha512 is now failing. Pomelo still fails, but there was never an attempt to get it working.

<!-- gh-comment-id:106097355 --> @jfoug commented on GitHub (May 27, 2015): The biggest thing is where there is insufficient salt/binary alignment. Say it is 1, but needs to be sizeof(int) or something. On -test=0, xsha512 is now failing. Pomelo still fails, but there was never an attempt to get it working.
Author
Owner

@jfoug commented on GitHub (May 28, 2015):

I found a core in hmacSHA384. It was allocations of the ipad/opad ctx vars. We were aligning to ARCH_WORD, but on 32 bit systems, that is only 4 bytes (8 bytes is the size of the 64 bit data). This did not show up on -test=0, but was found with the TS. Simple fix. I just allocate to forced align of 8.

But getting allocation to align to force a maximal alignment to be the same as minimal should flush out problems easier, or at least trigger warnings that force us to figure things out.

NOTE, the *_tiny() allocations do not have this max alignment=min alignment, but I think you dropped most of those and switch to mem_alloc_align

<!-- gh-comment-id:106416057 --> @jfoug commented on GitHub (May 28, 2015): I found a core in hmacSHA384. It was allocations of the ipad/opad ctx vars. We were aligning to ARCH_WORD, but on 32 bit systems, that is only 4 bytes (8 bytes is the size of the 64 bit data). This did not show up on -test=0, but was found with the TS. Simple fix. I just allocate to forced align of 8. But getting allocation to align to force a maximal alignment to be the same as minimal should flush out problems easier, or at least trigger warnings that force us to figure things out. NOTE, the *_tiny() allocations do not have this max alignment=min alignment, but I think you dropped most of those and switch to mem_alloc_align
Author
Owner

@magnumripper commented on GitHub (May 28, 2015):

Tiny has it since 093d04b

<!-- gh-comment-id:106577769 --> @magnumripper commented on GitHub (May 28, 2015): Tiny has it since 093d04b
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#749
No description provided.