Bug 885730

Summary: libselinux-devel: [gs]et*con manual pages should document threading behavior
Product: [Fedora] Fedora Reporter: Florian Weimer <fweimer>
Component: libselinuxAssignee: Daniel Walsh <dwalsh>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: rawhideCC: dwalsh, mgrepl, mitr
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-02-14 17:19:35 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Florian Weimer 2012-12-10 13:49:03 UTC
Description of problem:

The manual pages getfscon(3), getexeccon(3) (and maybe others) should document the threading behavior, that is, if the context is a thread-specific or process-wide attribute.

Version-Release number of selected component (if applicable):

libselinux-devel-2.1.10-3.fc17.x86_64

Comment 1 Daniel Walsh 2012-12-10 16:08:40 UTC
Eric, do you want to take a stab at this?

Comment 2 Miloslav Trmač 2012-12-11 13:51:44 UTC
This might be wrong, take it with a grain of salt:

AFAICS the contexts are thread-scoped in the kernel
http://oss.tresys.com/projects/refpolicy/browser/libselinux/src/setfscreatecon.c?rev=2192d4baa1a47137427ea5f22edb825c915657ce is handled in the kernel by fs/proc/base.c:proc_pid_attr_write => security/selinux/hooks.c:selinux_setprocattr => kernel/cred.c:commit_creds, which manipulates a per-task == per-thread "creds" pointer.

OTOH setfscreatecon.c uses /proc/self, which seems to link to the process, not to the thread - so perhaps the setfscreatecon() ando ther functions that use /proc/self/attr don't actually work in multi-threaded programs?

In any case, selinux_setprocattr fails if a thread attempts to modify the value of another thread, and this error seems to be correctly propagated through libselinux, so in the worst case using these functions in a multi-threaded program will "only" fail to work.

Comment 3 Fedora End Of Life 2013-07-03 22:20:43 UTC
This message is a reminder that Fedora 17 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 17. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '17'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 17's end of life.

Bug Reporter:  Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 17 is end of life. If you 
would still like  to see this bug fixed and are able to reproduce it 
against a later version  of Fedora, you are encouraged  change the 
'version' to a later Fedora version prior to Fedora 17's end of life.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 4 Florian Weimer 2013-07-04 08:19:12 UTC
Still present in libselinux-devel-2.1.13-15.fc19.x86_64.

Comment 5 Florian Weimer 2014-01-27 13:01:08 UTC
(In reply to Miloslav Trmač from comment #2)

> OTOH setfscreatecon.c uses /proc/self, which seems to link to the process,
> not to the thread - so perhaps the setfscreatecon() ando ther functions that
> use /proc/self/attr don't actually work in multi-threaded programs?

I have verified empircally that /proc/self/attr/fscreate reflects the process (or the process with the original PID), but /proc/self/task/%d/attr/fscreate on a separate thread does not change when the main thread calls setfscreatecon (and getfscreatecon on the thread reflects that as well).

So fscreate at least is thread-specific.

Comment 6 Eric Paris 2014-01-31 17:50:12 UTC
Wow, I've ignored this a long time.  set*con are per thread.  Dan, feel free to update the man page...

Comment 7 Daniel Walsh 2014-02-14 17:19:35 UTC
Fixed in libselinux-2.2.2-4.fc21