[PATCH v6 1/2] elf: Properly align PT_LOAD segments [BZ #28676]

Rongwei Wang rongwei.wang@linux.alibaba.com
Mon Dec 13 14:51:57 GMT 2021



On 12/13/21 7:52 PM, Szabolcs Nagy via Libc-alpha wrote:
> The 12/13/2021 12:46, Andreas Schwab wrote:
>> On Dez 13 2021, Rongwei Wang via Libc-alpha wrote:
>>
>>> +  else
>>> +    {
>>> +      /* Unmap the unused regions.  */
>>> +      ElfW(Addr) delta = map_start_aligned - map_start;
>>> +      if (delta)
>>> +	__munmap ((void *) map_start, delta);
>>> +      ElfW(Addr) map_end = map_start_aligned + maplength;
>>> +      delta = map_start + maplen - map_end;
>>> +      if (delta)
>>> +	__munmap ((void *) map_end, delta);
>>
>> I don't think map_end is guaranteed to be page-aligned.
> 
> indeed i see failing munmap syscalls in strace
Hi, Szabolcs

Thanks for your test! I have no arm32 environment, and ignoring this test.

It seems the 'map_end' need to be page-aligned before calling munmap.
The following code only update the first line to fix this bug:

+      ElfW(Addr) map_end = ALIGN_UP(map_start_aligned + maplength, 
GLRO(dl_pagesize));
+      delta = map_start + maplen - map_end;
+      if (delta)
+	__munmap ((void *) map_end, delta);

Can you help me test this new code again if available?

Thanks.

> 
> ..
> 3161105 munmap(0xf7973040, 57344)       = -1 EINVAL (Invalid argument)
> 3161105 munmap(0xf79591d4, 24576)       = -1 EINVAL (Invalid argument)
> 3161107 munmap(0xf6031038, 45056)       = -1 EINVAL (Invalid argument)
> 3161108 munmap(0xf56f1038, 53248)       = -1 EINVAL (Invalid argument)
> ...
> 


More information about the Libc-alpha mailing list