• Jan Kara's avatar
    audit: Embed key into chunk · 6ce317fd
    Jan Kara authored
    [ Upstream commit 8d20d6e9 ]
    
    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 prob...
    6ce317fd
audit_tree.c 23.6 KB