setexeccon vs. setfscreatecon
I see that setexeccon sets the context to be used for next execve call. And then there's setfscreatecon. I want something similar that sets the fscreate context for the next execve call. Does such a function exist? Is there some other way to do what I want?
In case you're wondering, here's my motivation: I'm merging some coreutils selinux changes into upstream and noticed that they would break thread-safety in coreutils' copying engine, src/copy.c -- because they introduce calls to setfscreatecon. From reading the man page for that function, I gather that the fscreate-context is a per-process attribute. As such (like umask and cwd), changing it affects all threads, and its use should be avoided in library-esque code.
What I would like to do is merge the context-printing and context-preserving parts of that patch, but not the context-setting parts (--context=CTX in cp, mkdir, mkfifo, mknod, install). Instead, I'm trying to add an option to runcon that would let me also set the fscreate context for the process it runs. Then, all of the individual context-setting options would be unnecessary.
Does this sound reasonable? Feasible?
Thanks,
Jim
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 13 lines · Jim Meyering
I see that setexeccon sets the context to be used for next execve call. And then there's setfscreatecon. I want something similar that sets the fscreate context for the next execve call. Does such a function exist? Is there some other way to do what I want?
In case you're wondering, here's my motivation: I'm merging some coreutils selinux changes into upstream and noticed that they would break thread-safety in coreutils' copying engine,
src/copy.c-- because they introduce calls to setfscreatecon. From reading the man page for that function, I gather that the fscreate-context is a per-process attribute. As such (like umask and cwd), changing it affects all threads, and its use should be avoided in library-esque code.
Quoted 8 lines
What I would like to do is merge the context-printing and context-preserving parts of that patch, but not the context-setting parts (--context=CTX in cp, mkdir, mkfifo, mknod, install). Instead, I'm trying to add an option to runcon that would let me also set the fscreate context for the process it runs. Then, all of the individual context-setting options would be unnecessary.
Does this sound reasonable? Feasible?
At present, the kernel resets the process attributes (exec, fscreate, and more recent additions like keycreate and sockcreate) upon each execve so that each program starts life with the default policy behaviors for its execve and file creation calls, and follows that behavior unless the program itself explicitly sets the attributes.
With regard to the thread issue, the kernel actually supports per-thread attributes (per-Linux task), but libselinux doesn't presently access it in a manner that allows you to leverage it (via /proc/self rather than /proc/self/task/<tid>). At present, any child thread will just fail upon the libselinux calls since it will be viewed by the kernel as attempting to change the attribute of the thread group leader from a different thread, and we only allow a thread to change its own attributes. libselinux could be changed to use /proc/self/task/<tid>, at which point the kernel would do the right thing, I think.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 21 lines · Stephen Smalley
Quoted 20 lines · Jim Meyering
I see that setexeccon sets the context to be used for next execve call. And then there's setfscreatecon. I want something similar that sets the fscreate context for the next execve call. Does such a function exist? Is there some other way to do what I want?
In case you're wondering, here's my motivation: I'm merging some coreutils selinux changes into upstream and noticed that they would break thread-safety in coreutils' copying engine,
src/copy.c-- because they introduce calls to setfscreatecon. From reading the man page for that function, I gather that the fscreate-context is a per-process attribute. As such (like umask and cwd), changing it affects all threads, and its use should be avoided in library-esque code.What I would like to do is merge the context-printing and context-preserving parts of that patch, but not the context-setting parts (--context=CTX in cp, mkdir, mkfifo, mknod, install). Instead, I'm trying to add an option to runcon that would let me also set the fscreate context for the process it runs. Then, all of the individual context-setting options would be unnecessary.
Quoted 4 lines
Quoted 1 line
Does this sound reasonable? Feasible?
At present, the kernel resets the process attributes (exec, fscreate, and more recent additions like keycreate and sockcreate) upon each execve
Thanks for the quick reply!
What you're saying seems to be at odds with setexeccon.1 as well as with this demonstration (using 2.6.17-1.2462.fc6):
$ id -Z
user_u:system_r:unconfined_t
$ runcon -r object_r -- ./id -Z
user_u:object_r:unconfined_tsince runcon's call to setexeccon does what the man page says it does (set exec context for subsequent execve call) and changes the role from system_r to object_r. Does that mean this behavior is Red Hat/Fedora- specific?
Is there any hope that I could get an interface to allow something similar with respect to the fscreate context?
With such a function, it would be trivial to set the context of files created by an arbitrary program: simply run it via e.g.,
runcon --fs-create-context=FS_CREATE_CONTEXT -- EXEC_CONTEXT PROGRAM ARG...
Without it, most file-creating programs will have to be modified (manually and tediously) to accept a new option allowing the user to select an fs-create context.
Quoted 6 lines
so that each program starts life with the default policy behaviors for its execve and file creation calls, and follows that behavior unless the program itself explicitly sets the attributes.
With regard to the thread issue, the kernel actually supports per-thread attributes (per-Linux task), but libselinux doesn't presently access it
I've heard of the Linux option to convert normally-per-process attributes into per-task ones. However that seems like an overly large stick to shake at this problem. Isn't it onerous, and even dangerous, for a library to require that a multi-threaded application flip that switch in Linux? Some other library used by the application could assume certain attributes are per-process.
Quoted 7 lines
in a manner that allows you to leverage it (via
/proc/selfrather than /proc/self/task/<tid>). At present, any child thread will just fail upon the libselinux calls since it will be viewed by the kernel as attempting to change the attribute of the thread group leader from a different thread, and we only allow a thread to change its own attributes. libselinux could be changed to use /proc/self/task/<tid>, at which point the kernel would do the right thing, I think.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 8 lines · Jim Meyering
What you're saying seems to be at odds with setexeccon.1 as well as with this demonstration (using 2.6.17-1.2462.fc6):
$ id -Z user_u:system_r:unconfined_t $ runcon -r object_r -- ./id -Z user_u:object_r:unconfined_t
Quoted 4 lines
since runcon's call to setexeccon does what the man page says it does (set exec context for subsequent execve call) and changes the role from
system_rtoobject_r. Does that mean this behavior is Red Hat/Fedora- specific?
No, what Steven was saying is that the label for execcon will be reset
on exec (after doing it's thing). To see this visually use "secon --self-exec" instead of id.
% secon
user: user_u
role: system_r
type: unconfined_t
sensitivity:
clearance:
mls-range:
% secon --self-exec
user:
role:
type:
sensitivity:
clearance:
mls-range:
% runcon -r system_r secon
user: user_u
role: system_r
type: unconfined_t
sensitivity:
clearance:
mls-range:
% runcon -r system_r -- secon --self-exec user:
role:
type:
sensitivity:
clearance:
mls-range:
Signature · 4 lines
James Antill - <[email protected]> setsockopt(fd, IPPROTO_TCP, TCP_CONGESTION, ...); setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, ...); setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, ...);
Quoted 10 lines · Jim Meyering
Thanks for the quick reply!
What you're saying seems to be at odds with setexeccon.1 as well as with this demonstration (using 2.6.17-1.2462.fc6):
$ id -Z user_u:system_r:unconfined_t $ runcon -r object_r -- ./id -Z user_u:object_r:unconfined_t
Quoted 4 lines
since runcon's call to setexeccon does what the man page says it does (set exec context for subsequent execve call) and changes the role from
system_rtoobject_r. Does that mean this behavior is Red Hat/Fedora- specific?
No, it just means I didn't explain adequately ;)
When a task sets its exec context to a particular value, then that context is applied to the transformed task as its current context upon its next execve call rather than using the default policy-defined transition (assuming that the caller is permitted by policy to transition to the new context and the new context is permitted by policy to use the new program as its entrypoint). But the exec context itself is reset by that execve, and is not applied to any execve calls made by the new program / transformed task. Those execve calls will then follow the default behavior, which will either be to perform a policy-defined transition or remain in the same context if no transition is defined. So it might even look like the exec context is being propagated just due to the latter inheritance of current context in the absence of a transition, but it isn't. Really. Honest ;)
Quoted 10 lines
Is there any hope that I could get an interface to allow something similar with respect to the fscreate context?
With such a function, it would be trivial to set the context of files created by an arbitrary program: simply run it via e.g.,runcon --fs-create-context=FS_CREATE_CONTEXT --
EXEC_CONTEXTPROGRAM ARG...Without it, most file-creating programs will have to be modified (manually and tediously) to accept a new option allowing the user to select an fs-create context.
In the case where the new program is running in a different context than the caller, we definitely want to reset the attributes to prevent the program from being maliciously influenced by the caller. Otherwise, the caller could try to trick the new program into creating files in a context of its choosing rather than the policy defaults in order to gain unauthorized access to the data. In the case where the new program is running in the same context as the caller, the issue is less clear, but it seemed simpler for programs to always know that they start life operating with the policy-defined behavior and that their initial attribute state is always cleared and only they can set it. I'd be uneasy about breaking that assumption now.
Quoted 9 lines
Quoted 2 lines
With regard to the thread issue, the kernel actually supports per-thread attributes (per-Linux task), but libselinux doesn't presently access it
I've heard of the Linux option to convert normally-per-process attributes into per-task ones. However that seems like an overly large stick to shake at this problem. Isn't it onerous, and even dangerous, for a library to require that a multi-threaded application flip that switch in Linux? Some other library used by the application could assume certain attributes are per-process.
There is no switch for credentials; uids/gids and security contexts are all per-task in Linux and not shareable even via clone. There have been various patches bandied about on linux-kernel over the years to permit sharing, but nothing has been adopted. The kernel keyring support might actually be a step in that direction.
I think that changing libselinux to
read/write /proc/self/task/<tid>/attr/xxx would be fairly straightforward, and the existing kernel would just work (i.e let you set and get the per-thread state that already exists). When we originally wrote the libselinux functions, /proc/self/task didn't exist and /proc/self was a reference to the per-thread state, but they switched that on us early in 2.6, and we never had a real requirement to motivate changing the libselinux functions.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Stephen Smalley <[email protected]> wrote:
...
Quoted 3 lines
No, it just means I didn't explain adequately ;)
When a task sets its exec context to a particular value, then that
...
Ahh... I see, now.
Thanks for taking the time.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: id -Z subsumed by secon?
In reply to a message not in the archiveQuoted 1 line · Jim Meyering
By the way, doesn't secon make id's -Z option unnecessary?
Well id -a is useful as a single line of all the current permissions,
IMO. It's also a lot easier to find id -Z and runcon or secon, IMO.
Signature · 1 line
James Antill <[email protected]>