Bug 662085 - ElectricFence (ef/efence) doesn't properly align memory by default
Summary: ElectricFence (ef/efence) doesn't properly align memory by default
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: ElectricFence
Version: 14
Hardware: Unspecified
OS: Unspecified
low
medium
Target Milestone: ---
Assignee: Petr Machata
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 662017 662029 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-12-10 15:47 UTC by Yann Droneaud
Modified: 2015-05-05 01:35 UTC (History)
2 users (show)

Fixed In Version: ElectricFence-2.2.2-30.fc14
Clone Of:
Environment:
Last Closed: 2011-01-28 19:20:35 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
Test case (1.87 KB, text/plain)
2010-12-10 15:47 UTC, Yann Droneaud
no flags Details

Description Yann Droneaud 2010-12-10 15:47:28 UTC
Created attachment 467992 [details]
Test case

ElectricFence malloc() wrapper did not return properly aligned memory pointer.
Aligned memory is a requirement of malloc() and must match the system ABI:

From Open Group Base Specifications Issue 7 / IEEE Std 1003.1-2008 :

"The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object in the space allocated (until the space is explicitly freed or reallocated)."


The attached test case could be run with and without ElectricFence.
The testcase allocte a few block of a given size, report the size, the address and the alignement of each block.

Without ElectricFence, on a x86_64 system where base alignment is 8 bytes, but 16 bytes is used (requirement for SSE):

$ ./malloc-alignment
   1: 0x1703010:   16 0x1703030:   16 0x1703050:   16 0x1703070:   16
   2: 0x1703010:   16 0x1703030:   16 0x1703050:   16 0x1703070:   16
   4: 0x1703010:   16 0x1703030:   16 0x1703050:   16 0x1703070:   16
   7: 0x1703010:   16 0x1703030:   16 0x1703050:   16 0x1703070:   16

With ElectricFence, still on x86_64 and EF_PROTECT_BELOW=1 which force malloc() to return a pointer to a memory page:

$ EF_PROTECT_BELOW=1 ef ./malloc-alignment

  Electric Fence 2.2.2 Copyright (C) 1987-1999 Bruce Perens <bruce>
   1: 0x7ffa306aa000: 4096 0x7ffa306ac000: 4096 0x7ffa306ae000: 4096 0x7ffa306b0000: 4096
   2: 0x7ffa306aa000: 4096 0x7ffa306ac000: 4096 0x7ffa306ae000: 4096 0x7ffa306b0000: 4096
   4: 0x7ffa306aa000: 4096 0x7ffa306ac000: 4096 0x7ffa306ae000: 4096 0x7ffa306b0000: 4096
   7: 0x7ffa306aa000: 4096 0x7ffa306ac000: 4096 0x7ffa306ae000: 4096 0x7ffa306b0000: 4096

With ElectricFence and EF_ALIGNMENT=16 which force an alignment of 16 bytes:

$ EF_ALIGNMENT=16 ef ./malloc-alignment

  Electric Fence 2.2.2 Copyright (C) 1987-1999 Bruce Perens <bruce>
   1: 0x7f5289642ff0:   16 0x7f5289644ff0:   16 0x7f5289646ff0:   16 0x7f5289648ff0:   16
   2: 0x7f5289642ff0:   16 0x7f5289644ff0:   16 0x7f5289646ff0:   16 0x7f5289648ff0:   16
   4: 0x7f5289642ff0:   16 0x7f5289644ff0:   16 0x7f5289646ff0:   16 0x7f5289648ff0:   16
   7: 0x7f5289642ff0:   16 0x7f5289644ff0:   16 0x7f5289646ff0:   16 0x7f5289648ff0:   16

And at last, with ElectricFence, still with default parameters

$ ef ./malloc-alignment

  Electric Fence 2.2.2 Copyright (C) 1987-1999 Bruce Perens <bruce>
   1: 0x7fb4334cdffc:    4 0x7fb4334cfffc:    4 0x7fb4334d1ffc:    4 0x7fb4334d3ffc:    4
   2: 0x7fb4334cdffc:    4 0x7fb4334cfffc:    4 0x7fb4334d1ffc:    4 0x7fb4334d3ffc:    4
   4: 0x7fb4334cdffc:    4 0x7fb4334cfffc:    4 0x7fb4334d1ffc:    4 0x7fb4334d3ffc:    4
   7: 0x7fb4334cdff8:    8 0x7fb4334cfff8:    8 0x7fb4334d1ff8:    8 0x7fb4334d3ff8:    8

With default parameters, ElectricFence returns memory address aligned on 4 bytes at minimum. This should be OK for such small allocations, but the testcase shows also bigger allocations:

  33: 0x7f4cc606dfdc:    4 0x7f4cc606ffdc:    4 0x7f4cc6071fdc:    4 0x7f4cc6073fdc:    4
  65: 0x7f4cc606dfbc:    4 0x7f4cc606ffbc:    4 0x7f4cc6071fbc:    4 0x7f4cc6073fbc:    4
 129: 0x7f4cc606df7c:    4 0x7f4cc606ff7c:    4 0x7f4cc6071f7c:    4 0x7f4cc6073f7c:    4
 257: 0x7f4cc606defc:    4 0x7f4cc606fefc:    4 0x7f4cc6071efc:    4 0x7f4cc6073efc:    4

And here, there's a problem: a block of 33 bytes could store a pointer, a double and an odd string, and *requires* an 8 bytes alignment which is not given by ElectricFence. 

The alignment problem is explained in efence(3) man page in third paragraph of WORD-ALIGNMENT AND OVERRUN DETECTION section : http://linux.die.net/man/3/efence

According to this man page "Unfortunately, malloc() is required to return word-aligned allocations," which is not exactly true regarding ABI and Open Group specification.

ElectricFence must aligned memory by default on the ABI requirements (16 bytes) in order to behave as expected by the applications.

Comment 1 Yann Droneaud 2010-12-10 16:01:38 UTC
*** Bug 662029 has been marked as a duplicate of this bug. ***

Comment 2 Yann Droneaud 2010-12-10 16:03:33 UTC
*** Bug 662017 has been marked as a duplicate of this bug. ***

Comment 3 Yann Droneaud 2010-12-11 22:07:40 UTC
This issue was already discussed in thread "Electric Fence - still reliable?" on fedora-devel-list in december 2009, 
see https://www.redhat.com/archives/fedora-devel-list/2009-December/msg00816.html

Comment 4 Fedora Update System 2011-01-19 19:28:00 UTC
ElectricFence-2.2.2-30.fc14 has been submitted as an update for Fedora 14.
https://admin.fedoraproject.org/updates/ElectricFence-2.2.2-30.fc14

Comment 5 Yann Droneaud 2011-01-20 14:55:17 UTC
(In reply to comment #4)
> ElectricFence-2.2.2-30.fc14 has been submitted as an update for Fedora 14.
> https://admin.fedoraproject.org/updates/ElectricFence-2.2.2-30.fc14

I've tested it on x86_64 and the patch ElectricFence-2.2.2-sse.patch seems to work well.

Comment 6 Fedora Update System 2011-01-20 19:52:49 UTC
ElectricFence-2.2.2-30.fc14 has been pushed to the Fedora 14 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update ElectricFence'.  You can provide feedback for this update here: https://admin.fedoraproject.org/updates/ElectricFence-2.2.2-30.fc14

Comment 7 Fedora Update System 2011-01-28 19:20:31 UTC
ElectricFence-2.2.2-30.fc14 has been pushed to the Fedora 14 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.