[macppc] Unbreak security/nss

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[macppc] Unbreak security/nss

Charlene Wendling
Hi,

As seen in the current powerpc bulk, nss is broken because we don't
implement getauxval(3):

> blinit.c:360:22: error: sys/auxv.h: No such file or directory

It has already been reported upstream [1], but `__has_include()'
is a GCC>=5 feature [2], and i didn't feel like imposing the use of
ports-gcc to other archs, so i adapted it to keep it built with base-gcc.

It then builds fine on macppc [3].

As you can see in the below patch, it's powerpc only where it has never
been built yet, so i did not bump REVISION.

Comments/feedback are welcome,

Charlène.


[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1602743
[2] https://www.gnu.org/software/gcc/gcc-5/changes.html
[3] https://bin.charlenew.xyz/nss.log


Index: patches/patch-nss_lib_freebl_blinit_c
===================================================================
RCS file: patches/patch-nss_lib_freebl_blinit_c
diff -N patches/patch-nss_lib_freebl_blinit_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-nss_lib_freebl_blinit_c 25 Dec 2019 17:36:38 -0000
@@ -0,0 +1,32 @@
+$OpenBSD$
+
+PowerPC only fix. OpenBSD does not support getauxval(3), from:
+https://bugzilla.mozilla.org/show_bug.cgi?id=1602743 ,
+modified to build with base-gcc (__has_include() is gcc>=5).
+
+Index: nss/lib/freebl/blinit.c
+--- nss/lib/freebl/blinit.c.orig
++++ nss/lib/freebl/blinit.c
+@@ -357,7 +357,9 @@ ppc_crypto_support()
+
+ #if defined(__powerpc__)
+
++#if !defined(__OpenBSD__)
+ #include <sys/auxv.h>
++#endif
+
+ // Defines from cputable.h in Linux kernel - PPC, letting us build on older kernels
+ #ifndef PPC_FEATURE2_VEC_CRYPTO
+@@ -368,8 +370,11 @@ static void
+ CheckPPCSupport()
+ {
+     char *disable_hw_crypto = PR_GetEnvSecure("NSS_DISABLE_PPC_GHASH");
++    long hwcaps = 0;
+
+-    long hwcaps = getauxval(AT_HWCAP2);
++#if !defined(__OpenBSD__)
++    hwcaps = getauxval(AT_HWCAP2);
++#endif
+
+     ppc_crypto_support_ = hwcaps & PPC_FEATURE2_VEC_CRYPTO && disable_hw_crypto == NULL;
+ }

Reply | Threaded
Open this post in threaded view
|

Re: [macppc] Unbreak security/nss

Jeremie Courreges-Anglas-2
On Wed, Dec 25 2019, Charlene Wendling <[hidden email]> wrote:

> Hi,
>
> As seen in the current powerpc bulk, nss is broken because we don't
> implement getauxval(3):
>
>> blinit.c:360:22: error: sys/auxv.h: No such file or directory
>
> It has already been reported upstream [1], but `__has_include()'
> is a GCC>=5 feature [2], and i didn't feel like imposing the use of
> ports-gcc to other archs, so i adapted it to keep it built with base-gcc.

In this file there's already fallback code in case __has_include and
getauxval aren't available.  The result is still a bit of a mess but
I think there's a chance to push it upstream.

Could you please give it a try?


Index: patches/patch-nss_lib_freebl_blinit_c
===================================================================
RCS file: patches/patch-nss_lib_freebl_blinit_c
diff -N patches/patch-nss_lib_freebl_blinit_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-nss_lib_freebl_blinit_c 25 Dec 2019 22:22:01 -0000
@@ -0,0 +1,48 @@
+$OpenBSD$
+
+Work around lack of <sys/auxv.h> and getauxval().
+
+Index: nss/lib/freebl/blinit.c
+--- nss/lib/freebl/blinit.c.orig
++++ nss/lib/freebl/blinit.c
+@@ -93,7 +93,7 @@ CheckX86CPUSupport()
+ #endif /* NSS_X86_OR_X64 */
+
+ /* clang-format off */
+-#if defined(__aarch64__) || defined(__arm__)
++#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__)
+ #ifndef __has_include
+ #define __has_include(x) 0
+ #endif
+@@ -115,7 +115,7 @@ static unsigned long (*getauxval)(unsigned long) = NUL
+ #define AT_HWCAP 16
+ #endif
+
+-#endif /* defined(__aarch64__) || defined(__arm__) */
++#endif /* defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) */
+ /* clang-format on */
+
+ #if defined(__aarch64__)
+@@ -357,7 +357,9 @@ ppc_crypto_support()
+
+ #if defined(__powerpc__)
+
++#if __has_include(<sys/auxv.h>)
+ #include <sys/auxv.h>
++#endif
+
+ // Defines from cputable.h in Linux kernel - PPC, letting us build on older kernels
+ #ifndef PPC_FEATURE2_VEC_CRYPTO
+@@ -368,8 +370,11 @@ static void
+ CheckPPCSupport()
+ {
+     char *disable_hw_crypto = PR_GetEnvSecure("NSS_DISABLE_PPC_GHASH");
++    long hwcaps = 0
+
+-    long hwcaps = getauxval(AT_HWCAP2);
++    if (getauxval) {
++        hwcaps = getauxval(AT_HWCAP2);
++    }
+
+     ppc_crypto_support_ = hwcaps & PPC_FEATURE2_VEC_CRYPTO && disable_hw_crypto == NULL;
+ }

--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply | Threaded
Open this post in threaded view
|

Re: [macppc] Unbreak security/nss

Charlene Wendling
On Wed, 25 Dec 2019 23:22:44 +0100
Jeremie Courreges-Anglas wrote:

> On Wed, Dec 25 2019, Charlene Wendling <[hidden email]> wrote:
> > Hi,
> >
> > As seen in the current powerpc bulk, nss is broken because we don't
> > implement getauxval(3):
> >
> >> blinit.c:360:22: error: sys/auxv.h: No such file or directory
> >
> > It has already been reported upstream [1], but `__has_include()'
> > is a GCC>=5 feature [2], and i didn't feel like imposing the use of
> > ports-gcc to other archs, so i adapted it to keep it built with
> > base-gcc.
>
> In this file there's already fallback code in case __has_include and
> getauxval aren't available.  The result is still a bit of a mess but
> I think there's a chance to push it upstream.
>
> Could you please give it a try?

Nice catch, it works fine once a missing semi-colon is added, thanks!

Charlène.


Index: patches/patch-nss_lib_freebl_blinit_c
===================================================================
RCS file: patches/patch-nss_lib_freebl_blinit_c
diff -N patches/patch-nss_lib_freebl_blinit_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-nss_lib_freebl_blinit_c 26 Dec 2019 18:41:48 -0000
@@ -0,0 +1,48 @@
+$OpenBSD$
+
+Work around lack of <sys/auxv.h> and getauxval().
+
+Index: nss/lib/freebl/blinit.c
+--- nss/lib/freebl/blinit.c.orig
++++ nss/lib/freebl/blinit.c
+@@ -93,7 +93,7 @@ CheckX86CPUSupport()
+ #endif /* NSS_X86_OR_X64 */
+
+ /* clang-format off */
+-#if defined(__aarch64__) || defined(__arm__)
++#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__)
+ #ifndef __has_include
+ #define __has_include(x) 0
+ #endif
+@@ -115,7 +115,7 @@ static unsigned long (*getauxval)(unsigned long) = NUL
+ #define AT_HWCAP 16
+ #endif
+
+-#endif /* defined(__aarch64__) || defined(__arm__) */
++#endif /* defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) */
+ /* clang-format on */
+
+ #if defined(__aarch64__)
+@@ -357,7 +357,9 @@ ppc_crypto_support()
+
+ #if defined(__powerpc__)
+
++#if __has_include(<sys/auxv.h>)
+ #include <sys/auxv.h>
++#endif
+
+ // Defines from cputable.h in Linux kernel - PPC, letting us build on older kernels
+ #ifndef PPC_FEATURE2_VEC_CRYPTO
+@@ -368,8 +370,11 @@ static void
+ CheckPPCSupport()
+ {
+     char *disable_hw_crypto = PR_GetEnvSecure("NSS_DISABLE_PPC_GHASH");
++    long hwcaps = 0;
+
+-    long hwcaps = getauxval(AT_HWCAP2);
++    if (getauxval) {
++        hwcaps = getauxval(AT_HWCAP2);
++    }
+
+     ppc_crypto_support_ = hwcaps & PPC_FEATURE2_VEC_CRYPTO && disable_hw_crypto == NULL;
+ }

Reply | Threaded
Open this post in threaded view
|

Re: [macppc] Unbreak security/nss

Jeremie Courreges-Anglas-2
On Thu, Dec 26 2019, Charlene Wendling <[hidden email]> wrote:

> On Wed, 25 Dec 2019 23:22:44 +0100
> Jeremie Courreges-Anglas wrote:
>
>> On Wed, Dec 25 2019, Charlene Wendling <[hidden email]> wrote:
>> > Hi,
>> >
>> > As seen in the current powerpc bulk, nss is broken because we don't
>> > implement getauxval(3):
>> >
>> >> blinit.c:360:22: error: sys/auxv.h: No such file or directory
>> >
>> > It has already been reported upstream [1], but `__has_include()'
>> > is a GCC>=5 feature [2], and i didn't feel like imposing the use of
>> > ports-gcc to other archs, so i adapted it to keep it built with
>> > base-gcc.
>>
>> In this file there's already fallback code in case __has_include and
>> getauxval aren't available.  The result is still a bit of a mess but
>> I think there's a chance to push it upstream.
>>
>> Could you please give it a try?
>
> Nice catch, it works fine once a missing semi-colon is added,

duh

> thanks!

Sure, ok jca@

> Charlène.
>
>
> Index: patches/patch-nss_lib_freebl_blinit_c
> ===================================================================
> RCS file: patches/patch-nss_lib_freebl_blinit_c
> diff -N patches/patch-nss_lib_freebl_blinit_c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-nss_lib_freebl_blinit_c 26 Dec 2019 18:41:48 -0000
> @@ -0,0 +1,48 @@
> +$OpenBSD$
> +
> +Work around lack of <sys/auxv.h> and getauxval().
> +
> +Index: nss/lib/freebl/blinit.c
> +--- nss/lib/freebl/blinit.c.orig
> ++++ nss/lib/freebl/blinit.c
> +@@ -93,7 +93,7 @@ CheckX86CPUSupport()
> + #endif /* NSS_X86_OR_X64 */
> +
> + /* clang-format off */
> +-#if defined(__aarch64__) || defined(__arm__)
> ++#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__)
> + #ifndef __has_include
> + #define __has_include(x) 0
> + #endif
> +@@ -115,7 +115,7 @@ static unsigned long (*getauxval)(unsigned long) = NUL
> + #define AT_HWCAP 16
> + #endif
> +
> +-#endif /* defined(__aarch64__) || defined(__arm__) */
> ++#endif /* defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) */
> + /* clang-format on */
> +
> + #if defined(__aarch64__)
> +@@ -357,7 +357,9 @@ ppc_crypto_support()
> +
> + #if defined(__powerpc__)
> +
> ++#if __has_include(<sys/auxv.h>)
> + #include <sys/auxv.h>
> ++#endif
> +
> + // Defines from cputable.h in Linux kernel - PPC, letting us build on older kernels
> + #ifndef PPC_FEATURE2_VEC_CRYPTO
> +@@ -368,8 +370,11 @@ static void
> + CheckPPCSupport()
> + {
> +     char *disable_hw_crypto = PR_GetEnvSecure("NSS_DISABLE_PPC_GHASH");
> ++    long hwcaps = 0;
> +
> +-    long hwcaps = getauxval(AT_HWCAP2);
> ++    if (getauxval) {
> ++        hwcaps = getauxval(AT_HWCAP2);
> ++    }
> +
> +     ppc_crypto_support_ = hwcaps & PPC_FEATURE2_VEC_CRYPTO && disable_hw_crypto == NULL;
> + }
>

--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE