IMA: move read/write counters into struct inode
Subsystems (4)
PATCH 1/3 IMA: move read/write counters into struct inode
IMA currently alocated an inode integrity structure for every inode in core. This stucture is about 120 bytes long. Most files however (especially on a system which doesn't make use of IMA) will never need any of this space. The problem is that if IMA is enabled we need to know information about the number of readers and the number of writers for every inode on the box. At the moment we collect that information in the per inode iint structure and waste the rest of the space. This patch moves those counters into the struct inode so we can eventually stop allocating an IMA integrity structure except when absolutely needed.
This patch does the minimum needed to move the location of the data. Further cleanups, especially the location of counter updates, may still be possible.
---
fs/inode.c | 2 ++ include/linux/fs.h | 5 ++++ include/linux/ima.h | 5 ++++ security/integrity/ima/ima.h | 3 -- security/integrity/ima/ima_iint.c | 32 +++++++++++--------------- security/integrity/ima/ima_main.c | 46 +++++++++++++++++++++---------------- 6 files changed, 52 insertions(+), 41 deletions(-)
fs/inode.c +2 -0
@@ -24,6 +24,7 @@#include <linux/mount.h> #include <linux/async.h> #include <linux/posix_acl.h> +#include <linux/ima.h> /* * This is needed for the following functions:
@@ -224,6 +225,7 @@ static struct inode *alloc_inode(struct super_block *sb)void __destroy_inode (struct inode *inode) {BUG_ON (inode_has_buffers (inode)); +ima_check_counters (inode);security_inode_free (inode);fsnotify_inode_delete (inode);#ifdef CONFIG_FS_POSIX_ACL
include/linux/fs.h +5 -0
@@ -776,6 +776,11 @@ struct inode {#ifdef CONFIG_SECURITY void *i_security;#endif +#ifdef CONFIG_IMA +unsigned long readcount;/* all protected by i_mutex */ +unsigned long writecount; +unsigned long opencount; +#endif #ifdef CONFIG_FS_POSIX_ACL struct posix_acl *i_acl;struct posix_acl *i_default_acl;
include/linux/ima.h +5 -0
@@ -21,6 +21,7 @@ extern int ima_file_check(struct file *file, int mask);extern void ima_file_free (struct file *file);extern int ima_file_mmap (struct file *file,unsigned long prot);extern void ima_counts_get (struct file *file); +extern void ima_check_counters (struct inode *inode);#else static inline int ima_bprm_check (struct linux_binprm *bprm)
@@ -58,5 +59,9 @@ static inline void ima_counts_get(struct file *file)return ; } +static inline void ima_check_counters (struct inode *inode); +{ +return ; +}#endif /* CONFIG_IMA_H */ #endif /* _LINUX_IMA_H */
security/integrity/ima/ima.h +0 -3
@@ -104,9 +104,6 @@ struct ima_iint_cache {unsigned long flags;u8 digest[IMA_DIGEST_SIZE ];struct mutex mutex;/* protects: version, flags, digest */ -long readcount;/* measured files readcount */ -long writecount;/* measured files writecount */ -long opencount;/* opens reference count */ struct kref refcount;/* ima_iint_cache reference count */ struct rcu_head rcu; };
security/integrity/ima/ima_iint.c +14 -18
@@ -73,6 +73,20 @@ out:return rc; } +void ima_check_counters (struct inode *inode) +{ +if (inode->readcount) +printk (KERN_INFO "%s: readcount: %ld\n" , __func__, inode->readcount); +if (inode->writecount) +printk (KERN_INFO "%s: writecount: %ld\n" , __func__, inode->writecount); +if (inode->opencount) +printk (KERN_INFO "%s: opencount: %ld\n" , __func__, inode->opencount); + + inode->readcount =0 ; + inode->writecount =0 ; + inode->opencount =0 ; +} +/* iint_free - called when the iint refcount goes to zero */ void iint_free (struct kref *kref) {
@@ -80,21 +94,6 @@ void iint_free(struct kref *kref) refcount); iint->version =0 ; iint->flags =0UL ; -if (iint->readcount !=0 ) { -printk (KERN_INFO "%s: readcount: %ld\n" , __func__, - iint->readcount); - iint->readcount =0 ; - } -if (iint->writecount !=0 ) { -printk (KERN_INFO "%s: writecount: %ld\n" , __func__, - iint->writecount); - iint->writecount =0 ; - } -if (iint->opencount !=0 ) { -printk (KERN_INFO "%s: opencount: %ld\n" , __func__, - iint->opencount); - iint->opencount =0 ; - }kref_init (&iint->refcount);kmem_cache_free (iint_cache, iint); }
@@ -131,9 +130,6 @@ static void init_once(void *foo) iint->version =0 ; iint->flags =0UL ;mutex_init (&iint->mutex); - iint->readcount =0 ; - iint->writecount =0 ; - iint->opencount =0 ;kref_init (&iint->refcount); }
security/integrity/ima/ima_main.c +26 -20
110 lines not on this page · raw message
PATCH 2/3 IMA: only allocate iint when needed
IMA always allocates an integrity structure to hold information about every inode, but only needed this structure to tract the number of readers and writers currently accessing a given inode. Since that information was moved into struct inode instead of the integrity struct this patch stops allocating the integrity stucture until it is needed. Thurs greatly reducing memory usage.
---
include/linux/ima.h | 6 -- security/integrity/ima/ima.h | 1 security/integrity/ima/ima_api.c | 2 - security/integrity/ima/ima_iint.c | 4 -- security/integrity/ima/ima_main.c | 91 ++++++++++++++++++++++++++----------- security/security.c | 4 -- 6 files changed, 67 insertions(+), 41 deletions(-)
include/linux/ima.h +0 -6
@@ -15,7 +15,6 @@ struct linux_binprm;#ifdef CONFIG_IMA extern int ima_bprm_check (struct linux_binprm *bprm); -extern int ima_inode_alloc (struct inode *inode);extern void ima_inode_free (struct inode *inode);extern int ima_file_check (struct file *file,int mask);extern void ima_file_free (struct file *file);
@@ -29,11 +28,6 @@ static inline int ima_bprm_check(struct linux_binprm *bprm)return 0 ; } -static inline int ima_inode_alloc (struct inode *inode) -{ -return 0 ; -} -static inline void ima_inode_free (struct inode *inode) {return ;
security/integrity/ima/ima.h +1 -0
@@ -70,6 +70,7 @@ int ima_init(void);void ima_cleanup (void );int ima_fs_init (void );void ima_fs_cleanup (void ); +int ima_inode_alloc (struct inode *inode);int ima_add_template_entry (struct ima_template_entry *entry,int violation,const char *op,struct inode *inode);int ima_calc_hash (struct file *file,char *digest);
security/integrity/ima/ima_api.c +1 -1
@@ -116,7 +116,7 @@ int ima_must_measure(struct ima_iint_cache *iint, struct inode *inode, {int must_measure; -if (iint->flags &IMA_MEASURED ) +if (iint && (iint->flags &IMA_MEASURED ))return 1 ; must_measure =ima_match_policy (inode, function, mask);
security/integrity/ima/ima_iint.c +1 -3
@@ -126,9 +126,7 @@ static void init_once(void *foo) {struct ima_iint_cache *iint = foo; -memset (iint,0 ,sizeof *iint); - iint->version =0 ; - iint->flags =0UL ; +memset (iint,0 ,sizeof (*iint));mutex_init (&iint->mutex);kref_init (&iint->refcount); }
security/integrity/ima/ima_main.c +63 -28
145 lines not on this page · raw message
security/security.c +1 -3
@@ -331,9 +331,7 @@ int security_inode_alloc(struct inode *inode) ret = security_ops->inode_alloc_security (inode);if (ret)return ret; - ret =ima_inode_alloc (inode); -if (ret) -security_inode_free (inode); +return ret; }
PATCH 3/3 IMA: use rbtree instead of radix tree for inode information cache
In reply to Eric ParisThe IMA code needs to store the number of tasks which have an open fd granting permission to write a file even when IMA is not in use. It needs this information in order to be enabled at a later point in time without losing it's integrity garantees. At the moment that means we store a little bit of data about every inode in a cache. We use a radix tree key'd on the inode's memory address. Dave Chinner pointed out that a radix tree is a terrible data structure for such a sparse key space. This patch switches to using an rbtree which should be more efficient.
Bug report from Dave:
I just noticed that slabtop
was reportingi an awfully high usage of radix tree nodes:
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
4200331 2778082 66% 0.55K 144839 29 2317424K radix_tree_node 2321500 2060290 88% 1.00K 72581 32 2322592K xfs_inode 2235648 2069791 92% 0.12K 69864 32 279456K iint_cache
That is, 2.7M radix tree nodes are allocated, and the cache itself is consuming 2.3GB of RAM. I know that the XFS inodei caches are indexed by radix tree node, but for 2 million cached inodes that would mean a density of 1 inode per radix tree node, which for a system with 16M inodes in the filsystems is an impossibly low density. The worst I've seen in a production system like kernel.org is about 20-25% density, which would mean about 150−200k radix tree nodes for that many inodes. So it's not the inode cache.
So I looked up what the iint_cache was. It appears to used for storing per-inode IMA information, and uses a radix tree for indexing. It uses the *address* of the struct inode as the indexing key. That means the key space is extremely sparse - for XFS the struct inode addresses are approximately 1000 bytes apart, which means the closest the radix tree index keys get is ~1000. Which means that there is a single entry per radix tree leaf node, so the radix tree is using roughly 550 bytes for every 120byte structure being cached. For the above example, it's probably wasting close to 1GB of RAM....
---
security/integrity/ima/ima.h | 4 +- security/integrity/ima/ima_iint.c | 86 +++++++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 24 deletions(-)
security/integrity/ima/ima.h +3 -1
@@ -101,6 +101,8 @@ static inline unsigned long ima_hash_key(u8 *digest)/* integrity data associated with an inode */ struct ima_iint_cache { +struct rb_node rb_node;/* rooted in ima_iint_tree */ +struct inode *inode;/* back pointer to inode in question */ u64 version;/* track inode changes */ unsigned long flags;u8 digest[IMA_DIGEST_SIZE ];
@@ -120,7 +122,7 @@ int ima_store_template(struct ima_template_entry *entry, int violation,void ima_template_show (struct seq_file *m,void *e,enum ima_show_type show); -/* radix tree calls to lookup, insert, delete +/* rbtree tree calls to lookup, insert, delete * integrity data associated with an inode. */ struct ima_iint_cache *ima_iint_insert (struct inode *inode);
security/integrity/ima/ima_iint.c +63 -23
129 lines not on this page · raw message
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
I do not like this at all. It bloats the inode with three unsigned
long values for a feature no sane person would ever use. And given that distros are sweet-talked by IBM to enable it the world will pay a huge penality for those 0.5% of the userbase that use IMA.
Please reorder your series to have patch to disable IMA unless explicitly enabled on the kernel command line first, and then second use the rbtree from your last patch.
Quoted 8 lines · Christoph Hellwig
I do not like this at all. It bloats the inode with three unsigned
long values for a feature no sane person would ever use. And given that distros are sweet-talked by IBM to enable it the world will pay a huge penality for those 0.5% of the userbase that use IMA.Please reorder your series to have patch to disable IMA unless explicitly enabled on the kernel command line first, and then second use the rbtree from your last patch.
More cryptic command line options and complexity is not the solution. I have no plans to send (a fixed/"working" version of) Kyle's patch which would cause a userspace regression since working machines would magically stop working.
The right solution is to provide features without unreasonably impacting those who do not want those features. At the moment my patch series reduces memory usage by a factor of at least 40 and eliminates the locking contention and serialization of bringing inodes into and out of core. It does so without introducing ANY additional overhead or complexity.
If there is a general consensus that 24 bytes per inode is too large we can move forward from here and drop the 'opencount' and save 8 bytes (while eliminating the debugging and verification this code has helped to provide in the past)
If there is a general consensus that 16 bytes per inode is too large we can travel down the much more complex route of attempting to collect this information dynamically by freezing userspace, scanning every open file, and calculating the information. We would then have a 2 stage integrity structure, the first with just counters and the second would contain integrity information if needed.
I'm willing to add those next 2 steps to my todo list if there is a consensus that the situation at hand is untenable, but those cannot be my highest priority. We are talking about a feature which has been enabled without massive complaint (aside from having bugs fixed in the kernel, in IMA, and in out of tree modules) in Fedora kernels for over a year. Obviously I think Dave's report is a big deal. Things were really really wrong, and I'm willing to fix it when things are wrong, but eventually I hit the point of diminishing returns.
-Eric
Quoted 22 lines · Eric Paris
Quoted 8 lines · Christoph Hellwig
I do not like this at all. It bloats the inode with three unsigned
long values for a feature no sane person would ever use. And given that distros are sweet-talked by IBM to enable it the world will pay a huge penality for those 0.5% of the userbase that use IMA.Please reorder your series to have patch to disable IMA unless explicitly enabled on the kernel command line first, and then second use the rbtree from your last patch.
More cryptic command line options and complexity is not the solution. I have no plans to send (a fixed/"working" version of) Kyle's patch which would cause a userspace regression since working machines would magically stop working.
The right solution is to provide features without unreasonably impacting those who do not want those features. At the moment my patch series reduces memory usage by a factor of at least 40 and eliminates the locking contention and serialization of bringing inodes into and out of core. It does so without introducing ANY additional overhead or complexity.
Quoted 4 lines
If there is a general consensus that 24 bytes per inode is too large we can move forward from here and drop the 'opencount' and save 8 bytes (while eliminating the debugging and verification this code has helped to provide in the past)
Eric, just to put that in context - changing the size of an inode needs to be conidered carefully because we cache so many of them. We often jump through hoops just to reduce it by 4 or 8 bytes. You are proposing to increase it by 24 bytes (roughly 5%) and as such that _should_ be considered a big deal, especially for something that is currently rarely used.
Personally I that adding a pointer into the struct inode is as much as I'd want to compromise to. Those that want to use IMA or have the possibility of turning it on dynamicaly can accept the additional overhead of another memory allocation during inode allocation as the cost of using this functionality. That's the way the security subsystem works, so I don't see any problems with doing this for IMA and it turns the overhead problem into one that only affects those that have it both configured and enabled. That seems like a reasonable compromise to me....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 8 lines · Dave Chinner
On Mon, Oct 18, 2010 at 10:14:03PM -0400, Eric Paris wrote:
Eric, just to put that in context - changing the size of an inode needs to be conidered carefully because we cache so many of them. We often jump through hoops just to reduce it by 4 or 8 bytes. You are proposing to increase it by 24 bytes (roughly 5%) and as such that _should_ be considered a big deal, especially for something that is currently rarely used.
In my mind it's framed a little differently, my patch series is reducing it from ~900 bytes to 24 bytes. Even though that memory might not have been inside struct inode if there is always a 1-1 mapping it might as
well be.... I'm going from seriously broken to a hell of a lot better.
I believe that when I resend this series I'll drop 8 more of those bytes (open count as I think we can do without that these days).
Quoted 9 lines
Personally I that adding a pointer into the struct inode is as much as I'd want to compromise to. Those that want to use IMA or have the possibility of turning it on dynamicaly can accept the additional overhead of another memory allocation during inode allocation as the cost of using this functionality. That's the way the security subsystem works, so I don't see any problems with doing this for IMA and it turns the overhead problem into one that only affects those that have it both configured and enabled. That seems like a reasonable compromise to me....
The problem is that this would actually waste another 8 bytes (the size of the pointer in struct inode) since IMA is still going to need to allocate a structure for every inode to hold the 16-24 bytes of counters. That 16-24 might not be in struct inode, but like I said, if there is a 1-1 mapping between the two there is no difference.
I said that if there was a consensus that this overhead was still too large (and it seems that may be the case) I would put looking at using a userspace freezer to attempt to collect the information dynamically on my todo list. I'll gladly do that but we have a space/time tradeoff I'd rather have a consensus on before I start.
If I go the pointer in struct inode route, I don't need to serialize entry and removal from core of every inode if IMA is enabled (while I add and remove it from the IMA lookup tree.) If I don't add any fields to struct inode I'll need to serialize while I add them to the IMA lookup tree, but at the savings of a void * in struct inode.
My guess is that most people will say forcing users to serialize and saving 8bytes per inode is the better choice, but I know there is scalability work going on and I want to make sure everyone agrees that is the right choice before we spend a lot of time on anything like this...
-Eric
Eric,
I think you and just about everyone here are on a different page, and before we have the basic disagreement settled I'm not sure we can make much progress.
Can you please explain why a feature like IMA that no sane user would ever want should cause _any_ overhead for users that just have it compiled in because their distro or defconfig did without actually using.
What exactly is the problem to require the few people that want it to use a kernel command line option and/or an _DEFAULT_ON config option?
Quoted 3 lines · Eric Paris
More cryptic command line options and complexity is not the solution. I have no plans to send (a fixed/"working" version of) Kyle's patch which would cause a userspace regression since working machines would magically stop working.
That is a valid argument.
Quoted 5 lines
The right solution is to provide features without unreasonably impacting those who do not want those features. At the moment my patch series reduces memory usage by a factor of at least 40 and eliminates the locking contention and serialization of bringing inodes into and out of core. It does so without introducing ANY additional overhead or complexity.
And that argument is missing the point IMO. Christoph is perfectly correct to observe:
It bloats the inode with three unsigned long values for a feature no sane person would ever use.
that's 24 bytes per inode - when in the past we've made _huge_ efforts to minimally shrink it by a few bytes.
Quoted 9 lines
If there is a general consensus that 24 bytes per inode is too large we can move forward from here and drop the 'opencount' and save 8 bytes (while eliminating the debugging and verification this code has helped to provide in the past)
If there is a general consensus that 16 bytes per inode is too large we can travel down the much more complex route of attempting to collect this information dynamically by freezing userspace, scanning every open file, and calculating the information. We would then have a 2 stage integrity structure, the first with just counters and the second would contain integrity information if needed.
Hm, why would all that be needed?
The security subsystem already has a private-data extension in struct inode:
struct inode {
...
#ifdef CONFIG_SECURITY
void *i_security; #endif
...
}
That could be used for IMA, right? IMA state can either embedd in struct inode_security_struct or the security subsystem could define an intermediate data structure. (it's up to the security subsystem how it wants to make use of this data pointer.)
An unlimited amount of optional information can be attached that way.
Thanks,
Ingo
Quoted 10 lines · Eric Paris
IMA currently alocated an inode integrity structure for every inode in core. This stucture is about 120 bytes long. Most files however (especially on a system which doesn't make use of IMA) will never need any of this space. The problem is that if IMA is enabled we need to know information about the number of readers and the number of writers for every inode on the box. At the moment we collect that information in the per inode iint structure and waste the rest of the space. This patch moves those counters into the struct inode so we can eventually stop allocating an IMA integrity structure except when absolutely needed.
Quoted 4 lines
This patch does the minimum needed to move the location of the data. Further cleanups, especially the location of counter updates, may still be possible.
Signed-off-by Eric Paris <[email protected]>
Noone should apply this, it doesn't build on !CONFIG_IMA. Notice my
extra ; on the end of the line :(
Quoted 6 lines
include/linux/ima.h +4
-0+static inline void ima_check_counters (struct inode *inode); +{ +return ; +}#endif /* CONFIG_IMA_H */ #endif /* _LINUX_IMA_H */
Quoted 10 lines · Eric Paris
IMA currently alocated an inode integrity structure for every inode in core. This stucture is about 120 bytes long. Most files however (especially on a system which doesn't make use of IMA) will never need any of this space. The problem is that if IMA is enabled we need to know information about the number of readers and the number of writers for every inode on the box. At the moment we collect that information in the per inode iint structure and waste the rest of the space. This patch moves those counters into the struct inode so we can eventually stop allocating an IMA integrity structure except when absolutely needed.
Hmm. I don't think this is really acceptable as-is.
First off (and most trivially) - the fields are misnamed. Just calling them "{open,read,write}count" was fine when it was part of an ima structure, but for all the historical reasons, inode fields are called 'i_xyzzy'.
Secondly, we already maintain a write count (called "i_writecount"). Why is the IMA writecount different, and should it be?
Thirdly, why is it an "unsigned long"? Are the IMA numbers cumulative or something? How could you ever overflow a 32-bit counter if not?
Finally, why does IMA even care about the read-counts vs open-counts? Why not just open-counts, and consider any non-write to be an open?
In short, I think this patch would be _much_ more acceptable if it added just a _single_ 32-bit "i_opencount". And even then I'd ask "what's the difference between i_opencount and our already existing i_count?
Linus
IOW, at a glance, I think it might be much more acceptable if we only added --
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · Linus Torvalds
Quoted 10 lines · Eric Paris
IMA currently alocated an inode integrity structure for every inode in core. This stucture is about 120 bytes long. Most files however (especially on a system which doesn't make use of IMA) will never need any of this space. The problem is that if IMA is enabled we need to know information about the number of readers and the number of writers for every inode on the box. At the moment we collect that information in the per inode iint structure and waste the rest of the space. This patch moves those counters into the struct inode so we can eventually stop allocating an IMA integrity structure except when absolutely needed.
Quoted 6 lines
Hmm. I don't think this is really acceptable as-is.
First off (and most trivially) - the fields are misnamed. Just calling them "{open,read,write}count" was fine when it was part of an ima structure, but for all the historical reasons, inode fields are called '
i_xyzzy'.
Will fix.
Quoted 2 lines
Secondly, we already maintain a write count (called "
i_writecount"). Why is the IMA writecount different, and should it be?
I ask Al about reusing this field long ago and he indicated it had a very different meaning. I can't remember what he indicated it meant off the top of my head but I'll take a look at it again. Lines like this leave me leary:
drivers/md/md.c::deny_bitmap_write_access()
atomic_set(&inode->i_writecount, -1);
Quoted 2 lines
Thirdly, why is it an "unsigned long"? Are the IMA numbers cumulative or something? How could you ever overflow a 32-bit counter if not?
Not cumulative. 32bits would probably be fine.
Quoted 2 lines
Finally, why does IMA even care about the read-counts vs open-counts? Why not just open-counts, and consider any non-write to be an open?
What IMA needs to function is the current readers and current writers. The open count was originally very useful when a number of places inside the kernel were allocating struct files themselves rather than letting the VFS do the lifting and we could end up with more struct files to a given inode than IMA realized. Back then IMA started trying to do one-off hooks to each filesystem doing this to fix the counters and measure appropriately but we eventually decided it was best to move all struct file creation into the vfs so it couldn't get out of whack. I believe at this point we could drop the opencount....
Quoted 4 lines
In short, I think this patch would be _much_ more acceptable if it added just a _single_ 32-bit "
i_opencount". And even then I'd ask "what's the difference betweeni_opencountand our already existingi_count?
i_count, I believe, is much different. i_count is counting the number of dentries in core referencing the inode, even if none of them are being used in any struct file or if one dentry is being referenced in 1000 struct files. The IMA counters are from a higher level, they counts the number of struct files referencing this inode.
I'll resend, shrinking from unsigned long to unsigned int and dropping opencount from struct inode. Should get us from using ~900 bytes per inode to using about 8 bytes per inode.
And like I said, if that still seems like too much overhead to most people (and it seems that's the case) I'll look at how to get down to 0, but it isn't going to be a fast obvious change...
-Eric
Al Viro
maintainerQuoted 9 lines · Eric Paris
I ask Al about reusing this field long ago and he indicated it had a very different meaning. I can't remember what he indicated it meant off the top of my head but I'll take a look at it again.
i_count, I believe, is much different.i_countis counting the number of dentries in core referencing the inode, even if none of them are being used in any struct file or if one dentry is being referenced in 1000 struct files. The IMA counters are from a higher level, they counts the number of struct files referencing this inode.
a) i_writecount is about VM_DENYWRITE, basically. Reusing it for ima could get unpleasant; when it's positive, we are fine, but it can get negative as well. IMA will have interesting time dealing with that.
b) i_count is simply a refcount for struct inode. Not exactly the number of dentries, but that's the main contributor. Basically, that's "how many pointers outside of inode hash chains point that that struct inode at the moment".
Quoted 9 lines · Al Viro
a)
i_writecountis aboutVM_DENYWRITE, basically. Reusing it for ima could get unpleasant; when it's positive, we are fine, but it can get negative as well. IMA will have interesting time dealing with that.b)
i_countis simply a refcount for struct inode. Not exactly the number of dentries, but that's the main contributor. Basically, that's "how many pointers outside of inode hash chains point that that struct inode at the moment".
My question was deeper. More along the lines of "why would IMA care?"
How/why could IMA ever care about the pointless and trivial differences between its current private open/read/write counts and the counts that we already maintain?
Yes, yes, I realize that they have technical differences in what they count. That's not the question. The question is "Why would IMA care?"
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Al Viro
maintainerQuoted 11 lines · Linus Torvalds
Quoted 9 lines · Al Viro
a)
i_writecountis aboutVM_DENYWRITE, basically. ?Reusing it for ima could get unpleasant; when it's positive, we are fine, but it can get negative as well. ?IMA will have interesting time dealing with that.b)
i_countis simply a refcount for struct inode. ?Not exactly the number of dentries, but that's the main contributor. ?Basically, that's "how many pointers outside of inode hash chains point that that struct inode at the moment".
Quoted 8 lines
My question was deeper. More along the lines of "why would IMA care?"
How/why could IMA ever care about the pointless and trivial differences between its current private open/read/write counts and the counts that we already maintain?
Yes, yes, I realize that they have technical differences in what they count. That's not the question. The question is "Why would IMA care?"
I'd rather not say what I think about IMA sanity (and usefulness); as for what it tries to do... They want to whine if you open a file that is already opened for write and they want to whine if you open a file for write when it's already opened for read. Unless they decide to leave the file alone, that is.
Quoted 12 lines · Al Viro
Quoted 11 lines · Linus Torvalds
Quoted 9 lines · Al Viro
a)
i_writecountis aboutVM_DENYWRITE, basically. ?Reusing it for ima could get unpleasant; when it's positive, we are fine, but it can get negative as well. ?IMA will have interesting time dealing with that.b)
i_countis simply a refcount for struct inode. ?Not exactly the number of dentries, but that's the main contributor. ?Basically, that's "how many pointers outside of inode hash chains point that that struct inode at the moment".
Quoted 8 lines
Quoted 8 lines
My question was deeper. More along the lines of "why would IMA care?"
How/why could IMA ever care about the pointless and trivial differences between its current private open/read/write counts and the counts that we already maintain?
Yes, yes, I realize that they have technical differences in what they count. That's not the question. The question is "Why would IMA care?"
The filesystem prevents files being executed from being opened for write. The same guarantees that the file won't change, obviously, doesn't exist for files being opened for read. Thus measuring a file opened for read that has already been open for write, has no meaning. Unfortunately, since the inode counters don't provide this information, IMA maintains a separate set of counters.
Quoted 4 lines
I'd rather not say what I think about IMA sanity (and usefulness); as for what it tries to do... They want to whine if you open a file that is already opened for write and they want to whine if you open a file for write when it's already opened for read. Unless they decide to leave the file alone, that is.
You left out one minor detail, invalidate the PCR as well.
Mimi
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Mimi" == Mimi Zohar <[email protected]> writes:
Quoted 12 lines · Al Viro
Quoted 12 lines · Linus Torvalds
Quoted 11 lines · Al Viro
Quoted 9 lines
a)
i_writecountis aboutVM_DENYWRITE, basically. ?Reusing it for ima could get unpleasant; when it's positive, we are fine, but it can get negative as well. ?IMA will have interesting time dealing with that.b)
i_countis simply a refcount for struct inode. ?Not exactly the number of dentries, but that's the main contributor. ?Basically, that's "how many pointers outside of inode hash chains point that that struct inode at the moment".
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
My question was deeper. More along the lines of "why would IMA care?"
How/why could IMA ever care about the pointless and trivial differences between its current private open/read/write counts and the counts that we already maintain?
Yes, yes, I realize that they have technical differences in what they count. That's not the question. The question is "Why would IMA care?"
Mimi> The filesystem prevents files being executed from being opened Mimi> for write. The same guarantees that the file won't change, Mimi> obviously, doesn't exist for files being opened for read. Thus Mimi> measuring a file opened for read that has already been open for Mimi> write, has no meaning. Unfortunately, since the inode counters Mimi> don't provide this information, IMA maintains a separate set of Mimi> counters.
Does this mean I can't replace /bin/sh on a running system using IMA at all, even if just one process has it opened and is running? So how the hell am I supposed to do live upgrades on a system?
Currently, /bin/sh gets replaced with the newer, better (for some value of better :-) version, while currently running users aren't impacted at all. New users pick up the new binary.
Gah! The only way to upgrade such a system would look be via a reboot. Not very nice at all... or can the root user disable IMA, upgrade a binary, then re-start IMA on a system?
So how does this improve security if root is compromised?
John
Al Viro
maintainerQuoted 3 lines · John Stoffel
Does this mean I can't replace
/bin/shon a running system using IMA at all, even if just one process has it opened and is running? So how the hell am I supposed to do live upgrades on a system?
rename(2). Prohibition against write(2) to binary being executed is *old*. Try to do the following:
cp /bin/sh /tmp/tmp/sh &
cat /bin/ls >/tmp/sh
and you'll get
sh: /tmp/sh: Text file busy
That has nothing to do with IMA...
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Al" == Al Viro <[email protected]> writes:
Quoted 3 lines · John Stoffel
Quoted 3 lines
Does this mean I can't replace
/bin/shon a running system using IMA at all, even if just one process has it opened and is running? So how the hell am I supposed to do live upgrades on a system?
Al> rename(2). Prohibition against write(2) to binary being executed is Al> *old*. Try to do the following:
Al> cp /bin/sh /tmp
Al> /tmp/sh &
Al> cat /bin/ls >/tmp/sh
Al> and you'll get
Al> sh: /tmp/sh: Text file busy
Al> That has nothing to do with IMA...
Duh, makes sense. Thanks for educating me. I still IMA is a waste of system resources...
John
Quoted 4 lines · Al Viro
I'd rather not say what I think about IMA sanity (and usefulness); as for what it tries to do... They want to whine if you open a file that is already opened for write and they want to whine if you open a file for write when it's already opened for read. Unless they decide to leave the file alone, that is.
Hm. Sounds like the same question that the file leases code needs answered. The important difference is that the leases code can just refuse to set a lease on inodes with multiple dentries.
While my mind's on it ... Al, is this code even close to correct?
if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0))
goto out;
if ((arg == F_WRLCK)
&& ((atomic_read(&dentry->d_count) > 1)
|| (atomic_read(&inode->i_count) > 1)))
goto out;Signature · 4 lines
Matthew Wilcox Intel Open Source Technology Centre "Bill, look, we understand that you're interested in selling us this operating system, but compare it to ours. We can't possibly take such a retrograde step."
Al Viro
maintainerQuoted 4 lines · Matthew Wilcox
Hm. Sounds like the same question that the file leases code needs answered. The important difference is that the leases code can just refuse to set a lease on inodes with multiple dentries.
Quoted 8 lines
While my mind's on it ... Al, is this code even close to correct?
if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0)) goto out; if ((arg == F_WRLCK) && ((atomic_read(&dentry->d_count) > 1) || (atomic_read(&inode->i_count) > 1))) goto out;
No. This is complete junk; note that e.g. ls -lR will disrupt it, since lstat(2) will bump dentry refcount. The first part is more or less OK; the second makes no sense.
What is it trying to do? Note that the first part also doesn't make a lot of sense, since you could be acquiring a write reference *right* *now*, just as that check passes. And you could finish getting it before you get to do anything else in generic_setlease().
Quoted 14 lines · Al Viro
Quoted 4 lines · Matthew Wilcox
Hm. Sounds like the same question that the file leases code needs answered. The important difference is that the leases code can just refuse to set a lease on inodes with multiple dentries.
Quoted 8 lines
While my mind's on it ... Al, is this code even close to correct?
if ((arg == F_RDLCK) && (atomic_read(&inode->i_writecount) > 0)) goto out; if ((arg == F_WRLCK) && ((atomic_read(&dentry->d_count) > 1) || (atomic_read(&inode->i_count) > 1))) goto out;
Quoted 3 lines
No. This is complete junk; note that e.g. ls -lR will disrupt it, since lstat(2) will bump dentry refcount. The first part is more or less OK; the second makes no sense.
It may be nobody cares about false positives--if leases are something provided as a caching optimization, then it's OK to deny them more often than strictly necessary.
(In fact, if you're using the write lease to allow somebody else to cache writes, then you want the stat to break the lease so it can get can trigger a cache flush and get an updated mtime.)
Not that I'll claim those checks are correct.
Quoted 4 lines
What is it trying to do? Note that the first part also doesn't make a lot of sense, since you could be acquiring a write reference *right* *now*, just as that check passes. And you could finish getting it before you get to do anything else in
generic_setlease().
Yeah, that's a race.
The lease code is broken. On my list of problems:
- Leases are broken only by conflicting opens; but both nfsv4 delegations and (I'm told) Windows op locks actually require that read leases be broken on any operation that changes file metadata--including unlink, link, rename, chmod, and chown.
- The internal kernel api used for lease-breaking is inherently racy as long as it consists of a single break_lease() call. (We probably need deny_leases() and undeny_leases(), or something.)
I'd be happy just to have read leases that worked correctly; write leases (which, at least for the NFSv4 server's purposes, also need to be broken on *access* to metadata) are worse.
I have patches that attempted to replace the current mechanism for F_RDLCK leases with an i_leasecount modeled on i_writecount. (So positive counts the number of leases held, negative counts operations temporarily disabling leases.) They were never completely correct.
I also wasn't sure what sort of requirements I should meet to avoid noticeable scalability problems (how much additional space in the inode could I get away with? What about additional locks, or just writes to inode fields, on read opens?).
--b.
Executive summary of the day's work:
Yesterday morning: 944 bytes per inode in core
Yesterday night: 24 bytes per inode in core
Tonight: 4 bytes per inode in core.
That's a x236 time reduction in memory usage. No I didn't even start looking at a freezer. Which could bring that 4 down to 0, but would add a scalability penalty on all inodes when IMA was enabled.
The memory associated with inodes that IMA actually cares about has gone from 312 to 320 bytes.
I'm going to follow up with my patch series again but they aren't really ready to be applied. The IBM people who wrote IMA are reviewing them. I have some questions if my RCU+RBTREE usage is valid/correct. I'd really like Al to take a close look at the last patch in the series to make sure my use of i_writecount actually does what I want it to do...
-Eric
Quoted 8 lines · Eric Paris
Executive summary of the day's work:
Yesterday morning: 944 bytes per inode in core
Yesterday night: 24 bytes per inode in core
Tonight: 4 bytes per inode in core.That's a x236 time reduction in memory usage. No I didn't even start looking at a freezer. Which could bring that 4 down to 0, but would add a scalability penalty on all inodes when IMA was enabled.
Why not use inode->i_security intelligently? That already exists so that way it's 0 bytes.
Thanks,
Ingo
Quoted 7 lines · Ingo Molnar
Quoted 5 lines · Eric Paris
Executive summary of the day's work:
Yesterday morning: 944 bytes per inode in core
Yesterday night: 24 bytes per inode in core
Tonight: 4 bytes per inode in core.
Quoted 8 lines
Quoted 3 lines
That's a x236 time reduction in memory usage. No I didn't even start looking at a freezer. Which could bring that 4 down to 0, but would add a scalability penalty on all inodes when IMA was enabled.
Why not use
inode->i_securityintelligently? That already exists so that way it's 0 bytes.Thanks,
It still wouldn't be 0 bytes since there would be a 1-1 mapping from inode to i_security structs. It would just be hiding the memory somewhere else so it's harder to spot. And that's exactly how we got into this situation, instead of just doing thing in the inode we hid it away in a radix tree node and ima_iint_cache. In any case it would require a secondary structure
struct generic_lsm_inode_structure
{
IMA Fields
void *lsm_inode_structure;
}Which means yet another pointer to the real per LSM inode struct. So it would actually likely cost memory....
The real reason I don't pursue this route is because of the litany of different ways this pointer is used in different LSMs (or not used at all.) And we all know that LSM authors aren't known for seeing the world the same way as each other. As a maintainer of one of those LSMs even I'm scared to try pushing that forward....
Quoted 12 lines · Eric Paris
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Eric Paris
Executive summary of the day's work:
Yesterday morning: 944 bytes per inode in core
Yesterday night: 24 bytes per inode in core
Tonight: 4 bytes per inode in core.That's a x236 time reduction in memory usage. No I didn't even start looking at a freezer. Which could bring that 4 down to 0, but would add a scalability penalty on all inodes when IMA was enabled.
Quoted 7 lines
Quoted 4 lines
Why not use
inode->i_securityintelligently? That already exists so that way it's 0 bytes.Thanks,
It still wouldn't be 0 bytes since there would be a 1-1 mapping from inode to
i_securitystructs. [...]
Only for IMA-affected files, right?
My point is to keep it 0 overhead for the _non IMA common case_.
Quoted 4 lines
The real reason I don't pursue this route is because of the litany of different ways this pointer is used in different LSMs (or not used at all.) And we all know that LSM authors aren't known for seeing the world the same way as each other. As a maintainer of one of those LSMs even I'm scared to try pushing that forward....
Ugh. That's a perfect reason to do it exactly like i suggested.
Thanks,
Ingo
Quoted 17 lines · Ingo Molnar
Quoted 15 lines · Eric Paris
Quoted 14 lines · Ingo Molnar
Quoted 8 lines · Eric Paris
Executive summary of the day's work:
Yesterday morning: 944 bytes per inode in core
Yesterday night: 24 bytes per inode in core
Tonight: 4 bytes per inode in core.That's a x236 time reduction in memory usage. No I didn't even start looking at a freezer. Which could bring that 4 down to 0, but would add a scalability penalty on all inodes when IMA was enabled.
Why not use
inode->i_securityintelligently? That already exists so that way it's 0 bytes.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Thanks,
It still wouldn't be 0 bytes since there would be a 1-1 mapping from inode to
i_securitystructs. [...]Only for IMA-affected files, right?
No, we need to keep the open read counter even for non-IMA-affected files in case we later determine that it is IMA-affected. That's the 4 bytes I have today, which I said could be eliminated with a freezer that calculated it when IMA was enabled, but isn't something I'm looking at right now....
-Eric
-Eric
Quoted 21 lines · Ingo Molnar
Quoted 11 lines · Eric Paris
Quoted 10 lines · Ingo Molnar
Quoted 8 lines · Eric Paris
Executive summary of the day's work:
Yesterday morning: 944 bytes per inode in core
Yesterday night: 24 bytes per inode in core
Tonight: 4 bytes per inode in core.That's a x236 time reduction in memory usage. No I didn't even start looking at a freezer. Which could bring that 4 down to 0, but would add a scalability penalty on all inodes when IMA was enabled.
Quoted 6 lines
Quoted 4 lines
Why not use
inode->i_securityintelligently? That already exists so that way it's 0 bytes.Thanks,
It still wouldn't be 0 bytes since there would be a 1-1 mapping from inode to
i_securitystructs. [...]Only for IMA-affected files, right?
Quoted 7 lines
My point is to keep it 0 overhead for the
_nonIMA commoncase_.Quoted 4 lines
The real reason I don't pursue this route is because of the litany of different ways this pointer is used in different LSMs (or not used at all.) And we all know that LSM authors aren't known for seeing the world the same way as each other. As a maintainer of one of those LSMs even I'm scared to try pushing that forward....
Ugh. That's a perfect reason to do it exactly like i suggested.
If you would like to make a proposal on LSM stacking other than the traditional "rip the LSM out" I am sure that everyone in the IMA, SELinux, TOMOYO, AppArmor and Smack communities would be happy to have a look. Short of having a viable mechanism for multiple LSMs to coexist IMA needs its separate space. Yes, people do use both IMA and LSMs on the same machine at the same time.
Quoted 9 lines
Thanks,
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 28 lines · Casey Schaufler
Quoted 27 lines · Ingo Molnar
Quoted 11 lines · Eric Paris
Quoted 10 lines · Ingo Molnar
Quoted 8 lines · Eric Paris
Executive summary of the day's work:
Yesterday morning: 944 bytes per inode in core
Yesterday night: 24 bytes per inode in core
Tonight: 4 bytes per inode in core.That's a x236 time reduction in memory usage. No I didn't even start looking at a freezer. Which could bring that 4 down to 0, but would add a scalability penalty on all inodes when IMA was enabled.
Quoted 6 lines
Quoted 4 lines
Why not use
inode->i_securityintelligently? That already exists so that way it's 0 bytes.Thanks,
It still wouldn't be 0 bytes since there would be a 1-1 mapping from inode to
i_securitystructs. [...]Only for IMA-affected files, right?
My point is to keep it 0 overhead for the
_nonIMA commoncase_.Quoted 4 lines
The real reason I don't pursue this route is because of the litany of different ways this pointer is used in different LSMs (or not used at all.) And we all know that LSM authors aren't known for seeing the world the same way as each other. As a maintainer of one of those LSMs even I'm scared to try pushing that forward....
Quoted 7 lines
Quoted 1 line
Ugh. That's a perfect reason to do it exactly like i suggested.
If you would like to make a proposal on LSM stacking other than the traditional "rip the LSM out" I am sure that everyone in the IMA, SELinux, TOMOYO, AppArmor and Smack communities would be happy to have a look. Short of having a viable mechanism for multiple LSMs to coexist IMA needs its separate space. Yes, people do use both IMA and LSMs on the same machine at the same time.
Yes, that's the essence of what i suggested: if various security concepts can be present at once then inode->security should not be a stupid pointer to a single, exclusive data structure (because that hardwires a "only a single security subsystem active" assumption), but should be a pointer to a linked list of security structures
- as many as there are security subsystems interested in that inode.
Thanks,
Ingo
Quoted 36 lines · Ingo Molnar
Quoted 28 lines · Casey Schaufler
Quoted 27 lines · Ingo Molnar
Quoted 11 lines · Eric Paris
Quoted 10 lines · Ingo Molnar
Quoted 8 lines · Eric Paris
Executive summary of the day's work:
Yesterday morning: 944 bytes per inode in core
Yesterday night: 24 bytes per inode in core
Tonight: 4 bytes per inode in core.That's a x236 time reduction in memory usage. No I didn't even start looking at a freezer. Which could bring that 4 down to 0, but would add a scalability penalty on all inodes when IMA was enabled.
Quoted 6 lines
Quoted 4 lines
Why not use
inode->i_securityintelligently? That already exists so that way it's 0 bytes.Thanks,
It still wouldn't be 0 bytes since there would be a 1-1 mapping from inode to
i_securitystructs. [...]Only for IMA-affected files, right?
My point is to keep it 0 overhead for the
_nonIMA commoncase_.Quoted 4 lines
The real reason I don't pursue this route is because of the litany of different ways this pointer is used in different LSMs (or not used at all.) And we all know that LSM authors aren't known for seeing the world the same way as each other. As a maintainer of one of those LSMs even I'm scared to try pushing that forward....
Quoted 6 lines
Quoted 1 line
Ugh. That's a perfect reason to do it exactly like i suggested.
If you would like to make a proposal on LSM stacking other than the traditional "rip the LSM out" I am sure that everyone in the IMA, SELinux, TOMOYO, AppArmor and Smack communities would be happy to have a look. Short of having a viable mechanism for multiple LSMs to coexist IMA needs its separate space. Yes, people do use both IMA and LSMs on the same machine at the same time.
Quoted 5 lines
Yes, that's the essence of what i suggested: if various security concepts can be present at once then
inode->securityshould not be a stupid pointer to a single, exclusive data structure (because that hardwires a "only a single security subsystem active" assumption), but should be a pointer to a linked list of security structures
- as many as there are security subsystems interested in that inode.
Glad to see support for an LSM module stacker (modulator, combiner, ...) growing. All we really need to do is get someone a case of the beverage of their choice and turn them loose on the problem. I think that the few anti-stacking holdouts (I was one, but converted a couple years ago) can be swayed by a reasonable implementation. It won't be easy, there are plenty of problems that need to be solved, but anyone who wants easy should stick to developing web portals and stay out of the kernel.
Quoted 4 lines
Thanks,
Ingo