Skip to contentSkip to conversation

BUG in security_context_to_sid() ?

DISCUSSION Park Lee 2 participants 4 messages Jan 7, 2005 SELinux security module

lore
Share & tools
lore

Park Lee

author
#0 lore raw

Hi,
I'm now learning SELinux hook function. so, I try
to write such a hook (Just for learning), shown as the following (I'm using Fedora Core 2, kernel:
2.6.5-1.358custom):

static int selinux_check_permission(char
*securitycontext_to_be_checked)

{
        int err = 0;
        u32 sid;
        struct avc_audit_data ad;
        AVC_AUDIT_DATA_INIT(&ad, NET);

        err =
security_context_to_sid(securitycontext_to_be_checked,
strlen(securitycontext_to_be_checked), &sid);
        if (err)
                goto out;

        tsec = current->security;
        err = avc_has_perm(tsec->sid, sid,

SECCLASS_SOCKET, SOCKET__CREATE, NULL, &ad);

out:

        return err;
}

But, every time, when security_context_to_sid() is
called in the hook, the kernel yield a oops as the following:

Debug: sleeping function called from invalid context at mm/slab.c:1980
in_atomic():1, irqs_disabled():0

Call Trace: [<0211691d>]  [<02130a17>]  [<02189857>] 

[<021837a6>] [<02294651>] [<02118840>] [<021189cd>]
[<02263e84>] [<0227a3e4>] [<0227a465>]
[<0227a953>] [<0218befb>] [<0218bc23>] [<02194118>]
[<0218d90d>] [<0218c25f>] [<0218b132>]
[<021894f4>] [<021895f5>] [<0217f686>] [<0217f728>]
[<021835ff>]
[<0227ac21>] [<0227452a>] [<0227af39>] [<0227b3cd>]
[<02264f19>] [<022652e7>] [<02253332>]
[<1195048f>] [<119506af>] [<02253495>] [<0211af6d>]
[<021078b1>] ======================= [<02107337>] [<118aeb59>] [<118aefba>]
[<118adab2>] [<02116b21>] [<02116b21>] [<022a2301>]
[<02115ed2>] [<118afbfe>] [<02116b21>]
[<02116b21>] [<118afb58>] [<118afb5e>] [<021041cd>]

After I've transformed the oops with ksymoops, it
looked like the following:

ksymoops 2.4.9 on i686 2.6.5-1.358custom. Options used
-V (default)
-K (specified)
-L (specified)
-o /lib/modules/2.6.5-1.358custom/ (default) -m /boot/System.map (specified)

No modules in ksyms, skipping objects

Call Trace: [<0211691d>]  [<02130a17>]  [<02189857>] 

[<021837a6>] [<02294651>] [<02118840>] [<021189cd>]
[<02263e84>] [<0227a3e4>] [<0227a465>]
[<0227a953>] [<0218befb>] [<0218bc23>] [<02194118>]
[<0218d90d>] [<0218c25f>] [<0218b132>]
[<021894f4>] [<021895f5>] [<0217f686>] [<0217f728>]
[<021835ff>]
[<0227ac21>] [<0227452a>] [<0227af39>] [<0227b3cd>]
[<02264f19>] [<022652e7>] [<02253332>]
[<1195048f>] [<119506af>] [<02253495>] [<0211af6d>]
[<021078b1>] ======================= [<02107337>] [<118aeb59>] [<118aefba>]
[<118adab2>] [<02116b21>] [<02116b21>] [<022a2301>]
[<02115ed2>] [<118afbfe>] [<02116b21>]
[<02116b21>] [<118afb58>] [<118afb5e>] [<021041cd>] Warning (Oops_read): Code line not seen, dumping what data is available

Trace; 0211691d <__might_sleep+80/8a>
Trace; 02130a17 <__kmalloc+40/76>
Trace; 02189857 <security_context_to_sid+72/1e9>
Trace; 021837a6 <selinux_check_permission+5e/9b>
... ...
... ...
1 warning issued. Results may not be reliable.

Then Is there any bug in security_context_to_sid()
function that cause such a oops? or has it already been modified now?

Thank you very much.

=====
Best Regards,
Park Lee

__________________________________
Do you Yahoo!?
All your favorites on one personal page – Try My Yahoo!
http://my.yahoo.com

--
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.

#1 lore raw
Quoted 7 lines · Park Lee

But, every time, when security_context_to_sid() is
called in the hook, the kernel yield a oops as the following:

Debug: sleeping function called from invalid context at mm/slab.c:1980

security_context_to_sid() is presently only called when it is safe to sleep; thus, it calls kmalloc with GFP_KERNEL rather than GFP_ATOMIC when it makes a copy of the context for processing. If you truly need to use it from non-blocking context, then it would need to be changed to use GFP_ATOMIC. But it would be better if you were to convert the context to a SID earlier while in a process context and then just use the SID later.

Signature · 8 lines
Stephen Smalley <[email protected]>
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.
author
#2 lore raw
Quoted 7 lines · Stephen Smalley

security_context_to_sid() is presently only called when it is safe to sleep; thus, it calls kmalloc with GFP_KERNEL rather than GFP_ATOMIC when it makes a copy of the context for processing. If you truly need to use it from non-blocking context, then it would need to be changed to use GFP_ATOMIC.

Thanks.

Because there are also other hook functions (such as selinux_inode_setxattr(), selinux_inode_post_setxattr(), selinux_inode_setsecurity(), selinux_setprocattr(), etc.) who will call security_context_to_sid(). If I now change security_context_to_sid(), let it call kmalloc with GFP_ATOMIC rather than its original GFP_KERNEL, will this change cause problem when other hook functions call the modified security_context_to_sid() function?

Thanks again.

=====
Best Regards,
Park Lee

__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com

--
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.

#3 lore raw
Quoted 10 lines · Park Lee

Because there are also other hook functions (such as selinux_inode_setxattr(), selinux_inode_post_setxattr(), selinux_inode_setsecurity(), selinux_setprocattr(), etc.) who will call security_context_to_sid(). If I now change security_context_to_sid(), let it call kmalloc with GFP_ATOMIC rather than its original GFP_KERNEL, will this change cause problem when other hook functions call the modified security_context_to_sid() function?

It could cause them to fail under memory pressure rather than blocking and waiting for memory to become available. It would be preferable to change your code to convert the context to a SID while in process context, then use the saved SID when in non-blocking context.

Signature · 8 lines
Stephen Smalley <[email protected]>
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.