Nylas not starting with hardened kernel
I have been using N1 on my linux machine for about 6 weeks now. I have recently introduced hardened kernel and found out that there is anonymous mapping issue in N1. Found it with grsecurity patches. dmesg will have a message like the following:
[ 403.207974] grsec: denied RWX mmap of <anonymous mapping> by /usr/share/nylas/nylas[nylas:1772] uid/euid:1000/1000 gid/egid:100/100, parent /usr/lib/systemd/systemd[systemd:1] uid/euid:0/0 gid/egid:0/0
N1 won't start when this is happening. For me, this is a showstopper bug.
For reference, this means that there's a memory mapping created that has read-write-execute on it. Should be read-execute or read-write.
As a temporary fix for this, run sudo setfattr -n user.pax.flags -v "m" /usr/share/nylas/nylas . N1 will resume working but it would be nice to figure out the root cause as this potentially can result in anonymous command execution and privilege escalation.
Revert temporary fix: sudo setfattr -x user.pax.flags /usr/share/nylas/nylas
Thanks for the report @bashok001 and security is very important. What are the PaX settings for Chrome's binary? N1 doesn't run the Chrome sandbox, which should make a PaX profile easier to write. V8 still needs access to RWX memory pages so it can write the JIT'ed code to them.
Hey folks - this likely impacts all apps built on Electron. Could you try downloading the Atom text editor and see if it works with the hardened kernel enabled? We should probably file a ticket against Electron.
@bengotow Usually this is an distribution thing to create the hardening profiles. There are many hardening technologies in the Linux world, including SELinux, AppArmor, and PaX.
@mbilker Chrome has no pax exception flag settings. It is working fine.
user.pax.flags: No such attribute
If this is not what you're looking for, please elucidate.
@bengotow Installed atom. Atom is working fine to open and save files. Except when I interact with apm.
[ 6100.165862] grsec: denied RWX mmap of <anonymous mapping> by /usr/share/atom-editor/src/atom-1.3.3/apm/node_modules/atom-package-manager/bin/node[node:10225] uid/euid:1000/1000 gid/egid:100/100, parent /usr/share/atom-editor/src/atom-1.3.3/apm/node_modules/atom-package-manager/bin/apm[apm:10219] uid/euid:1000/1000 gid/egid:100/100
Could you give me the PaX attributes for chrome and chrome-sandbox. The sandbox should have the flags on it.
From the paxd program, Chrome by default has memory protections from https://github.com/thestinger/paxd/blob/master/paxd.conf#L462-L463.
EDIT: MPROTECT for Chrome is disabled. Also, running the grsec variant kernel for Arch Linux causes Core 0 of my laptop to stay pegged at 100%. I don't know why.
Got it. Here you go.
- PaX flags: P----m-x-eR- [/opt/google/chrome/chrome]
- PaX flags: -p---m-x-e-- [/opt/google/chrome/nacl_helper]
- PaX flags: -----m-x-e-- [/opt/google/chrome/chrome-sandbox]
@bashok001 Notice the settings on them. The settings for /opt/google/chrome/chrome apply to the main Nylas binary (/usr/share/nylas/nylas or whereever it is installed).
This is unavoidable because of V8, as I stated earlier, needs to write compiled code to memory and the ability to execute that code in memory. An interpreter defeats the purpose of V8's fast native code.
Okay. True. If so, chrome already has m turned on. So, no memory protections (NOMPROTECT) are enforced. So, if the same settings are used by nylas, wouldn't it already have m enabled for it? As I noted it in the initial report, all I had to do was turn on m by setting user defined pax flags and nylas runs golden.
Since Chrome is used a lot, It may have gotten a definition for paxd. What distribution are you using? Check /etc/paxd.conf to see if there is a definition in there.
/etc/paxd.conf has chrome with m on but chromium with no m flag. Will that be of significance?
That is odd. Does Chromium start without the m flag?
What distribution are you on so I can check what they package into /etc/paxd.conf?
Surprisingly, there are no issues with PaX or Grsecurity posted on atom/electron's or atom/atom's issue pages. I thought there would be more users of Grsecurity out there.
Sorry. My bad. Chromium also has m. I misread conf. So, my question still stays on how turning m on by user defined flags on nylas makes it work. I am on Arch Linux with 4.3.3.201601051958-1-grsec kernel.
For me atom editor is working fine, but apm is not working.
That is really strange. The Atom editor does not have m in its PaX flags? I find that strange considering it uses apm internally and uses the same Electron backend as Nylas.
Though, while writing the above statement, I wonder if this is related to SQLite in Nylas N1 and other native extensions. Atom does not have as many native extensions used.
I am going to research SQLite and Grsecurity.
Surprisingly, that Grsecurity kernel does not like my MacBook. It kept the laptop's Core 0 pegged at 100%. I switched back to vanilla. I am happy to find many Arch Linux users of N1.
Thank you for looking into this. I do understand now the need to turn on m flag for nylas. But I am not sure why these flags are not imported from chrome or chromium settings.
I am trying to run Grsecurity on my desktop. I hate having to do the e flag on every graphics binary because of Nvidia stuff! Up to 10 binaries.
Now I can get into my X session. This is good. Now to test Chrome and Nylas.