polkit: switch back to mozjs but leave duktape as PACKAGECONFIG option

https://bugzilla.yoctoproject.org/show_bug.cgi?id=14829 reports
that duktape isn't fully compatible with mozjs as the supported
javascript features are different. duktape supports
ECMAScript standard version 5 while mozjs supports a lot more.
See https://kangax.github.io/compat-table/es5/ for the differences.
Thus the change from mozjs to duktape may break some rules
which rely on javascript features which duktape doesn't support,
for example array.includes() function,
https://kangax.github.io/compat-table/es6/
https://262.ecma-international.org/7.0/#sec-array.prototype.includes

For many embedded systems which care about fast boot times and smaller
rootfs using duktape is recommended but rules must be written in reduced
set of ECMA script language features. For array.includes() one alternative
is "array.indexOf(search) >= 0".

[YOCTO #14829]

Signed-off-by: Mikko Rapeli <mikko.rapeli@bmw.de>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
This commit is contained in:
Mikko Rapeli
2022-06-13 09:12:05 +03:00
committed by Khem Raj
parent 783c130976
commit 461ceffc48
3 changed files with 117 additions and 3 deletions
@@ -0,0 +1,38 @@
From 4ce27b66bb07b72cb96d3d43a75108a5a6e7e156 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@mengyan1223.wang>
Date: Tue, 10 Aug 2021 19:09:42 +0800
Subject: [PATCH] jsauthority: port to mozjs-91
Upstream-Status: Submitted [https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/92]
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
configure.ac | 2 +-
meson.build | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index d807086..5a7fc11 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,7 +80,7 @@ PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.30.0])
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
-PKG_CHECK_MODULES(LIBJS, [mozjs-78])
+PKG_CHECK_MODULES(LIBJS, [mozjs-91])
AC_SUBST(LIBJS_CFLAGS)
AC_SUBST(LIBJS_CXXFLAGS)
diff --git a/meson.build b/meson.build
index b3702be..733bbff 100644
--- a/meson.build
+++ b/meson.build
@@ -126,7 +126,7 @@ expat_dep = dependency('expat')
assert(cc.has_header('expat.h', dependencies: expat_dep), 'Can\'t find expat.h. Please install expat.')
assert(cc.has_function('XML_ParserCreate', dependencies: expat_dep), 'Can\'t find expat library. Please install expat.')
-mozjs_dep = dependency('mozjs-78')
+mozjs_dep = dependency('mozjs-91')
dbus_dep = dependency('dbus-1')
dbus_confdir = dbus_dep.get_pkgconfig_variable('datadir', define_variable: ['datadir', pk_prefix / pk_datadir]) #changed from sysconfdir with respect to commit#8eada3836465838
@@ -0,0 +1,63 @@
From 7799441b9aa55324160deefbc65f9d918b8c94c1 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@mengyan1223.wang>
Date: Tue, 10 Aug 2021 18:52:56 +0800
Subject: [PATCH] jsauthority: ensure to call JS_Init() and JS_ShutDown()
exactly once
Before this commit, we were calling JS_Init() in
polkit_backend_js_authority_class_init and never called JS_ShutDown.
This is actually a misusage of SpiderMonkey API. Quote from a comment
in js/Initialization.h (both mozjs-78 and mozjs-91):
It is currently not possible to initialize SpiderMonkey multiple
times (that is, calling JS_Init/JSAPI methods/JS_ShutDown in that
order, then doing so again).
This misusage does not cause severe issues with mozjs-78. However, when
we eventually port jsauthority to use mozjs-91, bad thing will happen:
see the test failure mentioned in #150.
This commit is tested with both mozjs-78 and mozjs-91, all tests pass
with it.
Upstream-Status: Submitted [https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/91]
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
src/polkitbackend/polkitbackendjsauthority.cpp | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp
index 41d8d5c..38dc001 100644
--- a/src/polkitbackend/polkitbackendjsauthority.cpp
+++ b/src/polkitbackend/polkitbackendjsauthority.cpp
@@ -75,6 +75,13 @@
/* ---------------------------------------------------------------------------------------------------- */
+static class JsInitHelperType
+{
+public:
+ JsInitHelperType() { JS_Init(); }
+ ~JsInitHelperType() { JS_ShutDown(); }
+} JsInitHelper;
+
struct _PolkitBackendJsAuthorityPrivate
{
gchar **rules_dirs;
@@ -589,7 +596,6 @@ polkit_backend_js_authority_finalize (GObject *object)
delete authority->priv->js_polkit;
JS_DestroyContext (authority->priv->cx);
- /* JS_ShutDown (); */
G_OBJECT_CLASS (polkit_backend_js_authority_parent_class)->finalize (object);
}
@@ -665,8 +671,6 @@ polkit_backend_js_authority_class_init (PolkitBackendJsAuthorityClass *klass)
g_type_class_add_private (klass, sizeof (PolkitBackendJsAuthorityPrivate));
-
- JS_Init ();
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -5,7 +5,7 @@ LICENSE = "LGPL-2.0-or-later"
LIC_FILES_CHKSUM = "file://COPYING;md5=155db86cdbafa7532b41f390409283eb \
file://src/polkit/polkit.h;beginline=1;endline=20;md5=0a8630b0133176d0504c87a0ded39db4"
DEPENDS = "expat glib-2.0 intltool-native duktape"
DEPENDS = "expat glib-2.0 intltool-native"
inherit autotools gtk-doc pkgconfig useradd systemd gobject-introspection features_check
@@ -14,6 +14,7 @@ REQUIRED_DISTRO_FEATURES = "polkit"
PACKAGECONFIG = "${@bb.utils.filter('DISTRO_FEATURES', 'pam', d)} \
${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'systemd', \
bb.utils.contains('DISTRO_FEATURES', 'x11', 'consolekit', '', d), d)} \
mozjs \
"
PACKAGECONFIG[pam] = "--with-authfw=pam,--with-authfw=shadow,libpam,libpam"
@@ -21,20 +22,32 @@ PACKAGECONFIG[systemd] = "--enable-libsystemd-login=yes --with-systemdsystemunit
# there is no --enable/--disable option for consolekit and it's not picked by shlibs, so add it to RDEPENDS
PACKAGECONFIG[consolekit] = ",,,consolekit"
# Default to mozjs javascript library
PACKAGECONFIG[mozjs] = ",,mozjs-91,,,duktape"
# duktape javascript engine is much smaller and faster but is not compatible with
# same javascript standards as mozjs. For example array.includes() function is not
# supported. Test rule compatibility when switching to duktape.
PACKAGECONFIG[duktape] = "--with-duktape,,duktape,,,mozjs"
MOZJS_PATCHES = "\
file://0002-jsauthority-port-to-mozjs-91.patch \
file://0003-jsauthority-ensure-to-call-JS_Init-and-JS_ShutDown-e.patch \
"
DUKTAPE_PATCHES = "file://0003-Added-support-for-duktape-as-JS-engine.patch"
PAM_SRC_URI = "file://polkit-1_pam.patch"
SRC_URI = "http://www.freedesktop.org/software/polkit/releases/polkit-${PV}.tar.gz \
${@bb.utils.contains('DISTRO_FEATURES', 'pam', '${PAM_SRC_URI}', '', d)} \
${@bb.utils.contains('PACKAGECONFIG', 'mozjs', '${MOZJS_PATCHES}', '', d)} \
${@bb.utils.contains('PACKAGECONFIG', 'duktape', '${DUKTAPE_PATCHES}', '', d)} \
file://0003-make-netgroup-support-optional.patch \
file://0001-pkexec-local-privilege-escalation-CVE-2021-4034.patch \
file://0002-CVE-2021-4115-GHSL-2021-077-fix.patch \
file://0003-Added-support-for-duktape-as-JS-engine.patch \
"
SRC_URI[sha256sum] = "c8579fdb86e94295404211285fee0722ad04893f0213e571bd75c00972fd1f5c"
EXTRA_OECONF = "--with-os-type=moblin \
--disable-man-pages \
--disable-libelogind \
--with-duktape \
"
do_configure:prepend () {