From: Stephen Smalley <sds@tycho.nsa.gov>
To: Krzysztof Opasiak <k.opasiak@samsung.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, casey@schaufler-ca.com
Cc: jlbec@evilplan.org,
"'Andrzej Pietrasiewicz'" <andrzej.p@samsung.com>,
gregkh@linuxfoundation.org,
"'Michal Nazarewicz'" <mina86@mina86.com>,
"'Robert Baldyga'" <r.baldyga@samsung.com>,
"Rafal Krypa" <r.krypa@samsung.com>,
"Tomasz Swierczek" <t.swierczek@samsung.com>,
"'Karol Lewandowski'" <k.lewandowsk@samsung.com>,
"'Marek Szyprowski'" <m.szyprowski@samsung.com>,
"'Stanislaw Wadas'" <s.wadas@samsung.com>,
kopasiak90@gmail.com,
"'Łukasz Stelmach'" <l.stelmach@samsung.com>
Subject: Re: VFS and LSM issues
Date: Wed, 10 Dec 2014 12:18:06 -0500 [thread overview]
Message-ID: <5488804E.8040404@tycho.nsa.gov> (raw)
In-Reply-To: <022101d01309$09152b00$1b3f8100$%opasiak@samsung.com>
On 12/08/2014 12:04 PM, Krzysztof Opasiak wrote:
> Dear All,
>
> I'm Krzysztof Opasiak from SRPOL (Samsung). I'm working on USB support
> in Tizen and mainline. In those works we use two Virtual File Systems
> - ConfigFS and FunctionFS. Recently I have tried to use them with
> SMACK and I ran into a few issues. Most of them looks to be a generic
> problem with many FS and LSM. You can find description of those issues
> and my research just below in 3 points. I'm not a VFS/LSM specialist so
> your help is very welcome;)
>
> 1) Issues with function FS
>
> It's a VFS which allow to provide custom USB function as userspace
> program. I know that may be quite new for you so let's define this as
> a VFS which works as follow:
>
> $ modprobe g_ffs
> $ mkdir /tmp/mount_root
> $ mount none -t functionfs /tmp/mount_root
> $ ls /tmp/mount_root
> ep0
>
> # now we run our program which writes some data to ep0
> # and based on this kernel creates epX
> # you can find one in tools/usb/ffs-test.c
>
> $ ./my_program /tmp/mount_root &
> $ ls /tmp/mount_root
> ep0 ep1 ep2
>
> Ok so now we would like to use this together with smack. Especially
> with smackfsdef mount option. First two steps go as above and then:
>
> $ mount none -t functionfs -o smackfsdef=my_label /tmp/mount_root
> $ ls -Z /tmp/mount_root/
> _ ep0
>
> Ops! Some bug here we requested to use my_label but we got _. When we
> run our program, rest of epX will get desired label (my_label). I have
> started to dig in kernel to find what happen and probably I found out
> where is a problem. Let's look to mount_fs() code which is executed
> during mount:
>
> struct dentry *
> mount_fs(struct file_system_type *type, int flags, const char *name,
> void *data)
> {
> (...)
> root = type->mount(type, flags, name, data);
> (...)
> error = security_sb_kern_mount(sb, flags, secdata);
> (...)
> }
>
> So what is important here is the order of operations. First is
> executed mount ops provided by selected file system. During this mount
> procedure functionfs executes new_inode(sb) to allocate inode for ep0
> which should appear directly after mount. After returning from mount
> function we execute security_sb_kern_mount() where we *parse the mount
> options* and sets the value for lsm specific structures for example we
> store the label passed in smackfsdef.
>
> The problem here is order of calls because first we call mount for
> given fs where we create a file and after this we fill security
> structures with security mount options. While creating file in mount
> callback super block is filled only with default values for security
> so ep0 has _ label. This looks like a generic issue for all VFS which
> creates indoes before or in their mount procedure.
>
> I'm not sure if we can simply move security_sb_kern_mount() above
> mount for specific fs, do we?
No. Look at SELinux for an example. It puts the inode security
structures into a list and then initializes them during
security_sb_kern_mount(), both to handle labeling of inodes initialized
before first policy load and to handle inodes created during ->mount().
In particular, look at the tail of sb_finish_set_opts() in
security/selinux/hooks.c. As SELinux has been handling this for a long
time, I would call this a bug in Smack, not in the VFS LSM hooks.
prev parent reply other threads:[~2014-12-10 17:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-08 17:04 VFS and LSM issues Krzysztof Opasiak
2014-12-10 4:54 ` Greg KH
2014-12-10 14:17 ` Krzysztof Opasiak
2014-12-10 17:19 ` Stephen Smalley
2014-12-10 17:18 ` Stephen Smalley [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=5488804E.8040404@tycho.nsa.gov \
--to=sds@tycho.nsa.gov \
--cc=andrzej.p@samsung.com \
--cc=casey@schaufler-ca.com \
--cc=gregkh@linuxfoundation.org \
--cc=jlbec@evilplan.org \
--cc=k.lewandowsk@samsung.com \
--cc=k.opasiak@samsung.com \
--cc=kopasiak90@gmail.com \
--cc=l.stelmach@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mina86@mina86.com \
--cc=r.baldyga@samsung.com \
--cc=r.krypa@samsung.com \
--cc=s.wadas@samsung.com \
--cc=t.swierczek@samsung.com \
/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