Native messaging clients on non-Windows platforms sometimes inherit file descriptors for network connections
Categories
(Toolkit :: Async Tooling, defect, P2)
Tracking
()
People
(Reporter: sami.vanttinen, Unassigned)
References
Details
| Reporter | ||
Updated•7 years ago
|
| Reporter | ||
Comment 1•7 years ago
|
||
Updated•7 years ago
|
Updated•7 years ago
|
Updated•7 years ago
|
Comment 3•7 years ago
|
||
Comment 5•7 years ago
|
||
Comment 6•5 years ago
|
||
Every time I do an lsof -i on my laptop, I always see some unexpected Python process with socket connections to random Internet addresses and I start freaking out before I remember that this bug is still a thing.
I first found out about this bug when I discovered that deleting large files downloaded by Firefox doesn't always free up the space they were using because a native messaging subprocess could still be holding handles to them. So I occasionally have to go and disable/enable a random extension if I'm running out of disk space.
Neither of these are exactly showstopper issues, but they're quite annoying relative to the (possibly) simple fix proposed in comment #5. Is there a reason not to use O_CLOEXEC?
Just wondering if this issue is ever going to be addressed? It was reported over 3 years ago, yet still seems to be causing many connections to random places via keepassxc-proxy.
Is there a reason why O_CLOEXEC isn't used during the open() of sockets? Using that flag avoids the race condition problems of setting FD_CLOEXEC.
Would you know more about that, Dragana?
Comment 9•5 years ago
|
||
(In reply to David Teller [:Yoric] (please use "needinfo") from comment #8)
Is there a reason why O_CLOEXEC isn't used during the open() of sockets? Using that flag avoids the race condition problems of setting FD_CLOEXEC.
Would you know more about that, Dragana?
I do no know why it is not used. Do you wan to open a separate bug to investigate this?
Comment 10•5 years ago
|
||
Sockets aren't opened; we'll need SOCK_CLOEXEC, which is planned for the next version of POSIX. Linux has it (see also bug 1363378), but macOS doesn't appear to support it as of 10.13. (However, macOS has the POSIX_SPAWN_CLOEXEC_DEFAULT flag.)
Comment 11•4 years ago
|
||
It seems that this problems is causing considerable paranoia - in this case wrt keepassxc, an external password manager for firefox appearing to making and/or having connections to "random" IPs: https://github.com/keepassxreboot/keepassxc-browser/issues/100, which would be catastrophic.
So it would be very, very welcome, if FF would not inherit random TCP connections to children.
I am not informed enough to know whether the children inherit open connections or only CLOSE_WAIT connections, which I am currently seeing with FF 78 ESR. If it would be the former, then that would be a security issue, although I am not informed either on how the security model for extensions looks like, how far they are intended to be isolated from whatever parts of the browser - the principle of letting every part and component, tab, JS executor, extension etc. have access to every other components context makes me cringe hard - that should not be. In this case, extensions should absolutely not inherit random TCP sockets.
It'd be very nice if this ticket could get resolved and inheriting random TCP sockets to extensions could be eliminated.
Comment 13•3 years ago
•
|
||
If it would be the former, then that would be a security issue, although I am not informed either on how the security model for extensions looks like, how far they are intended to be isolated from whatever parts of the browser
Native messaging extensions contain a native code part that runs with the same permissions as the main process of the browser itself. It's hence not clear what the security issue would be, given that you're already starting from such a privileged state, i.e. you already have the same powers as Firefox itself.
Similarly:
IMHO this can be exploited by a malicious extension, at least to collect meta information about the network connections opened by Firefox.
If you have installed and are running native code (required for WebExtensions' native messaging) and it is malicious, then it doesn't need this inheritance behavior to snoop on Firefox's network connections. It can just replace the real Firefox binary by a fake one that sends all the data to the attacker directly.
So although this is a bit ugly, I don't see any indications there's a real security issue here. The starting point for any exploit of this behavior ("I installed native code that is malicious") already amounts to a full system compromise, at which point any browser security feature is meaningless.
I first found out about this bug when I discovered that deleting large files downloaded by Firefox doesn't always free up the space they were using because a native messaging subprocess could still be holding handles to them.
Downloads aren't sockets, so this should be easier to address. It may be worth filing this separately.
Comment 14•3 years ago
|
||
(In reply to Jed Davis [:jld] ⟨⏰|UTC-6⟩ ⟦he/him⟧ from comment #10)
Sockets aren't
opened; we'll needSOCK_CLOEXEC, which is [planned for the next version of POSIX][ag411]. Linux has it (see also bug 1363378), but macOS doesn't appear to support it as of 10.13.
It might be a good idea to use it where it's supported. In the mean time, fcntl with FD_CLOEXEC, but there is of course a race with that method.
There is also, these days, a necko process, and sockets opened in that process will not be inherited.
(However, macOS has [the
POSIX_SPAWN_CLOEXEC_DEFAULTflag][cld].)
We should probably add that to subprocess_unix when we're on macos...
Comment 15•3 years ago
•
|
||
but there is of course a race with that method.
If we don't see a real security issue with the current behavior, then the small probability of the race is probably not something we actually care about? It would likely be enough to stop people from yelling at extension authors.
Comment 16•3 years ago
|
||
(In reply to Gian-Carlo Pascutto [:gcp] from comment #15)
but there is of course a race with that method.
If we don't see a real security issue with the current behavior, then the small probability of the race is probably not something we actually care about? It would likely be enough to stop people from yelling at extension authors.
No, I think it should be fine. And it would at least reduce the occurrence of resource leaks. But if we can use SOCK_CLOEXEC on Linux and POSIX_SPAWN_CLOEXEC_DEFAULT on macOS, we should be pretty much covered everywhere anyway.
Comment 17•3 years ago
|
||
(In reply to Kris Maglione [:kmag] from comment #16)
No, I think it should be fine. And it would at least reduce the occurrence of resource leaks. But if we can use
SOCK_CLOEXECon Linux andPOSIX_SPAWN_CLOEXEC_DEFAULTon macOS, we should be pretty much covered everywhere anyway.
SOCK_CLOEXEC in Necko (and IPC; we use EOF on the channel to detect that the other process died, so leaks should be avoided), MSG_CMSG_CLOEXEC for fd-passing in IPC, O_CLOEXEC with downloads and whatever is opening all of these .xpi/omni.ja files that I can see being leaked, and there are some pipes whose creators will need to be hunted down to use pipe2. (I think the Necko change would have to be in NSPR if we want to use SOCK_CLOEXEC instead of just setting the flag non-atomically, so we'd need to get an NSPR release rolled out and bump Gecko's required version.) I'm also seeing a netlink socket and a DRI device. There are a lot of problems here.
Alternately, IPC LaunchApp needs two minor features (chdir and not inheriting the environment; also disclaim on Mac but that looks relatively simple) and then it can be exposed to JS and used to replace the posix_spawn backend of Subprocess. (As an added bonus, we can stop changing the entire parent process's cwd.) I threw together a proof-of-concept today and it seems to work and pass the existing Subprocess unit tests on Linux, so I'll probably end up assigning myself bug 1276388.
It's probably also worth fixing the missing cloexec bits where we can, because there are going to be libraries using system/popen/etc.
Comment 18•3 years ago
|
||
(In reply to Jed Davis [:jld] ⟨⏰|UTC-6⟩ ⟦he/him⟧ from comment #17)
SOCK_CLOEXECin Necko (and IPC; we use EOF on the channel to detect that the other process died, so leaks should be avoided),MSG_CMSG_CLOEXECfor fd-passing in IPC,O_CLOEXECwith downloads and whatever is opening all of these.xpi/omni.jafiles that I can see being leaked, and there are some pipes whose creators will need to be hunted down to usepipe2. (I think the Necko change would have to be in NSPR if we want to useSOCK_CLOEXECinstead of just setting the flag non-atomically, so we'd need to get an NSPR release rolled out and bump Gecko's required version.) I'm also seeing a netlink socket and a DRI device. There are a lot of problems here.
Fair enough. I think the necko ones are the ones I'm most worried about, since most of them are ephemeral, and we open a lot of them, so they have more potential to leak system resources. The XPI/jar file descriptors at least generally stay open for the lifetime of the browser process.
Alternately, IPC
LaunchAppneeds two minor features (chdirand not inheriting the environment; alsodisclaimon Mac but that looks relatively simple) and then it can be [exposed to JS][ioutils] and used to replace theposix_spawnbackend ofSubprocess.
That would be ideal. r=me if you write the patch.
(As an added bonus, we can stop [changing the entire parent process's cwd][cwd-oops].)
Yes, I was never happy about that.
Updated•3 years ago
|
Description
•