Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getauxval on Android with API level > 18 #11257

Conversation

larsimmisch-adobe
Copy link
Contributor

One of the android applications we work on received analytics that devices of the device family Oppo A37x were crashing with SIGILL when trying to load a bundled libcrypto.so built from OpenSSL_1_1_1c.

This device family has a SnapDragon 410 processor: https://www.qualcomm.com/products/snapdragon-processors-410, which is based upon an ARM Cortex A53

These crashes were fixed by using the system-supplied getauxval function.

@petrovr
Copy link

petrovr commented Mar 6, 2020 via email

@kroeckx
Copy link
Member

kroeckx commented Mar 6, 2020

This is runtime detection. We ask the Linux kernel what it detected, rather than running some instructions to see if the CPU supports that instruction or not. We prefer to ask the kernel. We already use getauxval() if you have a recent enough glibc.

I'm not sure when the SIGILL is being seen, but I assume that either it's running in a debugger, or Android somehow doesn't allow us to catch the SIGILL.

@kroeckx kroeckx added approval: review pending This pull request needs review by a committer branch: 1.1.1 Merge to OpenSSL_1_1_1-stable branch branch: master Merge to master branch labels Mar 6, 2020
@kroeckx kroeckx added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Mar 6, 2020
@petrovr
Copy link

petrovr commented Mar 7, 2020 via email

@petrovr
Copy link

petrovr commented Mar 7, 2020 via email

@levitte
Copy link
Member

levitte commented Mar 7, 2020

@petrovr, PR welcome!

@t-j-h
Copy link
Member

t-j-h commented Mar 7, 2020

This check is perfectly valid in this context - when building an application at that API level the syscall is available. Sure you could add a dynamic solution to detect at runtime - and naturally a PR with that in it would be welcome - although testing that would be a "fun" exercise to organise. However this improves the situation for those targeting most currently active android releases.

Keep in mind that Android API level 18 is from 2013 (Aka Android release 4.3).

@petrovr
Copy link

petrovr commented Mar 7, 2020 via email

@levitte
Copy link
Member

levitte commented Mar 7, 2020

which model

Whichever you think is more suitable. It really depends on if you're going to code this for Android only (where it's probably easier to specify weak symbols consistently) or in a more generic way (it may be easier to check for symbols with DSO functions).

Your pick

@petrovr
Copy link

petrovr commented Mar 7, 2020

The test show that "global lookup" does not work - YAAL (yet another android limitation).
Solution with weak alias is fine. Test case:

#include <stdio.h>
#include <errno.h>

#  define HWCAP                  16


static unsigned long
my1_getauxval(unsigned long type) {
  extern unsigned long getauxval(unsigned long type) __attribute__((weak));
  if (getauxval != NULL)  return getauxval(type) ;
  /**/
  errno = ENOENT;
  return 0;
}

#define getauxval my1_getauxval
void test1() {
   unsigned long flags = getauxval(HWCAP);
   fprintf(stderr, "1-getauxval(HWCAP): 0x%lx, errno: %d\n", flags, errno);
}
#undef getauxval


#include <dlfcn.h>
static unsigned long
my2_getauxval(unsigned long type) {
  static unsigned long (*getauxval_f)(unsigned long type) = NULL;
  static int init = 1;

  if (init) {
    void *handle;
    init = 0;
    handle = dlopen(NULL, RTLD_LOCAL);
    if (handle != NULL) {
      union {
          void *v;
          unsigned long (*f)(unsigned long);
      } t;
      t.v = dlsym(handle, "getauxval");
      getauxval_f = t.f;
      dlclose(handle);
    }
  }

  if (getauxval_f != NULL)  return getauxval_f(type) ;
  /**/
  errno = ENOENT;
  return 0;
}

#define getauxval my2_getauxval
void test2() {
   unsigned long flags = getauxval(HWCAP);
   fprintf(stderr, "2-getauxval(HWCAP): 0x%lx, errno: %d\n", flags, errno);
}
#undef getauxval


int
main() {
  test1();
  test2();
  return 0;
}

@openssl openssl deleted a comment from openssl-machine Mar 9, 2020
@openssl-machine
Copy link
Collaborator

24 hours has passed since 'approval: done' was set, but as this PR has been updated in that time the label 'approval: ready to merge' is not being automatically set. Please review the updates and set the label manually.

@kroeckx
Copy link
Member

kroeckx commented Mar 10, 2020

@iamamoose: I think the "PR has been updated" text is confusing. I assume you mean someone commented on it?

@kroeckx kroeckx added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Mar 10, 2020
@levitte levitte added the cla: trivial One of the commits is marked as 'CLA: trivial' label Mar 10, 2020
@levitte
Copy link
Member

levitte commented Mar 10, 2020

Hoooold on!

I just noticed that the commit message marks this as trivial. I'm not sure I agree with that, and would like to hear what others think.

This is NOT ready to merge at this point

@levitte levitte removed the approval: ready to merge The 24 hour grace period has passed, ready to merge label Mar 10, 2020
@kroeckx
Copy link
Member

kroeckx commented Mar 10, 2020

Why wasn't the CLA: trivial label set earlier?

@iamamoose
Copy link
Member

@iamamoose: I think the "PR has been updated" text is confusing. I assume you mean someone commented on it?

It currently means a comment or a label change but should also mean a further push (it just doesn't check for that yet). Do you have any preferred wording "but this PR has had a comment or change" perhaps?

@mattcaswell
Copy link
Member

Why wasn't the CLA: trivial label set earlier?

AFAIK there is no automatic labelling if a commit contains "CLA: trivial" in the header.It's purely manual. Perhaps @iamamoose could work his magic...?

@iamamoose
Copy link
Member

Why wasn't the CLA: trivial label set earlier?

AFAIK there is no automatic labelling if a commit contains "CLA: trivial" in the header.It's purely manual. Perhaps @iamamoose could work his magic...?

openssl/tools#63

@levitte levitte removed the cla: trivial One of the commits is marked as 'CLA: trivial' label Mar 11, 2020
@paulidale paulidale reopened this Jun 14, 2021
@openssl-machine
Copy link
Collaborator

This PR has the label 'hold: cla required' and is stale: it has not been updated in 61 days. Note that this PR may be automatically closed in the future if no CLA is provided. For CLA help see https://www.openssl.org/policies/cla.html

@paulidale
Copy link
Contributor

CLA is in: the commit needs to have it's author changed.

@paulidale paulidale removed the cla: trivial One of the commits is marked as 'CLA: trivial' label Jun 15, 2021
@t8m t8m added the triaged: bug The issue/pr is/fixes a bug label Jun 15, 2021
… crashing with SIGILL when trying to load libcrypto.so. These crashes were fixed by using the system-supplied getauxval function.
@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Jun 15, 2021
@larsimmisch-adobe
Copy link
Contributor Author

Reopening PR with Author fixed to match iCLA

@paulidale paulidale added the approval: done This pull request has the required number of approvals label Jun 15, 2021
@paulidale
Copy link
Contributor

I don't think this should be merged to 1.1.1.

@t8m
Copy link
Member

t8m commented Jun 15, 2021

I don't think this should be merged to 1.1.1.

That's IMO debatable. But yeah, it is not a straight bug fix, rather a cleanup thing or improved platform support.

@t8m
Copy link
Member

t8m commented Jun 15, 2021

IMO OTC (or OMC? I never know who gives these exception approvals) would have to approve this as an exception to be merged to 1.1.1

@paulidale
Copy link
Contributor

OTC would need to clear this going into 1.1.1.

@t8m
Copy link
Member

t8m commented Jun 15, 2021

Also I think this can be merged to master straight away as this was approved looong time ago and the only thing to be resolved was the CLA.

@t8m
Copy link
Member

t8m commented Jun 15, 2021

@larsimmisch-adobe if you care about having this change in 1.1.1 could you please open a separate pull request against that branch?

@t8m t8m added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed branch: 1.1.1 Merge to OpenSSL_1_1_1-stable branch approval: done This pull request has the required number of approvals labels Jun 15, 2021
openssl-machine pushed a commit that referenced this pull request Jun 15, 2021
We received analytics that devices of the device family Oppo A37x
are crashing with SIGILL when trying to load libcrypto.so.
These crashes were fixed by using the system-supplied getauxval function.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #11257)
@t8m
Copy link
Member

t8m commented Jun 15, 2021

Merged to master. I've reformatted the commit message and supplied proper subject during merging. Thank you for the contribution!

@larsimmisch-adobe
Copy link
Contributor Author

@t8m It makes sense to have this in 1.1.1, so I have opened #15763.

Thanks!

@petrovr
Copy link

petrovr commented Jun 16, 2021 via email

devnexen pushed a commit to devnexen/openssl that referenced this pull request Jul 7, 2021
We received analytics that devices of the device family Oppo A37x
are crashing with SIGILL when trying to load libcrypto.so.
These crashes were fixed by using the system-supplied getauxval function.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#11257)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch triaged: bug The issue/pr is/fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.