Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this might be a good opportunity to replace calls to avc_has_perm() with calls to selinux_access_check() in selinux.c #16

Closed
ghost opened this issue Aug 16, 2017 · 8 comments

Comments

@ghost
Copy link

ghost commented Aug 16, 2017

avc_has_perm() is a legacy compatibility interface provided with libselinux, and it should ideally be replaced with calls to selinux_access_check()

as more important components like systemd become more dependent on dbus it becomes more important that the selinux code is up-to-date.

i understand that you may not see it as your duty to address this issue, but i am taking the opportunity to inform you that selinux.c is calling legacy compatibility interfaces, just in case you feel up to the task.

this might be a good opportunity to revisit dbus calls to legacy and compatibility interfaces provided by libselinux

SELinuxProject/selinux#34

@dvdhrm
Copy link
Member

dvdhrm commented Aug 16, 2017

Thanks for the hint!

selinux_access_check() resolves the contexts on every call. avc_has_perm() allows us to cache the lookups by storing the sid pointers rather than the context-strings. Is this intentional?

@ghost
Copy link
Author

ghost commented Aug 16, 2017 via email

@bigon
Copy link
Contributor

bigon commented Aug 23, 2017

If you are caching the security contexts I guess you should at least invalidate the cache if the policy is reloaded, see selinux_set_callback(3) manpage (and SELINUX_CB_POLICYLOAD)

@teg
Copy link
Contributor

teg commented Aug 23, 2017

@bigon could you expand a bit on that? This is my understanding, please correct me if I'm wrong:

  1. The security context of a peer (which is the SO_SECLABEL of its socket) is pinned in the file description at open() and stays fixed regardless of any change to security policy.
  2. The SID returned by avc_context_to_sid() is valid for the lifetime of the daemon (we only call avc_destroy() when shutting down the daemon).
  3. We need to listen for SELINUX_CB_POLICYLOAD to reload the security contexts of names, and then obviously get a new SID if the context changes (we currently do not do this).

Are you saying that we also need to re-resolve all SIDs when the policy changes? Could we get a different SID back, even if the context is guaranteed to be the same?

@bigon
Copy link
Contributor

bigon commented Aug 24, 2017

@teg I'm far from being an expert here, but I think that security context can be invalidated (the label become unlabeled_t) when a module is disabled or a policy is updated. But the sid itself might still be valid.

For the original question from @doverride (avc_has_perm vs selinux_check_access) I guess this could be discussed on the SELinux from the NSA

@dvdhrm
Copy link
Member

dvdhrm commented Aug 24, 2017

Lets just switch to selinux_check_access(). Makes the code simpler, and we follow the upstream recommendation.

If this ends up slowing down the message bus considerably, we will need an upstream solution, anyway. Relying on deprecated interfaces sounds not right.

@teg
Copy link
Contributor

teg commented Aug 24, 2017

Yeah, I'm fine with that.

teg added a commit to teg/dbus-broker that referenced this issue Aug 25, 2017
The SID API is deprecated upstream, instead move to the
selinux_check_access() API which does the lookup from context to SID
internally. If this proves to have a significant overhead we should
work with upstream SELinux to come up with a non-deprecated solution.

Addresses issue bus1#16.

Signed-off-by: Tom Gundersen <teg@jklm.no>
teg added a commit to teg/dbus-broker that referenced this issue Aug 25, 2017
The SID API is deprecated upstream, instead move to the
selinux_check_access() API which does the lookup from context to SID
internally. If this proves to have a significant overhead we should
work with upstream SELinux to come up with a non-deprecated solution.

Addresses issue bus1#16.

Signed-off-by: Tom Gundersen <teg@jklm.no>
teg added a commit to teg/dbus-broker that referenced this issue Aug 28, 2017
The SID API is deprecated upstream, instead move to the
selinux_check_access() API which does the lookup from context to SID
internally. If this proves to have a significant overhead we should
work with upstream SELinux to come up with a non-deprecated solution.

Addresses issue bus1#16.

Signed-off-by: Tom Gundersen <teg@jklm.no>
teg added a commit to teg/dbus-broker that referenced this issue Aug 28, 2017
The SID API is deprecated upstream, instead move to the
selinux_check_access() API which does the lookup from context to SID
internally. If this proves to have a significant overhead we should
work with upstream SELinux to come up with a non-deprecated solution.

Addresses issue bus1#16.

Signed-off-by: Tom Gundersen <teg@jklm.no>
dvdhrm pushed a commit that referenced this issue Aug 28, 2017
The SID API is deprecated upstream, instead move to the
selinux_check_access() API which does the lookup from context to SID
internally. If this proves to have a significant overhead we should
work with upstream SELinux to come up with a non-deprecated solution.

Addresses issue #16.

Signed-off-by: Tom Gundersen <teg@jklm.no>
@dvdhrm
Copy link
Member

dvdhrm commented Aug 28, 2017

Fixed!

Thanks for the report!

@dvdhrm dvdhrm closed this as completed Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants