Skip to contentSkip to conversation

Bug/misfeature of "securityfs"

DISCUSSION Markku Savela 3 participants 6 messages May 26, 2008 – Jun 6, 2008

lore
Share & tools
lore
#0 lore raw

I write a module which creates a securityfs on init

foobar = securityfs_create_dir("foobar", NULL)
and on exit it does
security_fs_remove(foobar);

When I do "insmod" and "rmmod", I see

/sys/kernel/security/foobar/

appear and go away.

Now, if have a shell and do "cd /sys/kernel/security/foobar", the "rmmod" does not remove the directory. The directory disappears when I exit the shell from it via "cd ..". This is fine, and as it should be, but....

IF, while having the shell in the directory, I try to "insmod" again, the insmod fails with "-1 File exists". Again, understandable, BUT when after this I exit the shell from the directory, IT DOES NOT GO AWAY. It's permanetly existing, and module install fails always with "File Exists".

Is this a bug, or am doing something wrong?

The kernel is Ubuntu Hardy heron

    2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 UTC 2008 i686
Signature · 1 line
Markku Savela
#1 lore raw
Quoted 24 lines · Markku Savela

I write a module which creates a securityfs on init

foobar = securityfs_create_dir("foobar", NULL)
and on exit it does
security_fs_remove(foobar);

When I do "insmod" and "rmmod", I see

/sys/kernel/security/foobar/

appear and go away.

Now, if have a shell and do "cd /sys/kernel/security/foobar", the "rmmod" does not remove the directory. The directory disappears when I exit the shell from it via "cd ..". This is fine, and as it should be, but....

IF, while having the shell in the directory, I try to "insmod" again, the insmod fails with "-1 File exists". Again, understandable, BUT when after this I exit the shell from the directory, IT DOES NOT GO AWAY. It's permanetly existing, and module install fails always with "File Exists".

Quoted 4 lines

Is this a bug, or am doing something wrong?

The kernel is Ubuntu Hardy heron

    2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 UTC 2008 i686

Sounds like a bug.

Signature · 2 lines
James Morris
<[email protected]>
#2 lore raw
Quoted 20 lines · James Morris
Quoted 18 lines · Markku Savela

I write a module which creates a securityfs on init

foobar = securityfs_create_dir("foobar", NULL)
and on exit it does
security_fs_remove(foobar);

When I do "insmod" and "rmmod", I see

/sys/kernel/security/foobar/

appear and go away.

Now, if have a shell and do "cd /sys/kernel/security/foobar", the "rmmod" does not remove the directory. The directory disappears when I exit the shell from it via "cd ..". This is fine, and as it should be, but....

Quoted 7 lines
Quoted 7 lines

IF, while having the shell in the directory, I try to "insmod" again, the insmod fails with "-1 File exists". Again, understandable, BUT when after this I exit the shell from the directory, IT DOES NOT GO AWAY. It's permanetly existing, and module install fails always with "File Exists".

Is this a bug, or am doing something wrong?

Yeah, the whole sequence above is "wrong" :)

How is the file always sticking around? Can you still see it in other shells? Is a process still located there somehow?

securityfs is just using libfs for all of this, there shouldn't be any problem here, unless it is also present there.

Or maybe we aren't cleaning up properly on the "file exists" code path? Care to look into that?

thanks,

greg k-h

#3 lore raw
Quoted 39 lines

From: Greg KH <[email protected]>

Quoted 20 lines · James Morris
Quoted 18 lines · Markku Savela

I write a module which creates a securityfs on init

foobar = securityfs_create_dir("foobar", NULL)
and on exit it does
security_fs_remove(foobar);

When I do "insmod" and "rmmod", I see

/sys/kernel/security/foobar/

appear and go away.

Now, if have a shell and do "cd /sys/kernel/security/foobar", the "rmmod" does not remove the directory. The directory disappears when I exit the shell from it via "cd ..". This is fine, and as it should be, but....

Quoted 7 lines
Quoted 7 lines

IF, while having the shell in the directory, I try to "insmod" again, the insmod fails with "-1 File exists". Again, understandable, BUT when after this I exit the shell from the directory, IT DOES NOT GO AWAY. It's permanetly existing, and module install fails always with "File Exists".

Is this a bug, or am doing something wrong?

Yeah, the whole sequence above is "wrong" :)

How is the file always sticking around? Can you still see it in other shells? Is a process still located there somehow?

securityfs is just using libfs for all of this, there shouldn't be any problem here, unless it is also present there.

Quoted 6 lines

Or maybe we aren't cleaning up properly on the "file exists" code path? Care to look into that?

thanks,

greg k-h

I think my original description is somewhat misleading: the file exists seems to come from the "insmod" for the module, not for the seurityfs directory, becuase it appears to think that the module is still loaded (while lsmod does not show it).

The directory is visible from other shells.

#4 lore raw
In reply to Greg KH

I should not really reply from hip in the morning, ignore more previous message. The "file exists" definitely comes from the module init failing, because it finds the directory existing.

Here is some more detailed information and a test module (unfortunately, just pasted in this message):

*shell1*

	*shell2*

         > cd /sys/kernel/security/
         > ls
         apparmor
Quoted 1 line

sudo insmod foobar.ko

> ls
apparmor foobar

Quoted 1 line

sudo rmmod foobar.ko

> ls
apparmor

// so far fine, directory comes and goes...

Quoted 1 line

sudo insmod foobar.ko

> ls
apparmor foobar
> cd foobar/

Quoted 2 lines

sudo rmmod foobar.ko
ls /sys/kernel/security/

apparmor foobar

        > cd ..
Quoted 1 line

ls /sys/kernel/security/

apparmor

// so far fine, directory goes when
// other shell exits it.

Quoted 1 line

sudo insmod foobar.ko

> cd foobar/

Quoted 2 lines

sudo rmmod foobar.ko
ls /sys/kernel/security/

apparmor foobar

Quoted 1 line

sudo insmod foobar.ko

insmod: error inserting 'foobar.ko': -1 File exists

        > cd ..
        > ls
        apparmor  foobar

// 'foobar' still exists, while module unloaded
// and shell also is out.

Quoted 1 line

ls /sys/kernel/security/

apparmor foobar

Quoted 1 line

ls /sys/kernel/security/

apparmor foobar

Quoted 1 line

sudo insmod foobar.ko

insmod: error inserting 'foobar.ko': -1 File exists

// And, now only reboot seems to remove the directory"

-------------------------------------------------------------------
tail /var/log/syslog

May 27 09:49:13 maja kernel: [  192.771424] foobar: Module 'foobar' loaded
May 27 09:49:28 maja kernel: [  207.637838] foobar: Module 'foobar' unloaded
May 27 09:49:35 maja kernel: [  214.890241] foobar: Module 'foobar' loaded
May 27 09:49:46 maja kernel: [  225.719495] foobar: Module 'foobar' unloaded
May 27 09:50:19 maja kernel: [  258.782263] foobar: Module 'foobar' loaded
May 27 09:50:27 maja kernel: [  266.641655] foobar: Module 'foobar' unloaded
May 27 09:50:48 maja kernel: [  288.383145] foobar: Foobar FS create failed
May 27 09:51:11 maja kernel: [  311.323851] foobar: Foobar FS create failed

------------------------------------------------------------------
#include <linux/init.h>
#include <linux/module.h>
#include <linux/security.h>

#define FOOBAR_NAME "foobar"

#undef DBG
#undef DBGG
#undef INFO
#undef ERR

#ifdef FOOBAR_DEBUG
# define DBG(args...) printk(KERN_DEBUG FOOBAR_NAME ": " args)
#else
# define DBG(args...)
#endif
#define DBGG(args...)
#define INFO(args...) printk(KERN_INFO FOOBAR_NAME ": " args) #define ERR(args...) printk(KERN_ERR FOOBAR_NAME ": " args)

static struct dentry* foobar_fs;

static void foobar_cleanup(void)

	{
	if (foobar_fs && !IS_ERR(foobar_fs))
		{
		securityfs_remove(foobar_fs);
		};
	}

static int __init foobar_init(void)

	{
	DBG("foobar_init\n");
	if (foobar_fs)
		{
		ERR("Foobar FS already exists\n");
		return -EEXIST;
		}

	foobar_fs = securityfs_create_dir(FOOBAR_NAME, NULL);
	if (IS_ERR(foobar_fs))
		{
		ERR("Foobar FS create failed\n");
		foobar_cleanup();
		return PTR_ERR(foobar_fs);
		}
	INFO("Module 'foobar' loaded\n");
	return 0;
	}

static void __exit foobar_exit(void)

	{
	DBG("foobar_exit\n");
	foobar_cleanup();
	INFO("Module 'foobar' unloaded\n");
	}

module_init(foobar_init);
module_exit(foobar_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Markku Savela");

#5 lore raw
Quoted 6 lines · Markku Savela

I should not really reply from hip in the morning, ignore more previous message. The "file exists" definitely comes from the module init failing, because it finds the directory existing.

Here is some more detailed information and a test module (unfortunately, just pasted in this message):

<snip>

Hm, yeah, that doesn't look good at all :(

Any thoughts as to if you would have time to look into fixing this? This isn't anything a normal user would ever hit, so I have a lot higher priority things to handle at the moment, and it will be a while before I could get to this.

thanks,

greg k-h