Security context of shared libraries
Hi all,
I have an executable started by /bin/foo which runs confined within the context foo_t.
The process loads (actually does LD_PRELOAD) bar.so which needs to access resources outside foo_t (actually unconfined_t).
I can allow access to such resources from foo_t, but I would like to allow such access only for code running within bar.so, instead of the whole process.
I have been looking in the docs, but I could not find if it is possible to specify a source context for shared libraries, instead of whole processes. My idea would be to define a context bar_t for code running within bar.so, and allow the required access (to unconfined_t) from bar_t, without extending access for foo_t.
Makes sense? Is it possible?
Thanks in advance,
M. Manfredini
Quoted 11 lines · mm
Hi all,
I have an executable started by
/bin/foowhich runs confined within the contextfoo_t.
The process loads (actually doesLD_PRELOAD) bar.so which needs to access resources outsidefoo_t(actuallyunconfined_t).I can allow access to such resources from
foo_t, but I would like to allow such access only for code running within bar.so, instead of the whole process.
Quoted 9 lines
I have been looking in the docs, but I could not find if it is possible to specify a source context for shared libraries, instead of whole processes.
My idea would be to define a contextbar_tfor code running within bar.so, and allow the required access (tounconfined_t) frombar_t, without extending access forfoo_t.Makes sense? Is it possible?
Makes sense, but is not possible AFAIK (not transparently anyway)
Quoted 8 lines
Thanks in advance,
M. Manfredini
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 19 lines · Dominick Grift
Quoted 18 lines · mm
Hi all,
I have an executable started by
/bin/foowhich runs confined within the contextfoo_t.
The process loads (actually doesLD_PRELOAD) bar.so which needs to access resources outsidefoo_t(actuallyunconfined_t).I can allow access to such resources from
foo_t, but I would like to allow such access only for code running within bar.so, instead of the whole process.I have been looking in the docs, but I could not find if it is possible to specify a source context for shared libraries, instead of whole processes.
My idea would be to define a contextbar_tfor code running within bar.so, and allow the required access (tounconfined_t) frombar_t, without extending access forfoo_t.
Quoted 4 lines
Quoted 2 lines
Makes sense? Is it possible?
Makes sense, but is not possible AFAIK (not transparently anyway)
I mean it makes that you would want that.
Quoted 10 lines
Quoted 8 lines
Thanks in advance,
M. Manfredini
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8 02D5 3B6C 5F1D 2C7B 6B02 https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02 Dominick Grift
Quoted 11 lines · mm
Hi all,
I have an executable started by
/bin/foowhich runs confined within the contextfoo_t.
The process loads (actually doesLD_PRELOAD) bar.so which needs to access resources outsidefoo_t(actuallyunconfined_t).I can allow access to such resources from
foo_t, but I would like to allow such access only for code running within bar.so, instead of the whole process.
Quoted 8 lines
I have been looking in the docs, but I could not find if it is possible to specify a source context for shared libraries, instead of whole processes.
My idea would be to define a contextbar_tfor code running within bar.so, and allow the required access (tounconfined_t) frombar_t, without extending access forfoo_t.Makes sense? Is it possible?
I understand what you are saying but it wouldn't be secure and it is not possible. Instead, run bar.so in a separate program/process and have them communicate over an IPC mechanism.
Quoted 12 lines · Stephen Smalley
Quoted 6 lines · mm
Hi all,
I have an executable started by
/bin/foowhich runs confined within the contextfoo_t.
The process loads (actually doesLD_PRELOAD) bar.so which needs to access resources outsidefoo_t(actuallyunconfined_t).I understand what you are saying but it wouldn't be secure and it is not possible. Instead, run bar.so in a separate program/process and have them communicate over an IPC mechanism.
Thanks for the reply, but it is not clear to me why it would not be secure.
Unfortunately I don't have control on bar.so.
Nonetheless, your reply may suggest the symmetric strategy:
bar.so is in fact an IPC proxy to an external process, say /bin/bar, which currently runs unconfined (and that also I have no control on). What I might think of is to define a bar_t context for /bin/bar, and allow the required access from foo_t to bar_t (instead of allowing from foo_t to unconfined_t). The idea is still to minimize access extension for foo_t, handling the target side instead of the source side.
Moreover, in order not to compromise the functionality of /bin/bar, I would need to allow bar_t the same access as unconfined_t (at least as a first approximation). The fact is that, although I can trust /bin/bar, it is not selinux-aware.
Would this be effective?
What would be the easiest way to define the bar_t context (i.e. define a context with the same access rights as another one)?
Thanks in advance,
M. Manfredini
Quoted 11 lines · mm
Quoted 8 lines · Stephen Smalley
Quoted 6 lines · mm
Hi all,
I have an executable started by
/bin/foowhich runs confined within the contextfoo_t.
The process loads (actually doesLD_PRELOAD) bar.so which needs to access resources outsidefoo_t(actuallyunconfined_t).
Quoted 5 lines
Quoted 4 lines
I understand what you are saying but it wouldn't be secure and it is not possible. Instead, run bar.so in a separate program/process and have them communicate over an IPC mechanism.
Thanks for the reply, but it is not clear to me why it would not be secure.
There is no enforceable separation between the executable and a shared library - they all run in the same process.
Quoted 9 lines
Unfortunately I don't have control on bar.so.
Nonetheless, your reply may suggest the symmetric strategy:
bar.so is in fact an IPC proxy to an external process, say/bin/bar, which currently runs unconfined (and that also I have no control on). What I might think of is to define abar_tcontext for/bin/bar, and allow the required access fromfoo_ttobar_t(instead of allowing fromfoo_ttounconfined_t).
The idea is still to minimize access extension forfoo_t, handling the target side instead of the source side.
Yes, that would be a better approach.
Quoted 4 lines
Moreover, in order not to compromise the functionality of
/bin/bar, I would need to allowbar_tthe same access asunconfined_t(at least as a first approximation). The fact is that, although I can trust/bin/bar, it is not selinux-aware.
I wouldn't do that; otherwise any security gains you are getting are illusory since bar is equivalent to unconfined. It isn't that hard to define a real confined domain for a program.
Quoted 3 lines
Would this be effective?
What would be the easiest way to define thebar_tcontext (i.e. define a context with the same access rights as another one)?
Generally the simplest approach is to define a stub .te file for your domain, include a permissive declaration for it (permissive bar_t;), and then derive a policy from the resulting avc: denied messages via some combination of audit2allow -R and manual examination. In Fedora, there is a sepolgen aka sepolicy-generate tool for generating a stub domain, although to be honest, I haven't used it myself - I just write policy by hand.
Quoted 9 lines · Stephen Smalley
Quoted 5 lines
Moreover, in order not to compromise the functionality of
/bin/bar, I would need to allowbar_tthe same access asunconfined_t(at least as a first approximation). The fact is that, although I can trust/bin/bar, it is not selinux-aware.I wouldn't do that; otherwise any security gains you are getting are illusory since bar is equivalent to unconfined. It isn't that hard to define a real confined domain for a program.
I agree that defining a real confined domain for /bin/bar is a better approach.
It is not clear to me that any security gains would be illusory: even if /bin/bar (from bar_t) has effectively unconfined access, still /bin/foo (i.e. foo_t) could only access bar_t, and not unconfined_t.
Quoted 4 lines
Generally the simplest approach is to define a stub .te file for your domain, include a permissive declaration for it (permissive
bar_t;), and then derive a policy from the resulting avc:
Thanks for the hint of the stub .te file.
The only issue here is that I would need to find a way to trigger all possible avc's from /bin/bar, which is not straightforward.
Quoted 13 lines · On 11/07/2016 09:50 AM, mm19827 wrote:
Quoted 9 lines · Stephen Smalley
Quoted 5 lines
Moreover, in order not to compromise the functionality of
/bin/bar, I would need to allowbar_tthe same access asunconfined_t(at least as a first approximation). The fact is that, although I can trust/bin/bar, it is not selinux-aware.I wouldn't do that; otherwise any security gains you are getting are illusory since bar is equivalent to unconfined. It isn't that hard to define a real confined domain for a program.
Quoted 5 lines
I agree that defining a real confined domain for
/bin/baris a better approach.
It is not clear to me that any security gains would be illusory: even if/bin/bar(frombar_t) has effectively unconfined access, still/bin/foo(i.e.foo_t) could only accessbar_t, and notunconfined_t.
I suppose that's true, depending on what it is that you have to allow between foo_t and bar_t, e.g. you can allow foo_t to connect to a bar_t socket or similar without allowing it to connect to unconfined_t sockets. If you truly want bar_t to be unconfined, you can always just have it call the unconfined_domain() interface in refpolicy, e.g. unconfined_domain(bar_t), and it will inherit all of the unconfined domain rules.
Quoted 7 lines
Quoted 4 lines
Generally the simplest approach is to define a stub .te file for your domain, include a permissive declaration for it (permissive
bar_t;), and then derive a policy from the resulting avc:Thanks for the hint of the stub .te file.
The only issue here is that I would need to find a way to trigger all possible avc's from/bin/bar, which is not straightforward.
Yes, it is better if you have some idea of the expected functionality of bar, whether from source code, static analysis of the binary, strace, or documentation, and can then define up front policy that corresponds.
Quoted 5 lines · Stephen Smalley
I suppose that's true, depending on what it is that you have to allow between
foo_tandbar_t, e.g. you can allowfoo_tto connect to abar_tsocket or similar without allowing it to connect tounconfined_tsockets.
Exactly.
If you truly want bar_t to be unconfined, you can always just
Quoted 4 lines
have it call the
unconfined_domain()interface in refpolicy, e.g.unconfined_domain(bar_t), and it will inherit all of the unconfined domain rules.
Thanks for the info.
It would be great (and this would be my last question), if you could give a pointer to a complete documentation of refpolicy macros and interfaces - I could find the kernel rules, and that it makes use of m4 macros, but not a complete documentation.
Quoted 5 lines
Yes, it is better if you have some idea of the expected functionality of bar, whether from source code, static analysis of the binary, strace, or documentation, and can then define up front policy that corresponds.
I have some idea of the functionality, but I do not have access to all details of the code. It is a closed source commercial product. I think I'll ask the supplier for more info (and eventually to support selinux themselves)
Thanks a lot for your info.
M. Manfredini
Quoted 15 lines · On 11/07/2016 10:11 AM, mm19827 wrote:
Quoted 5 lines · Stephen Smalley
I suppose that's true, depending on what it is that you have to allow between
foo_tandbar_t, e.g. you can allowfoo_tto connect to abar_tsocket or similar without allowing it to connect tounconfined_tsockets.Exactly.
If you truly want
bar_tto be unconfined, you can always justQuoted 4 lines
have it call the
unconfined_domain()interface in refpolicy, e.g.unconfined_domain(bar_t), and it will inherit all of the unconfined domain rules.
Quoted 5 lines
Thanks for the info.
It would be great (and this would be my last question), if you could give a pointer to a complete documentation of refpolicy macros and interfaces - I could find the kernel rules, and that it makes use of m4 macros, but not a complete documentation.
http://oss.tresys.com/docs/refpolicy/api/
It is generated from the refpolicy sources.
refpolicy mailing list is a better place to ask questions about refpolicy, see
http://oss.tresys.com/mailman/listinfo/refpolicy