Skip to contentSkip to conversation

Smack: Don't register smackfs if we're not loaded

PATCH Casey Schaufler 4 participants 6 messages Mar 4, 2008 – Mar 5, 2008

lore
Share & tools
lore
#0 lore raw

----- Original Message ----

Quoted 10 lines

From: Linus Torvalds <[email protected]>
To: Ahmed S. Darwish <[email protected]>
Cc: Casey Schaufler <[email protected]>; LKML <[email protected]>
Sent: Tuesday, March 4, 2008 9:21:19 AM
Subject: Re: [PATCH BUGFIX -rc3] Smack: Don't register smackfs if we're not loaded

Quoted 1 line · Ahmed S. Darwish
Quoted 7 lines
Quoted 2 lines

Smackfs initialization without an enabled Smack leads to an early Oops that renders the system unusable.

I really think this is bogus. Global enables like this are just wrong, and a sign that something else bad is going on.

What is the oops? Why does it happen?

A kernel that is built with both SELinux and Smack contains all of the components for both, including smackfs. If SELinux is chosen as the module to be used and smackfs is initialized the oops occurs because the Smack initialization that smackfs depends on has not been done.

One solution would be to tighten the smackfs code so that it handles the uninitialized LSM case properly.

Another would be to set up Kconfig as to make SELinux and Smack mutually exclusive, although I really don't know how well that would go over in testing circles because "config all on" becomes ambiguous.

A third would be to provide for stacking, but I assume that's beyond the scope of this exercise.

So I think that fixing up smackfs is the right choice at this point.

Quoted 3 lines

Linus

Casey Schaufler
[email protected]

#1 lore raw
Quoted 3 lines · Casey Schaufler

One solution would be to tighten the smackfs code so that it handles the uninitialized LSM case properly.

I really would tend to prefer that.

We had a very similar situation in the ACPI/WMI code, where some WMI helper routines would crash just because the WMI data structures hadn't been initialized.

The proper fix in that case (in my opinion, and the one that thus got committed ;^) was simply to make sure that the data structures were simply always consistent (and empty), even if the code itself was disabled. That just automatically meant that it didn't need any global flags to be tested.

So _if_ the alternative is as simple as just making sure that smackfs keeps its data structures consistent even when disabled, I think that's the right patch, rather than adding a separate hack to not touch them.

Linus

#2 lore raw
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · Casey Schaufler

One solution would be to tighten the smackfs code so that it handles the uninitialized LSM case properly.

I really would tend to prefer that.

Can you simply call init_smk_fs() from smack_init() prior to register_security() ?

- James

Signature · 2 lines
James Morris
<[email protected]>
#3 lore raw
Quoted 6 lines · James Morris
Quoted 4 lines · Linus Torvalds
Quoted 1 line · Casey Schaufler
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

One solution would be to tighten the smackfs code so that it handles the uninitialized LSM case properly.

I really would tend to prefer that.

Can you simply call init_smk_fs() from smack_init() prior to register_security() ?

After analysing below oops:

[    0.072989] Call Trace:
[    0.072989]  [<c017d4a4>] alloc_vfsmnt+0x24/0xd0
[    0.072989]  [<c0168ee1>] vfs_kern_mount+0x31/0x120
[    0.072989]  [<c0168fe2>] kern_mount_data+0x12/0x20
[    0.072989]  [<c038a73c>] init_smk_fs+0x4c/0x80
[    0.072989]  [<c038a6ce>] smack_init+0xae/0xd0
[    0.072989]  [<c038a192>] security_init+0x52/0x70
[    0.072989]  [<c037aaa5>] start_kernel+0x1e5/0x290
[    0.072989]  [<c037a380>] unknown_bootoption+0x0/0x1f0
[    0.072989]  =======================

I've found that vfs_caches_init() got called after calling security_init() in the main kernel init path.

This leads to kern_mount() Oopsing cause of Null dereferencing of mnt_cache in the alloc_vfsmnt(mnt_cache, GFP_KERNEL) step.

I was thinking about exporting the current chosen_lsm[] string, but I don't know if this maybe seen by Linus as another global that arises from bad design. It may not also scale well if the LSM needs to check if it's enabled in various places (lots of strcmp()s).

Regards,

Signature · 5 lines
"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com
#4 lore raw
In reply to Casey Schaufler
Quoted 18 lines · Casey Schaufler

----- Original Message ----

Quoted 17 lines

From: Linus Torvalds <[email protected]>
To: Ahmed S. Darwish <[email protected]>
Cc: Casey Schaufler <[email protected]>; LKML <[email protected]>
Sent: Tuesday, March 4, 2008 9:21:19 AM
Subject: Re: [PATCH BUGFIX -rc3] Smack: Don't register smackfs if we're not loaded

Quoted 3 lines · Ahmed S. Darwish

Smackfs initialization without an enabled Smack leads to an early Oops that renders the system unusable.

I really think this is bogus. Global enables like this are just wrong, and a sign that something else bad is going on.

What is the oops? Why does it happen?

...

Quoted 4 lines

One solution would be to tighten the smackfs code so that it handles the uninitialized LSM case properly.

IMHO no smackfs code should ever execute if smack isn't loaded.

This means catching it from the very fist step where it registers itself in init_smk_fs instead of doing several if(we're enabled) cases in the code path.

The solution should be a _general_ solution, _not_ a SMACK one cause SELinux sufferes from exactly the same problem.

a.k.a:

LSMs need a scalable way to know if they're enabled that makes everyone happy ( especially Linus ;) ).

Regads to all,

Signature · 5 lines
"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com
#5 lore raw
Quoted 2 lines · Ahmed S. Darwish
Quoted 1 line · Casey Schaufler
Quoted 1 line

From: Linus Torvalds <[email protected]>

...

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

What is the oops? Why does it happen?

...

Quoted 4 lines

One solution would be to tighten the smackfs code so that it handles the uninitialized LSM case properly.

Quoted 9 lines

IMHO no smackfs code should ever execute if smack isn't loaded.

This means catching it from the very fist step where it registers itself in init_smk_fs instead of doing several if(we're enabled) cases in the code path.

The solution should be a _general_ solution, _not_ a SMACK one cause SELinux sufferes from exactly the same problem.

Not to be misunderstood here, I'm used to writing SMACK in capitals. I ,ofcourse, don't mean shouting (never will).

Regards,

Signature · 5 lines
"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com