2014-11-04 10:27:26

by Miklos Szeredi

[permalink] [raw]
Subject: [PATCH] audit_tree: keep inode pinned

From: Miklos Szeredi <[email protected]>

Audit rules disappear when an inode they watch is evicted from the cache.
This is likely not what we want.

The guilty commit is "fsnotify: allow marks to not pin inodes in core",
which didn't take into account that audit_tree adds watches with a zero
mask.

Adding any mask should fix this.

Fixes: 90b1e7a57880 ("fsnotify: allow marks to not pin inodes in core")
Signed-off-by: Miklos Szeredi <[email protected]>
Cc: [email protected] # 2.6.36+
---
kernel/audit_tree.c | 1 +
1 file changed, 1 insertion(+)

--- a/kernel/audit_tree.c
+++ b/kernel/audit_tree.c
@@ -154,6 +154,7 @@ static struct audit_chunk *alloc_chunk(i
chunk->owners[i].index = i;
}
fsnotify_init_mark(&chunk->mark, audit_tree_destroy_watch);
+ chunk->mark.mask = FS_IN_IGNORED;
return chunk;
}


2014-11-04 15:17:14

by Eric Paris

[permalink] [raw]
Subject: Re: [PATCH] audit_tree: keep inode pinned

[adding paul and richard]

On Tue, 2014-11-04 at 11:27 +0100, Miklos Szeredi wrote:
> From: Miklos Szeredi <[email protected]>
>
> Audit rules disappear when an inode they watch is evicted from the cache.
> This is likely not what we want.
>
> The guilty commit is "fsnotify: allow marks to not pin inodes in core",
> which didn't take into account that audit_tree adds watches with a zero
> mask.
>
> Adding any mask should fix this.
>
> Fixes: 90b1e7a57880 ("fsnotify: allow marks to not pin inodes in core")
> Signed-off-by: Miklos Szeredi <[email protected]>
> Cc: [email protected] # 2.6.36+
> ---
> kernel/audit_tree.c | 1 +
> 1 file changed, 1 insertion(+)
>
> --- a/kernel/audit_tree.c
> +++ b/kernel/audit_tree.c
> @@ -154,6 +154,7 @@ static struct audit_chunk *alloc_chunk(i
> chunk->owners[i].index = i;
> }
> fsnotify_init_mark(&chunk->mark, audit_tree_destroy_watch);
> + chunk->mark.mask = FS_IN_IGNORED;
> return chunk;
> }
>

2014-11-05 16:58:39

by Richard Guy Briggs

[permalink] [raw]
Subject: Re: [PATCH] audit_tree: keep inode pinned

On 14/11/04, Miklos Szeredi wrote:
> From: Miklos Szeredi <[email protected]>

Hi Miklos,

> Audit rules disappear when an inode they watch is evicted from the cache.
> This is likely not what we want.
>
> The guilty commit is "fsnotify: allow marks to not pin inodes in core",
> which didn't take into account that audit_tree adds watches with a zero
> mask.
>
> Adding any mask should fix this.

Nice find! Do you have a quick reproducer to detect this?

> Fixes: 90b1e7a57880 ("fsnotify: allow marks to not pin inodes in core")
> Signed-off-by: Miklos Szeredi <[email protected]>
> Cc: [email protected] # 2.6.36+
> ---
> kernel/audit_tree.c | 1 +
> 1 file changed, 1 insertion(+)
>
> --- a/kernel/audit_tree.c
> +++ b/kernel/audit_tree.c
> @@ -154,6 +154,7 @@ static struct audit_chunk *alloc_chunk(i
> chunk->owners[i].index = i;
> }
> fsnotify_init_mark(&chunk->mark, audit_tree_destroy_watch);
> + chunk->mark.mask = FS_IN_IGNORED;
> return chunk;
> }
>

- RGB

--
Richard Guy Briggs <[email protected]>
Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat
Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545

2014-11-05 19:36:50

by Miklos Szeredi

[permalink] [raw]
Subject: Re: [PATCH] audit_tree: keep inode pinned

On Wed, Nov 5, 2014 at 5:58 PM, Richard Guy Briggs <[email protected]> wrote:
> On 14/11/04, Miklos Szeredi wrote:
>> From: Miklos Szeredi <[email protected]>
>
> Hi Miklos,
>
>> Audit rules disappear when an inode they watch is evicted from the cache.
>> This is likely not what we want.
>>
>> The guilty commit is "fsnotify: allow marks to not pin inodes in core",
>> which didn't take into account that audit_tree adds watches with a zero
>> mask.
>>
>> Adding any mask should fix this.
>
> Nice find! Do you have a quick reproducer to detect this?


- reboot
- add tree rule
- echo 2 > /proc/sys/vm/drop_caches

drop_caches doesn't guarantee dropping the inode from the cache, but
after a reboot it usually does.

Thanks,
Miklos

2014-11-11 19:48:03

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH] audit_tree: keep inode pinned

On Tue, Nov 4, 2014 at 5:27 AM, Miklos Szeredi <[email protected]> wrote:
> From: Miklos Szeredi <[email protected]>
>
> Audit rules disappear when an inode they watch is evicted from the cache.
> This is likely not what we want.
>
> The guilty commit is "fsnotify: allow marks to not pin inodes in core",
> which didn't take into account that audit_tree adds watches with a zero
> mask.
>
> Adding any mask should fix this.
>
> Fixes: 90b1e7a57880 ("fsnotify: allow marks to not pin inodes in core")
> Signed-off-by: Miklos Szeredi <[email protected]>
> Cc: [email protected] # 2.6.36+
> ---
> kernel/audit_tree.c | 1 +
> 1 file changed, 1 insertion(+)

Thanks for your help on this, I've merged this into the audit
stable-3.18 branch; I plan on pushing this to Linus later this week.

* git://git.infradead.org/users/pcmoore/audit stable-3.18

> --- a/kernel/audit_tree.c
> +++ b/kernel/audit_tree.c
> @@ -154,6 +154,7 @@ static struct audit_chunk *alloc_chunk(i
> chunk->owners[i].index = i;
> }
> fsnotify_init_mark(&chunk->mark, audit_tree_destroy_watch);
> + chunk->mark.mask = FS_IN_IGNORED;
> return chunk;
> }

--
paul moore
http://www.paul-moore.com

2014-11-12 17:30:13

by Richard Guy Briggs

[permalink] [raw]
Subject: Re: [PATCH] audit_tree: keep inode pinned

On 14/11/05, Miklos Szeredi wrote:
> On Wed, Nov 5, 2014 at 5:58 PM, Richard Guy Briggs <[email protected]> wrote:
> > On 14/11/04, Miklos Szeredi wrote:
> >> From: Miklos Szeredi <[email protected]>
> >
> > Hi Miklos,
> >
> >> Audit rules disappear when an inode they watch is evicted from the cache.
> >> This is likely not what we want.
> >>
> >> The guilty commit is "fsnotify: allow marks to not pin inodes in core",
> >> which didn't take into account that audit_tree adds watches with a zero
> >> mask.
> >>
> >> Adding any mask should fix this.
> >
> > Nice find! Do you have a quick reproducer to detect this?
>
> - reboot
> - add tree rule
> - echo 2 > /proc/sys/vm/drop_caches
>
> drop_caches doesn't guarantee dropping the inode from the cache, but
> after a reboot it usually does.

Perfect, thanks! That works as expected. While I was at it, I checked
the audit_watch code and the pending "filter on process name" patches to
make sure they didn't have the same problem.

> Thanks,
> Miklos

- RGB

--
Richard Guy Briggs <[email protected]>
Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat
Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545