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.
*** Bug 662029 has been marked as a duplicate of this bug. ***
*** Bug 662017 has been marked as a duplicate of this bug. ***
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
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
(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.
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
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.