Skip to content

SIGILL in _armv7_tick with big.LITTLE processors #14838

Closed

Description

@DirtYiCE

We have a few HiKey 960 test boards running Android 9, and sometimes our tests crashes with SIGILL on these machines in _armv7_tick. These boards have a big.LITTLE processor with four Cortex-A73 and four Cortex-A53, and it looks like the CNTVCT instruction used by _armv7_tick is only supported by one processor type. OpenSSL does a runtime detection for CNTVCT support at startup in OPENSSL_cpuid_setup by executing the instruction and if it does not fail it assumes support is available. The problem is that if this feature detection is done on a core that supports CNTVCT and the kernel later migrates the process to a core that doesn't, OpenSSL randomly crashes (mostly when reseeding the RNG).

I've created a little test program

int main()
{
  asm volatile("mrrc p15, 1, r0, r1, c14");
}

Running this program on one of these test-boards usually crashes with a SIGILL, but if I place load on the system (by running a few processes using 100% CPU), the program sometimes executes successfully.

What is the recommended way to deal with this issue? Disable runtime detection altogether? It looks like for other CPU features OpenSSL already uses getauxval, and hopefully the kernel can determine correctly what is supported even with big.LITTLE CPUs, so only CNTVCT is problematic.

OpenSSL version: 1.1.1k, custom build.

Activity

  1. added
    issue: bug report
    on Apr 12, 2021
  2. davidben commented on Apr 12, 2021

    @davidben
    Contributor

    In addition to avoiding this kind of problem, the SIGILL probe that OpenSSL uses also isn't thread-safe and will interfere with applications that may be doing interesting things with SIGILL themselves. Best to avoid the probing stuff altogether and stick to platform-supported mechanisms for detecting features on ARM. (getauxval, IsProcessorFeaturePresent, sysctlbyname, defined(__ARM_FOO), etc.)

  3. added
    branch: 1.1.1
    branch: master
    triaged: bug
    and removed
    issue: bug report
    on Apr 12, 2021
  4. dlegaultbbry commented on Apr 15, 2021

    @dlegaultbbry

    For the tick part, I haven't seen that covered in HWCAP nor could I find any ARM docs that suggested how this 'feature' is detectable through some feature registers somewhere. So how would one work around that one assuming all the others (NEON, AES, etc.) are all things that are covered in HWCAP?

  5. davidben commented on Apr 15, 2021

    @davidben
    Contributor

    ARM feature detection tends to be platform-specific, hence getauxval and friends. If there isn't a corresponding entry in getauxval, it may be that this isn't really well-supported on Linux and OpenSSL shouldn't be calling it. (Looks like it's used as an extra source of entropy, but seeing as this isn't a good entropy source anyway, it's probably not worth the trouble.)

  6. paulidale commented on Apr 16, 2021

    @paulidale
    Contributor

    It seems like we'd need to probe the CPU, know enough about it to know that it is a big.LITTLE processor and then limit ourselves to the LITTLE subset. I don't think we're in a position where we can have an instruction trap and switch to the LITTLE path instead. As @davidben notes, this could possibly be done at build time.

  7. davidben commented on Apr 16, 2021

    @davidben
    Contributor

    Well, I think you should look at a combination of things:

    • If __ARM_NEON, etc., are defined, the platform has configured the feature to be statically available. Then OpenSSL can also treat the feature as available. In fact, if you arrange for the capability check to be statically 1, the compiler can drop the fallback code and reduce code size. This can be done on all platforms. For instance, the Android NDK defaults to requiring NEON these days, and many iOS and macOS capabilities are static (below).
    • If on a Linux-based platform, getauxval is the way to go for features beyond static capabilities. On older Android, you may need to pull in getauxval as a weak pointer and either fall back to the static config or other mechanism if missing. (Historically, on older Androids, we needed a mess of fallbacks and workarounds including /proc/cpuinfo and /proc/self/auxv. This is less important now.)
    • If on Windows, use IsProcessorFeaturePresent.
    • If on iOS or macOS, sysctlbyname is the API, but you'll also need to check __ARM_NEON and friends. Most of the features used by OpenSSL are part of the baseline for iOS and macOS, so they aren't even present in sysctlbyname. But I imagine later features will use sysctlbyname since the baseline already exists.
    • If some other platform, do what that platform expects.

    This is sadly a bit messier than x86, where userspace can easily access CPUID information. But I don't think SIGILL is the right strategy.

  8. cgutman commented on May 5, 2021

    @cgutman
    Contributor

    I also saw some instances of this crash in Google Play crash reports from the field. I disassembled my native library and matched the reported PC at the time of the crash to _armv7_tick (specifically the mrrc p15,1,r0,r1,c14 instruction).

    So far, I see these crashes occurring on the following devices so far:
    My Android TV (codename: tokyo) - MStar T16 SoC - Android 9
    Xiaomi MiTV (codename: croods) - MediaTek T31 SoC - Android 10

    Interestingly, the MediaTek T31 is not a big.LITTLE processor. It has a single homogenous set of Cortex A55 cores, so there must be something more at play (at least in my case) than simply getting migrated to the little cores. Perhaps the kernel doesn't set CNTKCTL.PL0VCTEN == 1 to enable reading CNTVCT from user-mode on these devices? I guess that still doesn't explain why the SIGILL handler didn't work though.

  9. added
    help wanted
    on May 6, 2021
  10. gdevillele commented on Apr 19, 2023

    @gdevillele

    I can repro this on the Samsung Galaxy A6 smartphone (big.LITTLE), only when running with debugger attached so far.
    (not sure why)

    I would love this to get fixed, and I am ready to help if I can.

  11. paulidale commented on Apr 19, 2023

    @paulidale
    Contributor

    My guess would be that the phone isn't migrating the process between from the big to the little processor normally. In the debugger it is because it's mostly idle time waiting for human input.

    Any fix boils down to OpenSSL needing better feature probing using the OS's capabilities. ARM feature detection is a bit horrible to be honest.

  12. cgutman commented on Apr 19, 2023

    @cgutman
    Contributor

    This is already fixed in OpenSSL 3.0 and later branches via 6c3728c. Backporting to 1.1.1 should be pretty trivial.

  13. gdevillele commented on Apr 20, 2023

    @gdevillele

    @cgutman thanks a lot for the commit link! I did the backport and am now testing it. Will submit a 1.1.1 PR if it works.
    (my first OpenSSL contribution, yay 😄)

  14. added 2 commits that reference this issue on May 4, 2023
    b184fcf
    fc9dfb2
  15. tom-cosgrove-arm commented on Jul 27, 2023

    @tom-cosgrove-arm
    Contributor

    This is not going to be fixed in 1.1.1 as it is going to be end-of-life on 11 September this year, and is only receiving security fixes now.

    It was fixed in 3.0 and subsequent releases by #18852

  16. added
    resolved: fixed
    backlog fix
    and removed
    branch: master
    help wanted
    on Jan 23, 2026
  17. t8m commented on Jan 23, 2026

    @t8m
    Member

    This is fixed in current releases. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlog fixbranch: 1.1.1resolved: fixedtriaged: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions