Closed Bug 1608558 Opened 5 years ago Closed 5 years ago

Add linux sandboxing to socket process

Categories

(Core :: Networking, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla76
Tracking Status
firefox76 --- fixed

People

(Reporter: mjf, Assigned: mjf)

References

(Blocks 1 open bug, Regressed 1 open bug)

Details

(Whiteboard: [necko-triaged])

Attachments

(4 files)

The socket process currently has no sandboxing. We can start with Linux first.

Assignee: nobody → mfroman
Priority: -- → P2

My plan is to take most of what works for RDD and then see where I need help from the sandboxing team.

Whiteboard: [necko-triaged]

Just an info: at some point we will move all network operation to the socket process (we will try to do so if we do not have a lot performance penalty). I am writing the note here, so that sandbox team is aware (if not already aware) of it.

Jed, I've added most of the linux sandboxing code for the socket process that follows what you did for the linux sandbox on RDD. I still have some mochitest failures and I'm not sure what to change in the sandbox to fix them. Would have time to help troubleshoot? I've submitted a new try run with the patch that I submitted to phabricator:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=4aa1638979e838e8dd3c1466f2c2e89bb64305c0

Here is a slightly older run that is already complete, but should be identical code (just in multiple patches while I experimented with it):
https://treeherder.mozilla.org/#/jobs?repo=try&revision=2bead52329815626db8eefe6cb3411533060cace&selectedJob=283865740

Flags: needinfo?(jld)
Blocks: 1611527

Here is a concrete failure:
./mach mochitest --keep-open=false --headless dom/media/tests/mochitest/identity/test_peerConnection_asymmetricIsolation.html

This test hangs waiting for network activity when the socket process crashes here[1]. After adding some local instrumentation, we're failing inside of PORT_LoadLibraryFromOrigin[2]. The full path (for me) is /home/mfroman/mozilla/obj/deb/dist/bin/libnss3.so, and newShLibName is libsoftokn3.so.

[1] https://searchfox.org/mozilla-central/source/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp#359
[2] https://searchfox.org/mozilla-central/source/security/nss/lib/util/secload.c#131

More info: after temporarily adding read access to the firefox binary directory like here[1], I hit this:

 1:01.91 GECKO(21318) Sandbox: seccomp sandbox violation: pid 21345, tid 21345, syscall 102, args 140590155486248 140590155490087 0 87 0 0.  Killing process.

[1] https://searchfox.org/mozilla-central/source/security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp#400-413

Syscall 102 is getuid. Looks like you'll have to whitelist that call.

https://filippo.io/linux-syscall-table/

With the current patch sets, I'm getting this failure:

 1:01.97 GECKO(8574) (generic/CRIT) PR_Connect failed: -5980

I've a tried a few things, but nothing has changed that failure. Any thoughts?

Flags: needinfo?(gpascutto)

PR_Connect failed: -5980

nsprpub/pr/include/prerr.h
76:#define PR_NETWORK_UNREACHABLE_ERROR (-5980L)

So what could cause the network to be unreachable from within the socket process? The best guess would be that you mistakenly created a new network namespace for the socket process. Some digging through the patch confirms that, I'll point out the mistake in Phabricator.

Flags: needinfo?(jld)
Flags: needinfo?(gpascutto)
Attachment #9121049 - Attachment description: Bug 1608558 - add linux sandboxing to socket process. → Bug 1608558 - pt1 - add linux sandboxing to socket process.
Attachment #9125841 - Attachment description: Bug 1608558 - past crash loading libsoftokn3.so - now seccomp for syscall 102 → Bug 1608558 - pt2 - add SandboxBrokerPolicyFactory::GetSocketProcessPolicy to allow access to certs.
Attachment #9125842 - Attachment description: Bug 1608558 - past seccomp 102 - now fails on PR_Connect → Bug 1608558 - pt3 - add EvaluateSocketCall and missing cases to EvaluateSyscall for Socket process sandbox.

:jld, :gcp,
Who's correct person to review?

Flags: needinfo?(jld)
Flags: needinfo?(gpascutto)

I did a quick first pass, jld will have to do the final review.

What do you think about making the socket process sandbox correspond to level 5? This would allow a quick fallback to 4 if we find problems in the field.

Flags: needinfo?(jld)
Flags: needinfo?(gpascutto)

What do you think about making the socket process sandbox correspond to level 5? This would allow a quick fallback to 4 if we find problems in the field.

jld reminded me the pref we have is for content only. Other sandboxes have to rely on ENV vars. (Maybe they should have prefs too, especially if we think some breakage is possible?)

(In reply to Gian-Carlo Pascutto [:gcp] from comment #15)

What do you think about making the socket process sandbox correspond to level 5? This would allow a quick fallback to 4 if we find problems in the field.

jld reminded me the pref we have is for content only. Other sandboxes have to rely on ENV vars. (Maybe they should have prefs too, especially if we think some breakage is possible?)

Would a simple 'enabled' pref work for this case? That would be fairly easy to add.

Flags: needinfo?(gpascutto)

I'd add a "level" one similar to the one for content. If we want to make this sandbox useful we'll have to follow up on this to try to filter the allowed socket types etc, and that's the kind of thing that would be useful to dial back. A level wouldn't be much more complicated than a boolean toggle, I think.

Flags: needinfo?(gpascutto)

:gcp, I added a new patch that adds and uses a level pref.

Flags: needinfo?(gpascutto)
Attachment #9121049 - Attachment description: Bug 1608558 - pt1 - add linux sandboxing to socket process. → Bug 1608558 - pt1 - add linux sandboxing to socket process. r?jld!
Attachment #9125841 - Attachment description: Bug 1608558 - pt2 - add SandboxBrokerPolicyFactory::GetSocketProcessPolicy to allow access to certs. → Bug 1608558 - pt2 - add SandboxBrokerPolicyFactory::GetSocketProcessPolicy to allow access to certs. r?jld!
Attachment #9125842 - Attachment description: Bug 1608558 - pt3 - add EvaluateSocketCall and missing cases to EvaluateSyscall for Socket process sandbox. → Bug 1608558 - pt3 - add EvaluateSocketCall and missing cases to EvaluateSyscall for Socket process sandbox. r?jld!
Attachment #9128232 - Attachment description: Bug 1608558 - pt4 - use security.sandbox.socket.process.level for linux socket process sandbox. → Bug 1608558 - pt4 - use security.sandbox.socket.process.level for linux socket process sandbox. r?jld!

I added a new patch that adds and uses a level pref.

Looks good. As I commented, I'd set the base level to 1, not 4, and then file a follow-up bug where we try to restrict the allowed connection types and options (which would then increase the level to 2, etc).

Flags: needinfo?(gpascutto)

(In reply to Gian-Carlo Pascutto [:gcp] from comment #20)

I added a new patch that adds and uses a level pref.

Looks good. As I commented, I'd set the base level to 1, not 4, and then file a follow-up bug where we try to restrict the allowed connection types and options (which would then increase the level to 2, etc).

Sorry, I misunderstood you in Comment 14. I'll thought we were starting at 4 or 5 and going higher. I'll fix.

:gcp I think I've addressed your concerns in pt4. Also, are you satisfied w/ :jld's explanation on pt2, or do you still want me to look into specifically allowing only libsoftokn3.so and its dependencies? If so, can you point me to an example where that type of thing is done?

Flags: needinfo?(gpascutto)
See Also: → 1455498
Flags: needinfo?(gpascutto)
Pushed by mfroman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/10e01cf10faf pt1 - add linux sandboxing to socket process. r=gcp https://hg.mozilla.org/integration/autoland/rev/adc30f2f9a5c pt2 - add SandboxBrokerPolicyFactory::GetSocketProcessPolicy to allow access to certs. r=jld,gcp https://hg.mozilla.org/integration/autoland/rev/678c6a3d00ee pt3 - add EvaluateSocketCall and missing cases to EvaluateSyscall for Socket process sandbox. r=gcp https://hg.mozilla.org/integration/autoland/rev/43e7de62af7f pt4 - use security.sandbox.socket.process.level for linux socket process sandbox. r=gcp
Regressions: 1626385
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: