You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SIGILL in _armv7_tick with big.LITTLE processors #14838
backlog fixThe issue was closed as part of the backlog reduction initiative.branch: 1.1.1Applies to OpenSSL_1_1_1-stable branch (EOL)resolved: fixedThis issue has been fixedtriaged: bugThe issue/pr is/fixes a bug
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).
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.
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.)
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?
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.)
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.
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.
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.
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.
@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 😄)
backlog fixThe issue was closed as part of the backlog reduction initiative.branch: 1.1.1Applies to OpenSSL_1_1_1-stable branch (EOL)resolved: fixedThis issue has been fixedtriaged: bugThe issue/pr is/fixes a bug
Activity
davidben commentedon Apr 12, 2021
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.)dlegaultbbry commentedon Apr 15, 2021
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?
davidben commentedon Apr 15, 2021
ARM feature detection tends to be platform-specific, hence
getauxvaland friends. If there isn't a corresponding entry ingetauxval, 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.)paulidale commentedon Apr 16, 2021
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.
davidben commentedon Apr 16, 2021
Well, I think you should look at a combination of things:
__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).getauxvalis the way to go for features beyond static capabilities. On older Android, you may need to pull ingetauxvalas 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/cpuinfoand/proc/self/auxv. This is less important now.)IsProcessorFeaturePresent.sysctlbynameis the API, but you'll also need to check__ARM_NEONand friends. Most of the features used by OpenSSL are part of the baseline for iOS and macOS, so they aren't even present insysctlbyname. But I imagine later features will usesysctlbynamesince the baseline already exists.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.
cgutman commentedon May 5, 2021
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 themrrc p15,1,r0,r1,c14instruction).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 == 1to enable reading CNTVCT from user-mode on these devices? I guess that still doesn't explain why the SIGILL handler didn't work though.gdevillele commentedon Apr 19, 2023
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.
paulidale commentedon Apr 19, 2023
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.
cgutman commentedon Apr 19, 2023
This is already fixed in OpenSSL 3.0 and later branches via 6c3728c. Backporting to 1.1.1 should be pretty trivial.
gdevillele commentedon Apr 20, 2023
@cgutman thanks a lot for the commit link! I did the backport and am now testing it. Will submit a
1.1.1PR if it works.(my first OpenSSL contribution, yay 😄)
fix bug with `armv7_tick` probing
fix bug with `armv7_tick` probing
tom-cosgrove-arm commentedon Jul 27, 2023
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
t8m commentedon Jan 23, 2026
This is fixed in current releases. Closing.