Closed Bug 1680771 Opened 5 years ago Closed 5 years ago

Ensure WebRTC connections are partitioned

Categories

(Core :: WebRTC, defect, P2)

defect

Tracking

()

RESOLVED FIXED
86 Branch
Tracking Status
firefox86 --- fixed

People

(Reporter: annevk, Assigned: bwc)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 obsolete file)

From discussion with Byron and Jan-Ivar it appears name lookups and connections might not always be suitably partitioned using a principal.

Byron was willing to provide a couple pointers to the relevant code and I was hoping Tim (or colleague) would be willing to take a look as to how it might have to be adjusted to take advantage of network partitioning.

Flags: needinfo?(docfaraday)

Here's the code that we use to open TCP sockets:

https://searchfox.org/mozilla-central/rev/6bb59b783b193f06d6744c5ccaac69a992e9ee7b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp#148

We use a System principal for the proxy info lookup here:

https://searchfox.org/mozilla-central/rev/6bb59b783b193f06d6744c5ccaac69a992e9ee7b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp#207

We use the loading principal for the channel (in the web proxy case) here:

https://searchfox.org/mozilla-central/rev/6bb59b783b193f06d6744c5ccaac69a992e9ee7b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp#387-388

We do not seem to be using any principal when opening a TCP stream in the non-proxy case; this code just uses nsISocketTransport. I am not sure how one would tell this interface about principal stuff, but maybe SetOriginAttributes would be the thing to use?

https://searchfox.org/mozilla-central/rev/6bb59b783b193f06d6744c5ccaac69a992e9ee7b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp#332-355

I should note that I am working on delegating all DNS lookups for TCP to WebrtcTCPSocket (and therefore Necko) over in bug 1416220. I should also note that our mochitests exercise the localhost case on linux and OS X. Right now the patches for bug 1416220 are not working on the linux testers for some reason, although these tests do work on my own linux box. Not sure what is up with that, I may be tripping over some of the localhost-related policy.

Flags: needinfo?(docfaraday)
See Also: → 1416220

Thanks Byron! I hope that Tim has time to take a look. We should probably also look at the UDP connections?

Flags: needinfo?(tihuang)

Right now, the DNS resolution for both UDP and TCP is handled here:

https://searchfox.org/mozilla-central/rev/6bb59b783b193f06d6744c5ccaac69a992e9ee7b/dom/media/webrtc/transport/nriceresolver.cpp#174-177

Bug 1416220 will stop using this for TCP, but UDP will continue to use it.

The UDP socket code does different things depending on how processes are set up:

https://searchfox.org/mozilla-central/rev/6bb59b783b193f06d6744c5ccaac69a992e9ee7b/dom/media/webrtc/transport/nr_socket_prsock.cpp#1650-1665

For the socket process and parent process case, we use a plain NrSocket for UDP. Note that this is very low level API, and will certainly not be able to handle DNS on its own:

https://searchfox.org/mozilla-central/rev/6bb59b783b193f06d6744c5ccaac69a992e9ee7b/dom/media/webrtc/transport/nr_socket_prsock.cpp#576

For the content process case, we use NrUdpSocketIpc, which in turn relies on UDPSocketChild, which may be able to handle DNS on its own:

https://searchfox.org/mozilla-central/rev/6bb59b783b193f06d6744c5ccaac69a992e9ee7b/dom/media/webrtc/transport/nr_socket_prsock.cpp#1473

In order to delegate DNS lookups to Necko for our UDP sockets, we would want to unify these two cases, probably relying on UDPSocketChild for both (unless on the parent process, but it is unclear if we even want to continue supporting that).

From the code, it looks that we can partition the WebRTC connections. Right now, the partition key is from the cookieJarSettings. So, we can have the connection partitioned if we can get the cookieJarSettings from the content.

For TCP connections, I think we can get the cookieJarSettings from the loadInfo passed by the mProxyConfig. And set it to the channel here.

For UDP connections, we can set the originAttributes to the nsISocketTransport directly. But I am not sure if we can get the loadInfo from the content in this case.

I need more time to check the DNS resolution.

Byron, I have two questions here. Does the loadInfo in the mProxyConfig came from the content document? Does WebRTC have another way to pass information from the content document other than mProxyConfig? Thanks.

Flags: needinfo?(tihuang) → needinfo?(docfaraday)

(In reply to Tim Huang[:timhuang] from comment #4)

From the code, it looks that we can partition the WebRTC connections. Right now, the partition key is from the cookieJarSettings. So, we can have the connection partitioned if we can get the cookieJarSettings from the content.

For TCP connections, I think we can get the cookieJarSettings from the loadInfo passed by the mProxyConfig. And set it to the channel here.

For UDP connections, we can set the originAttributes to the nsISocketTransport directly. But I am not sure if we can get the loadInfo from the content in this case.

I need more time to check the DNS resolution.

Byron, I have two questions here. Does the loadInfo in the mProxyConfig came from the content document? Does WebRTC have another way to pass information from the content document other than mProxyConfig? Thanks.

Hmm, it seems not: https://searchfox.org/mozilla-central/rev/1843375acbbca68127713e402be222350ac99301/dom/media/webrtc/jsapi/PeerConnectionMedia.cpp#874

I think it would be possible to fix this, though. mProxyConfig is the only way we would pass this kind of information, although it has to go through the MediaTransportHandler ipdl as an NrSocketProxyConfig first.

Flags: needinfo?(docfaraday)

So would it be appropriate to use this LoadInfo c'tor with the Document's LoadPrincipal? Or is there some other way we should be doing this?

https://searchfox.org/mozilla-central/rev/1843375acbbca68127713e402be222350ac99301/netwerk/base/LoadInfo.h#84

I seem to recall having some difficulty using the "real" principal here back when I wrote this code, but let me try.

Flags: needinfo?(tihuang)

Ok, the patch in comment 7 seems to work ok. In order to set the cookie jar stuff, I guess NewChannelFromURIWithProxyFlags would have to take another param, or maybe we could expose NewChannelFromURIWithProxyFlagsInternal since that takes a LoadInfo, which is what we already have.

(In reply to Byron Campen [:bwc] from comment #6)

So would it be appropriate to use this LoadInfo c'tor with the Document's LoadPrincipal? Or is there some other way we should be doing this?

https://searchfox.org/mozilla-central/rev/1843375acbbca68127713e402be222350ac99301/netwerk/base/LoadInfo.h#84

Yes, I think this is correct. And the CookieJarSettings will be inherited from the document here.

(In reply to Byron Campen [:bwc] from comment #8)

Ok, the patch in comment 7 seems to work ok. In order to set the cookie jar stuff, I guess NewChannelFromURIWithProxyFlags would have to take another param, or maybe we could expose NewChannelFromURIWithProxyFlagsInternal since that takes a LoadInfo, which is what we already have.

I think you can set the cookieJarSettings to the loadInfo of the channel before opening it. So, we don't need the NewChannelFromURIWithProxyFlagsInternal.

Flags: needinfo?(tihuang)

(In reply to Tim Huang[:timhuang] from comment #9)

(In reply to Byron Campen [:bwc] from comment #6)

So would it be appropriate to use this LoadInfo c'tor with the Document's LoadPrincipal? Or is there some other way we should be doing this?

https://searchfox.org/mozilla-central/rev/1843375acbbca68127713e402be222350ac99301/netwerk/base/LoadInfo.h#84

Yes, I think this is correct. And the CookieJarSettings will be inherited from the document here.

(In reply to Byron Campen [:bwc] from comment #8)

Ok, the patch in comment 7 seems to work ok. In order to set the cookie jar stuff, I guess NewChannelFromURIWithProxyFlags would have to take another param, or maybe we could expose NewChannelFromURIWithProxyFlagsInternal since that takes a LoadInfo, which is what we already have.

I think you can set the cookieJarSettings to the loadInfo of the channel before opening it. So, we don't need the NewChannelFromURIWithProxyFlagsInternal.

So I guess we can stomp the LoadInfo with nsIChannel::SetLoadInfo? I'll need to double check that we don't lose any of the flags by doing that.

Severity: -- → S3
Priority: -- → P2

(In reply to Byron Campen [:bwc] from comment #10)

So I guess we can stomp the LoadInfo with nsIChannel::SetLoadInfo? I'll need to double check that we don't lose any of the flags by doing that.

You don't need to set the whole loadInfo. The loadInfo will also be created when creating the channel. All you need to do is to set the CookieJarSettings to the loadInfo of the channel.

Assignee: nobody → docfaraday

Try looks good.

Strawman patch up for review. What else needs to be done here besides the work over in bug 1416220?

I have a question regarding the non-proxy connections.

In which case the non-proxy connections could be established? If it could be established due to the script in the content, then I think we should also find a way to partition it. If not, and the content script cannot observe non-proxy channels, then I think it's fine.

Byron, could you answer this for me? Thanks.

Flags: needinfo?(docfaraday)

(In reply to Tim Huang[:timhuang] from comment #16)

I have a question regarding the non-proxy connections.

In which case the non-proxy connections could be established? If it could be established due to the script in the content, then I think we should also find a way to partition it. If not, and the content script cannot observe non-proxy channels, then I think it's fine.

Byron, could you answer this for me? Thanks.

Non-proxy connections would be established by JS in the same way proxied ones are, the thing that makes the difference is whether an http proxy is configured. The code that opens the non-proxied TCP socket is here:

https://searchfox.org/mozilla-central/rev/6bb59b783b193f06d6744c5ccaac69a992e9ee7b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp#332-355

How would one go about partitioning this? Bear in mind that at this stage, DNS lookup will be finished already. This is just establishing a raw TCP socket over which media data will flow, so there's not going to be any cacheing or anything, so maybe there's nothing to partition?

Flags: needinfo?(docfaraday)

We have also partitioned the HTTP connection pool beside the HTTP cache. Could the non-proxy connections be reused? If so, I think we should also partition it.

So in the non-proxy case, there is no http connection at all. It is a raw TCP socket.

Ah, I didn't get your point in the first place. I think you are right that there is no point to partition a raw TCP socket.

Attachment #9193532 - Attachment is obsolete: true

There's a r+ patch which didn't land and no activity in this bug for 2 weeks.
:bwc, could you have a look please?
For more information, please visit auto_nag documentation.

Flags: needinfo?(docfaraday)
Status: NEW → ASSIGNED

Had to rebase, and re-test manually. Try looks good. Let's try landing again.

Flags: needinfo?(docfaraday)
Pushed by bcampen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1f4c8a19d48c Use a real LoadInfo for WebrtcTCPSocket, ensure we use that LoadInfo's CookieJarSettings for our DNS/proxy lookup, and remove a flag that was breaking http proxy support for webrtc. r=timhuang,mjf
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 86 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: