LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Richard Guy Briggs <rgb@redhat.com>
To: Paul Moore <pmoore@redhat.com>
Cc: linux-fsdevel@vger.kernel.org, linux-audit@redhat.com,
	sd@queasysnail.net, linux-kernel@vger.kernel.org,
	linux@roeck-us.net, viro@zeniv.linux.org.uk
Subject: Re: [PATCH v2 4/5] audit: fix filename matching in __audit_inode() and __audit_inode_child()
Date: Thu, 22 Jan 2015 11:04:05 -0500	[thread overview]
Message-ID: <20150122160405.GJ18752@madcap2.tricolour.ca> (raw)
In-Reply-To: <20150122050016.1347.17253.stgit@localhost>

On 15/01/22, Paul Moore wrote:
> In all likelihood there were some subtle, and perhaps not so subtle,
> bugs with filename matching in audit_inode() and audit_inode_child()
> for some time, however, recent changes to the audit filename code have
> definitely broken the filename matching code.  The breakage could
> result in duplicate filenames in the audit log and other odd audit
> record entries.  This patch fixes the filename matching code and
> restores some sanity to the filename audit records.
> 
> CC: viro@zeniv.linux.org.uk
> CC: linux-fsdevel@vger.kernel.org
> Signed-off-by: Paul Moore <pmoore@redhat.com>

Noted change to use the iterator instead of the reference in the inode check.

Reviewed-by: Richard Guy Briggs <rgb@redhat.com>

> ---
>  kernel/auditsc.c |   34 +++++++++++++++++++++++++---------
>  1 file changed, 25 insertions(+), 9 deletions(-)
> 
> diff --git a/kernel/auditsc.c b/kernel/auditsc.c
> index c967ffc..c54b5f0 100644
> --- a/kernel/auditsc.c
> +++ b/kernel/auditsc.c
> @@ -1846,6 +1846,7 @@ void __audit_inode(struct filename *name, const struct dentry *dentry,
>  	/* The struct filename _must_ have a populated ->name */
>  	BUG_ON(!name->name);
>  #endif
> +
>  	/*
>  	 * If we have a pointer to an audit_names entry already, then we can
>  	 * just use it directly if the type is correct.
> @@ -1863,7 +1864,17 @@ void __audit_inode(struct filename *name, const struct dentry *dentry,
>  	}
>  
>  	list_for_each_entry_reverse(n, &context->names_list, list) {
> -		if (!n->name || strcmp(n->name->name, name->name))
> +		if (n->ino) {
> +			/* valid inode number, use that for the comparison */
> +			if (n->ino != inode->i_ino ||
> +			    n->dev != inode->i_sb->s_dev)
> +				continue;
> +		} else if (n->name) {
> +			/* inode number has not been set, check the name */
> +			if (strcmp(n->name->name, name->name))
> +				continue;
> +		} else
> +			/* no inode and no name (?!) ... this is odd ... */
>  			continue;
>  
>  		/* match the correct record type */
> @@ -1931,11 +1942,16 @@ void __audit_inode_child(const struct inode *parent,
>  
>  	/* look for a parent entry first */
>  	list_for_each_entry(n, &context->names_list, list) {
> -		if (!n->name || n->type != AUDIT_TYPE_PARENT)
> +		if (!n->name ||
> +		    (n->type != AUDIT_TYPE_PARENT &&
> +		     n->type != AUDIT_TYPE_UNKNOWN))
>  			continue;
>  
> -		if (n->ino == parent->i_ino &&
> -		    !audit_compare_dname_path(dname, n->name->name, n->name_len)) {
> +		if (n->ino == parent->i_ino && n->dev == parent->i_sb->s_dev &&
> +		    !audit_compare_dname_path(dname,
> +					      n->name->name, n->name_len)) {
> +			if (n->type == AUDIT_TYPE_UNKNOWN)
> +				n->type = AUDIT_TYPE_PARENT;
>  			found_parent = n;
>  			break;
>  		}
> @@ -1944,11 +1960,8 @@ void __audit_inode_child(const struct inode *parent,
>  	/* is there a matching child entry? */
>  	list_for_each_entry(n, &context->names_list, list) {
>  		/* can only match entries that have a name */
> -		if (!n->name || n->type != type)
> -			continue;
> -
> -		/* if we found a parent, make sure this one is a child of it */
> -		if (found_parent && (n->name != found_parent->name))
> +		if (!n->name ||
> +		    (n->type != type && n->type != AUDIT_TYPE_UNKNOWN))
>  			continue;
>  
>  		if (!strcmp(dname, n->name->name) ||
> @@ -1956,6 +1969,8 @@ void __audit_inode_child(const struct inode *parent,
>  						found_parent ?
>  						found_parent->name_len :
>  						AUDIT_NAME_FULL)) {
> +			if (n->type == AUDIT_TYPE_UNKNOWN)
> +				n->type = type;
>  			found_child = n;
>  			break;
>  		}
> @@ -1984,6 +1999,7 @@ void __audit_inode_child(const struct inode *parent,
>  			found_child->name_put = false;
>  		}
>  	}
> +
>  	if (inode)
>  		audit_copy_inode(found_child, dentry, inode);
>  	else
> 

- RGB

--
Richard Guy Briggs <rbriggs@redhat.com>
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

  reply	other threads:[~2015-01-22 16:04 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-22  4:59 [PATCH v2 0/5] Overhaul the audit filename handling Paul Moore
2015-01-22  4:59 ` [PATCH v2 1/5] fs: rework getname_kernel to handle up to PATH_MAX sized filenames Paul Moore
2015-01-22 15:53   ` Richard Guy Briggs
2015-01-22 16:56     ` Guenter Roeck
2015-01-22  5:00 ` [PATCH v2 2/5] fs: create proper filename objects using getname_kernel() Paul Moore
2015-01-22 15:54   ` Richard Guy Briggs
2015-01-22  5:00 ` [PATCH v2 3/5] audit: enable filename recording via getname_kernel() Paul Moore
2015-01-22  5:00 ` [PATCH v2 4/5] audit: fix filename matching in __audit_inode() and __audit_inode_child() Paul Moore
2015-01-22 16:04   ` Richard Guy Briggs [this message]
2015-01-22  5:00 ` [PATCH v2 5/5] audit: replace getname()/putname() hacks with reference counters Paul Moore
2015-01-22 16:09   ` Richard Guy Briggs
2015-01-22 16:24     ` Paul Moore
2015-01-22  5:36 ` [PATCH v2 0/5] Overhaul the audit filename handling Guenter Roeck
2015-01-22  7:54   ` Al Viro
2015-01-22 16:23     ` Paul Moore
2015-01-22 21:25       ` Paul Moore
2015-01-22 21:29         ` Al Viro
2015-01-22 21:40           ` Al Viro
2015-01-22 22:05             ` Paul Moore
2015-01-23  5:30             ` Al Viro
2015-01-23 16:15               ` Paul Moore
2015-01-24  9:03               ` Sedat Dilek
2015-01-24 22:54                 ` Stephen Rothwell
2015-01-26 15:52                 ` Paul Moore
2015-01-22 17:13     ` Guenter Roeck
2015-01-22 16:22   ` Paul Moore
2015-01-22 16:58     ` Guenter Roeck

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=20150122160405.GJ18752@madcap2.tricolour.ca \
    --to=rgb@redhat.com \
    --cc=linux-audit@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=pmoore@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [PATCH v2 4/5] audit: fix filename matching in __audit_inode() and __audit_inode_child()' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).