From: Tvrtko Ursulin <tvrtko.ursulin@sophos.com>
To: Greg KH <greg@kroah.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: BUG: Securityfs and bind mounts (2.6.34)
Date: Wed, 14 Jul 2010 17:19:46 +0100 [thread overview]
Message-ID: <201007141719.46488.tvrtko.ursulin@sophos.com> (raw)
In-Reply-To: <20100708154648.GA13923@kroah.com>
[-- Attachment #1: Type: text/plain, Size: 1912 bytes --]
On Thursday 08 Jul 2010 16:46:48 Greg KH wrote:
> On Thu, Jul 08, 2010 at 04:32:42PM +0100, Tvrtko Ursulin wrote:
> > On Thursday 08 Jul 2010 16:20:59 Greg KH wrote:
> > > > :) Well I do not know, but, it kind of smelled like a bug in the
> > > > : vfs/mount
> > > >
> > > > handling/securityfs area so I thought to let experts know. I _think_
> > > > I did nothing that much wrong. Just used the exposed API
> > > > (securityfs_remove) and some bind mount shuffling from userspace.
> > >
> > > securitfs just uses libfs underneath it, and really doesn't have any
> > > bindings for module ownerships, so I wouldn't recommend doing what you
> > > just did.
> >
> > Just do double check what you are saying, securityfs is not safe for use
> > from modules? If so I would then recommend removing the exports otherwise
> > it is an invitation to shoot yourself into the foot.
>
> Hm, did you properly set the module owner of the file_operations that
> you passed to securityfs? That should protect if you have an open file,
> but I doubt anyone thought you would do crazy things like bind mounts on
> top of a ramfs and then think it was safe to unload a lower module :)
Hi again,
Here is the reproducer. Build the attached test module and put test.ko in the
cwd. Then run:
umount /sys/kernel/security
mount none -t securityfs /sys/kernel/security/
insmod test.ko
mount file --bind /sys/kernel/security/test/file
rmmod test
insmod test.ko
umount /sys/kernel/security/test/file
umount /sys/kernel/security # <-------- BANG:
It is a bit different than what I initially said. It looks like reference
counting on a dentry gets messed up once securityfs_create_dir() in second
insmod of test.ko fails with -EEXIST.
HTH,
Tvrtko
Sophos Plc, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom.
Company Reg No 2096520. VAT Reg No GB 348 3873 20.
[-- Attachment #2: test.c --]
[-- Type: text/x-csrc, Size: 968 bytes --]
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/security.h>
static struct dentry *root;
static struct dentry *file;
static int test_open(struct inode *inode, struct file *file)
{
return -1;
}
static struct file_operations test_fops = {
.owner = THIS_MODULE,
.open = test_open,
};
static int __init test_init(void)
{
root = securityfs_create_dir("test", NULL);
if (IS_ERR(root)) {
printk("error creating root %d\n", PTR_ERR(root));
return PTR_ERR(root);
}
file = securityfs_create_file("file", S_IRUSR, root, NULL, &test_fops);
if (IS_ERR(file)) {
printk("error creating file %d\n", PTR_ERR(file));
securityfs_remove(root);
return PTR_ERR(file);
}
return 0;
}
static void __exit test_exit(void)
{
securityfs_remove(file);
securityfs_remove(root);
}
MODULE_LICENSE("GPL");
module_init(test_init);
module_exit(test_exit);
prev parent reply other threads:[~2010-07-14 16:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-08 10:12 Tvrtko Ursulin
2010-07-08 14:43 ` Greg KH
2010-07-08 14:55 ` Tvrtko Ursulin
2010-07-08 15:20 ` Greg KH
2010-07-08 15:32 ` Tvrtko Ursulin
2010-07-08 15:46 ` Greg KH
2010-07-08 16:14 ` Tvrtko Ursulin
2010-07-14 16:19 ` Tvrtko Ursulin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201007141719.46488.tvrtko.ursulin@sophos.com \
--to=tvrtko.ursulin@sophos.com \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®