test_030_mmap_min in ubuntu_qrt_kernel_security failed on 5.11/5.13/5.15 ARM64k

Bug #1931393 reported by Po-Hsu Lin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QA Regression Testing
Fix Released
Undecided
Unassigned
ubuntu-kernel-tests
Fix Released
Undecided
Unassigned

Bug Description

Issue found on 5.11.0-20.21-generic-64k and 5.8.0-56.63-generic-64k with arm64 instances on aws cloud (instance a1.2xlarge, a1.medium, c6g.8xlarge)

  ======================================================================
  FAIL: test_030_mmap_min (__main__.KernelSecurityTest)
  Low memory allocation respects mmap_min_addr
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "./test-kernel-security.py", line 289, in test_030_mmap_min
      self.assertShellExitEquals(expected, ['sudo', '-u', os.environ['SUDO_USER'], "./low-mmap", '%d' % (wanted)])
    File "/home/ubuntu/autotest/client/tmp/ubuntu_qrt_kernel_security/src/qa-regression-testing/scripts/testlib.py", line 1166, in assertShellExitEquals
      self.assertEqual(expected, rc, msg + result + report)
  AssertionError: Got exit code 1, expected 0
  Command: 'sudo', '-u', 'ubuntu', './low-mmap', '32768'
  Output:
  Testing lower 32768 bytes in 65536 byte chunks: pass (could not allocate memory)
  Testing 65536 byte chunk above 32767:
   Unexpectedly unable to allocate 65536 bytes at 0x00000000
  FAIL (cannot allocate memory)

This is not a regression as it can be found in 5.11.0-14.15-generic-64k and 5.8.0-52.59-generic-64k as well.

Also, it looks like this issue does not exist on generic arm64 kernel with the same instance.

Po-Hsu Lin (cypressyew)
tags: added: arm64 sru-20210531
tags: added: 5.11 5.8 ubuntu-qrt-kernel-security
description: updated
Revision history for this message
Kleber Sacilotto de Souza (kleber-souza) wrote :

Found with hirsute/linux 5.11.0-26.28.

tags: added: sru-20210719
Revision history for this message
Stefan Bader (smb) wrote :

Is mmap_min_addr working on arm64 with the generic-64k flavour? Or rather supposed to, maybe that is a x86 thing...

Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

Hi Stefan,
yes this test_030_mmap_min test passed with generic arm64, but not generic-64k arm64

5.11.0-38.4 with appleton arm64:
 test_030_mmap_min (__main__.KernelSecurityTest)
 Low memory allocation respects mmap_min_addr ... (32768) ok

Revision history for this message
Steve Beattie (sbeattie) wrote :

I suspect with the 64k pages, that the mmap_min_addr has to be page aligned, and so might be getting set or rounded to 64k instead of 32k like on arm64 with 4k pages. I say this because it looks like from the testcase output that it is correctly blocking the attempt to mmap the lowest 32k, but also unexpectedly blocking the next 32k, where the test expects mmap_min_addr to be 32k on arm64.

What is the contents of /proc/sys/vm/mmap_min_addr on such a system, as well as the output of 'grep PageSize /proc/self/smaps | sort | uniq'?

Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

Hi Steve,
here is the output from an AWS a1.medium instance running with H-5.11 generic-64k:

$ uname -a
Linux ip-172-31-9-86 5.11.0-38-generic-64k #42-Ubuntu SMP Fri Sep 24 15:47:04 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
$ cat /proc/sys/vm/mmap_min_addr
32768
$ grep PageSize /proc/self/smaps | sort | uniq
KernelPageSize: 64 kB
MMUPageSize: 64 kB

Revision history for this message
Steve Beattie (sbeattie) wrote :

Hey Po-Hsu, I attempted to get a generic/generic-64k kernel to boot in ec2 and never got it to recognize the root device, so I couldn't reporduce the failure. That said, from what I've read it and what the failed tests report indicates that despite the kernel reporting mmap_min_addr of 32k, the kernel enforces it by pages so on a 64k page system, the actual enforced value will be 64k.

I have gone ahead and committed a fix to QRT that checks for whether CONFIG_ARM64_64K_PAGES is enabled and keeps the expected 64k enforced value if so: https://git.launchpad.net/qa-regression-testing/commit/?id=d56f3347a1f69c06be638ca6b6917083143ce5a4

I verified that it didn't trigger with the regular aws arm kernel, but it would be great if you could validate the adjusted test on arm64 + 64k page environment.

Thanks!

Changed in qa-regression-testing:
status: New → Fix Committed
Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

Hello Steve,
sorry for the late reply, I think it can be reproduced on a arm64 bare-metal system. This test is now failing with a different error message.

On A 5.11.0-39.43 generic-64k ARM64 bare-metal node "dazzle":
    ======================================================================
    FAIL: test_030_mmap_min (__main__.KernelSecurityTest)
    Low memory allocation respects mmap_min_addr
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "./test-kernel-security.py", line 285, in test_030_mmap_min
        mmap_limit = self._test_sysctl_value('vm/mmap_min_addr', wanted, "is wine or qemu-kvm-extras-static installed?")
      File "/home/ubuntu/autotest/client/tmp/ubuntu_qrt_kernel_security/src/qa-regression-testing/scripts/testlib.py", line 1269, in _test_sysctl_value
        self.assertEqual(value, expected, report)
    AssertionError: /proc/sys/vm/mmap_min_addr is not 65536: 32768 (is wine or qemu-kvm-extras-static installed?)

Test suite HEAD SHA1: 07a33cbe

This can be spotted with 5.11.0-39.43 generic-64k on a1.medium / a1.metal / c6g.8xlarge
and 5.13.0-21.21 generic-64k as well.

Po-Hsu Lin (cypressyew)
tags: added: 5.13 jammy
tags: added: 5.15
summary: - test_030_mmap_min in ubuntu_qrt_kernel_security failed on 5.11 ARM64k
+ test_030_mmap_min in ubuntu_qrt_kernel_security failed on 5.11/5.13/5.15
+ ARM64k
Revision history for this message
Thadeu Lima de Souza Cascardo (cascardo) wrote :
Revision history for this message
Steve Beattie (sbeattie) wrote :

Cascardo, nice catch, merged. Thanks.

Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

I can confirm that with Cascardo's fix, the low-mmap test in test_030_mmap_min is now green.

$ sudo -u ubuntu ./low-mmap 65536
Testing lower 65536 bytes in 65536 byte chunks: pass (could not allocate memory)
Testing 65536 byte chunk above 65535: pass (able to allocate memory)

Closing this bug base on this result.

However the zero-possible test is failing (unexpected pass), please see bug 2002503

Revision history for this message
Po-Hsu Lin (cypressyew) wrote :

Hints retired. Thanks.

Changed in ubuntu-kernel-tests:
status: New → Fix Released
Changed in qa-regression-testing:
status: Fix Committed → Fix Released
tags: added: kinetic
tags: added: sru-20221114 sru-20230102
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.