From: Amir Goldstein <amir73il@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Linux Audit <linux-audit@redhat.com>,
Paul Moore <paul@paul-moore.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Richard Guy Briggs <rgb@redhat.com>
Subject: Re: [PATCH 4/6] audit: Embed key into chunk
Date: Fri, 29 Jun 2018 15:53:20 +0300 [thread overview]
Message-ID: <CAOQ4uxgnjUu43bFpu0iVxx854yfjPt+7QMxYLpVO-oBfV9ehJQ@mail.gmail.com> (raw)
In-Reply-To: <20180628164014.4925-5-jack@suse.cz>
On Thu, Jun 28, 2018 at 7:40 PM, Jan Kara <jack@suse.cz> wrote:
> Currently chunk hash key (which is in fact pointer to the inode) is
> derived as chunk->mark.conn->obj. It is tricky to make this dereference
> reliable for hash table lookups only under RCU as mark can get detached
> from the connector and connector gets freed independently of the
> running lookup. Thus there is a possible use after free / NULL ptr
> dereference issue:
>
> CPU1 CPU2
> untag_chunk()
> ...
> audit_tree_lookup()
> list_for_each_entry_rcu(p, list, hash) {
> list_del_rcu(&chunk->hash);
> fsnotify_destroy_mark(entry);
> fsnotify_put_mark(entry)
> chunk_to_key(p)
> if (!chunk->mark.connector)
> ...
> hlist_del_init_rcu(&mark->obj_list);
> if (hlist_empty(&conn->list)) {
> inode = fsnotify_detach_connector_from_object(conn);
> mark->connector = NULL;
> ...
> frees connector from workqueue
> chunk->mark.connector->obj
>
> This race is probably impossible to hit in practice as the race window
> on CPU1 is very narrow and CPU2 has a lot of code to execute. Still it's
> better to have this fixed. Since the inode the chunk is attached to is
> constant during chunk's lifetime it is easy to cache the key in the
> chunk itself and thus avoid these issues.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
> kernel/audit_tree.c | 26 +++++++-------------------
> 1 file changed, 7 insertions(+), 19 deletions(-)
>
> diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
> index 7f9df8c66227..89ad8857a578 100644
> --- a/kernel/audit_tree.c
> +++ b/kernel/audit_tree.c
> @@ -24,6 +24,7 @@ struct audit_tree {
>
> struct audit_chunk {
> struct list_head hash;
> + unsigned long key;
> struct fsnotify_mark mark;
> struct list_head trees; /* with root here */
> int dead;
> @@ -172,21 +173,6 @@ static unsigned long inode_to_key(const struct inode *inode)
> return (unsigned long)&inode->i_fsnotify_marks;
> }
>
> -/*
> - * Function to return search key in our hash from chunk. Key 0 is special and
> - * should never be present in the hash.
> - */
> -static unsigned long chunk_to_key(struct audit_chunk *chunk)
> -{
> - /*
> - * We have a reference to the mark so it should be attached to a
> - * connector.
> - */
> - if (WARN_ON_ONCE(!chunk->mark.connector))
> - return 0;
> - return (unsigned long)chunk->mark.connector->obj;
> -}
> -
> static inline struct list_head *chunk_hash(unsigned long key)
> {
> unsigned long n = key / L1_CACHE_BYTES;
> @@ -196,12 +182,11 @@ static inline struct list_head *chunk_hash(unsigned long key)
> /* hash_lock & entry->group->mark_mutex is held by caller */
> static void insert_hash(struct audit_chunk *chunk)
> {
> - unsigned long key = chunk_to_key(chunk);
> struct list_head *list;
>
Suggest to add check (WARN_ON_ONCE(!chunk->key))
because its quite hard to assert by code review alone that no execution
path was missed where chunk->key should have been set.
Thanks,
Amir.
next prev parent reply other threads:[~2018-06-29 12:53 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-28 16:40 [PATCH 0/6] audit: Fix various races when tagging and untagging mounts Jan Kara
2018-06-28 16:40 ` [PATCH 1/6] audit_tree: Replace mark->lock locking Jan Kara
2018-06-29 11:31 ` Amir Goldstein
2018-07-03 14:07 ` Jan Kara
2018-06-28 16:40 ` [PATCH 2/6] audit: Fix possible spurious -ENOSPC error Jan Kara
2018-06-29 11:42 ` Amir Goldstein
2018-07-02 6:05 ` Dan Carpenter
2018-07-03 14:18 ` Jan Kara
2018-06-28 16:40 ` [PATCH 3/6] audit: Fix possible tagging failures Jan Kara
2018-06-29 12:05 ` Amir Goldstein
2018-07-03 14:21 ` Jan Kara
2018-07-03 17:42 ` Amir Goldstein
2018-07-04 8:28 ` Jan Kara
2018-06-28 16:40 ` [PATCH 4/6] audit: Embed key into chunk Jan Kara
2018-06-29 12:53 ` Amir Goldstein [this message]
2018-07-03 14:25 ` Jan Kara
2018-06-28 16:40 ` [PATCH 5/6] audit: Make hash table insertion safe against concurrent lookups Jan Kara
2018-06-29 13:02 ` Amir Goldstein
2018-07-03 15:31 ` Jan Kara
2018-06-28 16:40 ` [PATCH 6/6] audit: Point to fsnotify mark instead of embedding it Jan Kara
2018-06-29 13:20 ` Amir Goldstein
2018-07-04 12:34 ` Jan Kara
2018-06-29 11:44 ` [PATCH 0/6] audit: Fix various races when tagging and untagging mounts Amir Goldstein
2018-06-29 18:01 ` Paul Moore
2018-07-03 14:14 ` Jan Kara
2018-07-03 17:03 ` Paul Moore
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=CAOQ4uxgnjUu43bFpu0iVxx854yfjPt+7QMxYLpVO-oBfV9ehJQ@mail.gmail.com \
--to=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=linux-audit@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=rgb@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).