Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1958111

Summary: bundle mozjs78 in gjs and polkit instead of shipping it as a separate component
Product: Red Hat Enterprise Linux 9 Reporter: Kalev Lember <klember>
Component: mozjs78Assignee: Kalev Lember <klember>
Status: CLOSED CURRENTRELEASE QA Contact: Petr Schindler <pschindl>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.0CC: fmuellner, fsumsal, fzatlouk, jrybar, lnykryn, mcatanza, mclasen, rstrode, tpelka, tpopela
Target Milestone: betaKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: gjs-1.68.1-2.el9 polkit-0.117-6.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-07-07 12:09:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kalev Lember 2021-05-07 08:31:33 UTC
I would like to avoid having to maintain mozjs78 for all of RHEL 9 lifetime. Right now mozjs78 is still supported upstream and is getting fixes as part of Firefox 78 ESR, but that is going to end soon.

mozjs78 has two consumers in RHEL 9: gjs and polkit.

If we end up rebasing gjs and polkit to newer versions during RHEL 9 lifetime, that creates a situation where we are going to have nothing left in the distro that uses mozjs78, but we still have to maintain it as we don't know if any customers are using it or not. I would like to avoid that because mozjs is massive code base (firefox-78.10.0esr.source.tar.xz tarball is 320 MB) and we can't possibly maintain security fixes there for a long time.

Instead, my proposal is to build mozjs78 as a private library and install it in /usr/lib64/polkit and /usr/lib64/gjs, respectively, and retire the system mozjs78.

It used to be that we needed to have mozjs as a shared library because gjs and libproxy both used mozjs symbols that ended up in the same process namespace. This meant that both had to be linked against the exact same libmozjs to avoid symbol clashes and weird crashes. However, libproxy is going away in RHEL 9 (and its mozjs backend is gone in Fedora) so this problem is no more.

Fedora has some other packages that use mozjs, but I think it would be easiest to just build the mozjsXX package that they need in EPEL and avoid shipping it in base RHEL. This way they can be retired more easily once the consumers have moved to a newer mozjs version and nothing uses the old one any more.


Pros of bundling:

- When polkit and mozjs in the future move to a newer mozjs version we can more easily update the bundled copy instead of having to create a new shared component in RHEL.

- Easier to test mozjs fixes: I worked on mozjs s390x fixes for RHEL 8 and it was a pain to test because the fixes went in mozjs, but it was the consumer (gjs) that was failing. If they are in the same package then we can more easily run gjs testsuite in %check against the bundled libmozjs.

- Don't have to maintain a security nightmare for all of RHEL 9 life cycle


Cons of bundling:

- gjs and polkit build times get a lot slower and it's harder to iterate fixes there

- Have to copy any mozjs78 fixes to two repos instead of just updating one


Adding polkit and gjs and libproxy package maintainers to CC for discussion. I'd be happy to do the bundling work here though.

Comment 1 František Zatloukal 2021-05-07 08:50:33 UTC
I'll add just my two cents to one of the cons: 

- gjs and polkit build times get a lot slower and it's harder to iterate fixes there

If this change was to happen, I think it'd be best to have some sort switch in gjs/polkit to either use bundled mozjs or system mozjs. For some iterating over fixes that aren't affected by mozjs, one could switch mozjs to the system package (conditional BR and pulled from EPEL in such cases). That could reduce build times in some cases when a gjs/polkit issue/fix is unrelated to mozjs. It'd also allow to share polkit/gjs specfiles between Fedora and RHEL.

Comment 2 Kalev Lember 2021-05-07 09:19:40 UTC
Ah, good idea! Thanks, František.

Comment 3 Jan Rybar 2021-05-07 12:51:33 UTC
Hi Kalev,

being independent on the package in RHEL9 sounds interesting, especially after the trouble caused by rebase of Gnome Shell in RHEL7, however, do you have a specific plan in terms of maintaining the bundled library within the consumer packages? Aiming at the CVEs and other security issues...

Comment 4 Kalev Lember 2021-05-07 13:16:39 UTC
Hi Jan,

I'm happy to help keep it up to date (as long as upstream is releasing new versions) and in sync with the copy that's bundled in gjs, basically just do the same minimum maintenance that it's getting now as a separate package.

I can't promise any CVE fixes after Firefox ESR 78 is EOL though, but it's the same issue when it's separate package. We just don't have resources to keep maintaining old, EOL mozjs versions. This whole bundling thing is to make it easier to get rid of the old versions in the future.

I think a good plan is to just keep polkit and gjs up to date with latest upstream releases. I'm sure both of them are going to eventually get ported to newer mozjs versions upstream and when that happens, I'm happy to help get new versions of bundled mozjs building and up to date, basically just copy what we do for gjs.

(Also, security issues in polkit's JS engine shouldn't be exploitable as polkitd only runs code that only admins can install to /usr/share/polkit-1/rules.d/, which makes the attack surface very small even if there's a flaw in the JS engine.)

Comment 5 Matthias Clasen 2021-05-07 13:24:44 UTC
Some random musings from the sidelines:

- Could polkit be ported to use gjs, instead of using mozjs directly?
- Alternatively, would smaller embedded js engines like ducttape be easier for this?

Either of these will certainly require some more resources in the short term, but would make the 'mozjs problem' disappear for polkit

Comment 6 Michael Catanzaro 2021-05-07 16:10:16 UTC
I think this is a good long-term plan for gjs. Remember to add to the spec: Provides: bundled(mozjs) = 78.10.0.

For polkit, bundling mozjs seems OK as a short-term measure, but mozjs is really a terrible choice of JS engine due to lack of API and ABI stability. With gjs, this maintenance cost is primarily suffered and handled by upstream. But that doesn't seem to be going as well for polkit. Also, polkit's dependency on mozjs is much easier to eliminate than it would be for gjs.

(In reply to Matthias Clasen from comment #5)
> - Could polkit be ported to use gjs, instead of using mozjs directly?
> - Alternatively, would smaller embedded js engines like ducttape be easier
> for this?

duktape would seem to be much better. I imagine it probably has far fewer CVEs than mozjs. There is already a MR for this: https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/35. With duktape, we have to choose between bundling it vs. maintaining it as a system library. I guess we could do the former for RHEL and the later for Fedora. duktape seems to provide API but not ABI stability, which is fine for Fedora, but not good enough for RHEL. Also, it seems Fedora's system duktape is unmaintained and a couple years outdated, which is a negative. Finally, we probably don't want to maintain duktape in RHEL any more than we want to maintain mozjs, even though duktape would be easier.

mozjs is just the worst option possible. Even depending on JavaScriptCore (from WebKitGTK) would be better than that. (JavaScriptCore has a stable API/ABI, so keeping up with security updates is easy, and I handle it already.) duktape is probably best though. We just need to remember Provides: bundled(duktape) if we bundle it.

(In reply to František Zatloukal from comment #1)
> If this change was to happen, I think it'd be best to have some sort switch
> in gjs/polkit to either use bundled mozjs or system mozjs.

Well we have to do that anyway, because we want to share the spec with Fedora (so this change isn't lost for RHEL 10), but we don't want to bundle mozjs in Fedora.

(In reply to Kalev Lember from comment #0)
> It used to be that we needed to have mozjs as a shared library because gjs
> and libproxy both used mozjs symbols that ended up in the same process
> namespace. This meant that both had to be linked against the exact same
> libmozjs to avoid symbol clashes and weird crashes. However, libproxy is
> going away in RHEL 9 (and its mozjs backend is gone in Fedora) so this
> problem is no more.

One caveat: this plan is conditional on changing glib-pacrunner to do web proxy autodiscovery on its own, without libproxy. I'm planning to work on that, but it requires that I make glib-networking depend directly on a JS engine. I had been planning to use JavaScriptCore and split glib-pacrunner out into a subpackage to avoid a hard dependency, but I suppose duktape would work too, if the Fedora duktape package was in better shape. P.S. glib-pacrunner is already designed with a process boundary, so no extra effort is required to ensure the JS engine is used out-of-process and won't cause crashes for linked applications.

Comment 7 Jan Rybar 2021-05-10 09:44:00 UTC
(In reply to Matthias Clasen from comment #5)
> Some random musings from the sidelines:
> 
> - Could polkit be ported to use gjs, instead of using mozjs directly?
> - Alternatively, would smaller embedded js engines like ducttape be easier
> for this?
> 
> Either of these will certainly require some more resources in the short
> term, but would make the 'mozjs problem' disappear for polkit

Polkit is also used on gnome-free DEs like KDE and Xfce. I don't use them so I don't know if having to install gjs wouldn't bring the entire gnome dependency list. I'd rather bundle the lib if I had to than this.

The work on transition from mozjs to duktape is stalled as the merge request mentioned in comment#6 doesn't meet requirements in terms of safety and code culture. The MR doesn't contain any implementation of runaway_killer and that would make polkit prone to infinite loops.

Comment 9 Kalev Lember 2021-06-02 09:30:07 UTC
OK, I went ahead and merged the gjs changes to switch to bundled mozjs78 (gjs-1.68.1-2.el9, https://gitlab.com/redhat/centos-stream/rpms/gjs/-/commit/dfa7946b87c564737147ec7aebd8b7e7b1ba0c0b). I'll work on polkit next.

Comment 13 Petr Schindler 2021-06-17 19:05:03 UTC
All tests from our test suite pass. No regression found.

Comment 14 Kalev Lember 2021-07-01 18:35:32 UTC
OK, and here's the matching change for polkit to bundle mozjs: https://gitlab.com/redhat/centos-stream/rpms/polkit/-/merge_requests/2

Jan, are you OK with me merging this?

Comment 15 Jan Rybar 2021-07-02 18:01:53 UTC
(In reply to Kalev Lember from comment #14)
> OK, and here's the matching change for polkit to bundle mozjs:
> https://gitlab.com/redhat/centos-stream/rpms/polkit/-/merge_requests/2
> 
> Jan, are you OK with me merging this?

Hello Kalev,

compiles, installs, works. I see no trouble.

Comment 16 Kalev Lember 2021-07-07 10:00:24 UTC
Thanks, Jan! I went ahead and merged it and kicked off the build: polkit-0.117-6.el9

tpopela, I think you should be able to start the mozjs78 package removal process now if you want.

Comment 17 Tomas Popela 2021-07-12 05:41:31 UTC
(In reply to Kalev Lember from comment #16)
> tpopela, I think you should be able to start the mozjs78 package removal
> process now if you want.

Thank you Kalev! I will remove it this week.