ANDROID: 16K: improve robustness of vma padding logic

Clear the VM_PAD_MASK in copy_vma() to ensure that duplicated VMAs do
not inherit padding metadata from the source VMA. This preserves the
property that padding is only defined for the original mappings
created by the dynamic linker and avoids potential inconsistency
when remapped or copied ranges are smaller than the original.

Add a validation check in vma_pad_pages() to ensure the padding count
is always strictly less than the total number of pages in the VMA.
This ensures the returned padding count remains consistent with the
current VMA size and prevents any invalid data page calculations.

Update the linker_ctx() check by verifying the absolute paths of the
dynamic linker binaries. This ensures that the kernel correctly
identifies the dynamic loader context and ensures the migration
logic is only triggered in the intended environment.

Limit the application of padding pages to MAP_PRIVATE mappings in
madvise_vma_pad_pages(). This restriction ensures the logic is only
applied to the private segment mappings used by the dynamic linker
during ELF loading.

Bug: 498369302
Change-Id: Ifc9712b9ec80d32a21fa6c33a666e2ffb515f163
Signed-off-by: Kalesh Singh <[email protected]>
(cherry picked from commit 66044bcf67fccd02311c0030f04ba5f5e7197b8e)
Signed-off-by: Lee Jones <[email protected]>
1 file changed