Re: [GIT PULL] SELinux patches for v5.8
From: Linus Torvalds
Date: Tue Jun 02 2020 - 20:31:55 EST
On Mon, Jun 1, 2020 at 6:07 PM Paul Moore <paul@xxxxxxxxxxxxxx> wrote:
> - A number of improvements to various SELinux internal data structures
> to help improve performance. We move the role transitions into a hash
> table. In the content structure we shift from hashing the content
> string (aka SELinux label) to the structure itself, when it is valid.
> This last change not only offers a speedup, but it helps us simplify
> the code some as well.
Side note since you mention performance work: in the past when I've
looked at SELinux performance (generally as part of pathname lookup
etc VFS loads), the biggest cost by far was that all the SELinux data
structures take a ton of cache misses.
Yes, some of the hashing shows up in the profiles, but _most_ of it
was loading the data from inode->i_security etc.
And the reason seemed to be that every single inode ends up having a
separately allocated "struct inode_security_struct" (aka "isec"). Even
if the contents are often all exactly the same for a large set of
inodes that thus _could_ conceptually share the data.
Now, it used to be - before being able to stack security layers -
SElinux would control that pointer, and it could have done some kind
of sharing scheme with copy-on-write behavior (the way we do 'struct
cred' for processes), and it would have caused a much smaller cache
footprint (and thus likely much fewer cache misses).
These days, that sharing of the i_security pointer across different
security layers makes that sound really really painful.
But I do wonder if anybody in selinux land (or general security
subsystem land) has been thinking of maybe at least having a "this
inode has no special labeling" marker that could possibly avoid having
all those extra allocations.
Because it really does end up being visible in profiles how costly it
is to look up any data behind inode->i_security.