Re: [PATCH] selinux: Improving SELinux read/write performance

Previous thread: First stab at Elantech touchpad driver for 2.6.22.6. Testers wanted! by Arjan Opmeer on Thursday, September 13, 2007 - 8:00 pm. (3 messages)

Next thread: Wrappers to load bitmaps (Re: [PATCH] Improve ebitmap scanning) by KaiGai Kohei on Thursday, September 13, 2007 - 9:02 pm. (1 message)
To: <selinux@...>
Cc: <ynakam@...>, Stephen Smalley <sds@...>, James Morris <jmorris@...>, Eric Paris <eparis@...>, <kaigai@...>, <linux-security-module@...>, <linux-kernel@...>
Date: Thursday, September 13, 2007 - 8:27 pm

Hello.

I would like to propose patch that reduces overhead in read/write by SELinux.
I sent RFC in previous thread.
http://lkml.org/lkml/2007/9/6/14
As a result of discussion in previous thread,
quality of code has improved, so I would like to submit patch here.

1. Background
Look at benchmark result below.
lmbench simple read/write(average of 5 run).
Big overhead exists especially on SH(SuperH) arch.

1) Result for x86(Pentium 4 2.6Ghz), kernel 2.6.22
Base SELinux Overhead(%)
Simple read 1.10 1.24 12.3
Simple write 1.02 1.14 14.0
* Base: kernel compiled without SELinux support

2) Result for SH(SH4, SH7751R), kernel 2.6.22
Base SELinux Overhead(%)
Simple read 2.39 5.49 130.5
Simple write 2.07 5.10 146.6

2. About patch
It reduces the selinux overhead on read/write by only revalidating
permissions in selinux_file_permission if the task or inode labels have
changed or the policy has changed since the open-time check.
A new LSM hook, security_dentry_open, is added to capture
the necessary state at open time to allow this optimization.

3. Result of benchmark after applying patch
1) Result for x86(Pentium 4 2.6Ghz), kernel 2.6.22
Base SELinux Overhead(%)
Simple read 1.10 1.13 2.3(Before 12.3)
Simple write 1.02 1.024 0.6(Before 14.0)
* Base: kernel compiled without SELinux support

2) Result for SH(SH4, SH7751R), kernel 2.6.22
Base SELinux Overhead(%)
Simple read 2.39 2.63 10.4(Before 130.5)
Simple write 2.07 2.34 13.1(Before 146.6)

Overhead in read/write is reduced a lot.
This patch adds permission check at open time(in __dentry_open),
but open/close performance does not get worse as shown below.

* Lmbench simple open/close
Pentium 4(before patch):
Base SELinux Overhead(%)
open/close 5.97 7.45 24.9
after patch:
open/close 5.97 7.48 25.3

SH(before patch):
...

To: Yuichi Nakamura <ynakam@...>
Cc: <selinux@...>, James Morris <jmorris@...>, Eric Paris <eparis@...>, <kaigai@...>, <linux-security-module@...>, <linux-kernel@...>
Date: Monday, September 17, 2007 - 4:45 pm

Thanks, looks good.

--
Stephen Smalley
National Security Agency

-

To: Stephen Smalley <sds@...>
Cc: Yuichi Nakamura <ynakam@...>, <selinux@...>, Eric Paris <eparis@...>, <kaigai@...>, <linux-security-module@...>, <linux-kernel@...>
Date: Monday, September 17, 2007 - 5:56 pm

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6.git#for-akpm

--
James Morris
<jmorris@namei.org>
-

Previous thread: First stab at Elantech touchpad driver for 2.6.22.6. Testers wanted! by Arjan Opmeer on Thursday, September 13, 2007 - 8:00 pm. (3 messages)

Next thread: Wrappers to load bitmaps (Re: [PATCH] Improve ebitmap scanning) by KaiGai Kohei on Thursday, September 13, 2007 - 9:02 pm. (1 message)