Accept file descriptor only from root owned process
AbandonedPublic

Authored by chinmoyr on Apr 17 2018, 5:15 PM.

Details

Reviewers
dfaure
ossi
Group Reviewers
Frameworks
Summary

Limiting file ioslave to recieve file descriptor only from root owned process helps to make sure
that no malicious process interfere while a privilege operation is in progress by sending garbage
data to the socket.

Diff Detail

Repository
R241 KIO
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
chinmoyr created this revision.Apr 17 2018, 5:15 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptApr 17 2018, 5:15 PM
chinmoyr requested review of this revision.Apr 17 2018, 5:15 PM
ossi added a subscriber: ossi.May 6 2018, 9:36 AM

as i certainly mentioned somewhere else already, this is redundant with putting the socket in a safe place. but fair enough ...

src/ioslaves/file/fdreceiver.cpp
74–95

i'd append "(our setuid helper)" to that - i wondered for a moment why the limitation.

chinmoyr updated this revision to Diff 33776.May 7 2018, 4:29 PM
chinmoyr marked an inline comment as done.

Updated the comment

chinmoyr updated this revision to Diff 34966.May 27 2018, 11:31 AM

I only realized now that after making the previous change I forgot to rebase.
So uploading correct patch.

Restricted Application added a subscriber: kde-frameworks-devel. · View Herald TranscriptMay 27 2018, 11:31 AM

@ossi would you mind reviewing this patch?

ossi accepted this revision.May 27 2018, 11:48 AM
This revision is now accepted and ready to land.May 27 2018, 11:48 AM
ossi added inline comments.May 27 2018, 11:50 AM
src/ioslaves/file/fdreceiver.cpp
89

i wonder whether that shouldn't come with an unconditional acceptConnection = true; then - now the compilation succeeds, but it will fail to operate. given that the whole feature is redundant with moving the socket to a safe place (something you really should mention in the commit message), this seems like a rather pointless limitation.

chinmoyr added inline comments.May 27 2018, 1:13 PM
src/ioslaves/file/fdreceiver.cpp
89

I don't think making acceptConnection unconditionally true is a good idea. At least it will make this patch look horrible.
Since getsocketopt conforms to posix, how about we check for __ unix __ , and posix compliance instead of __ linux __ and upon failure inform the user to install a posix compliant libc?

ossi added inline comments.May 27 2018, 10:31 PM
src/ioslaves/file/fdreceiver.cpp
89

i don't see why that would be horrible; as i pointed out multiple times already, this change is redundant. one correction, though: add a code comment here rather than extending the commit message.

getsockopt() is standard, but the actual options aren't. you could change the ifdef to SO_PEERCRED itself, but that wouldn't actually add any portability.

chinmoyr added inline comments.May 28 2018, 6:13 AM
src/ioslaves/file/fdreceiver.cpp
89

i don't see why that would be horrible

I meant adding "acceptConnection = true;" after #warning would look weird. Obviously that's not even an issue and I shouldn't have mentioned it.

There is a discussion[1] going on related to a similar change in ktexteditor. Because ktexteditor also uses polkit to save files in read-only location, one of the suggestions to improve this process, in case the owner of target is not root, was to either ignore the operation or drop privileges to owner/group of the directory. Now in KIO the kauth helper performs every operation as root. So if in future it is decided to do a privilege drop before performing any file operation on non-root targets then this change will likely be a hindrance. After considering the fact that this is also redundant, now I am not really feeling confident about this change. Just out of curiosity, I want to know (although I feel weird for asking this) what was your reason for accepting this patch?

[1]: https://bugzilla.suse.com/show_bug.cgi?id=1033055#c13

ossi added inline comments.May 28 2018, 8:00 AM
src/ioslaves/file/fdreceiver.cpp
89

i initially didn't notice the problem we're currently discussing.
but more generally: it's a second layer of security, just in case somebody accidentally f*cks up the perms of their runtime dir (not something to be particularly concerned about; you'd certainly have bigger problems in this case). it might also help detecting configuration problems (though for that you'd have to add reasonable error reporting). and if done right, it's (currently) harmless, and i didn't feel like arguing over it. but i myself would just drop it.

chinmoyr updated this revision to Diff 35010.May 28 2018, 8:15 AM

Accept socket connection where getsockopt() is not present

chinmoyr abandoned this revision.May 28 2018, 8:23 AM

As of now this change is not of any importance. If in future a situation arises where we need it I will reopen this revision.