Skip to content
  • Simon McVittie's avatar
    userdb: Reference-count DBusUserInfo, DBusGroupInfo · dc94fe3d
    Simon McVittie authored
    Previously, the hash table indexed by uid (or gid) took ownership of the
    single reference to the heap-allocated struct, and the hash table
    indexed by username (or group name) had a borrowed pointer to the same
    struct that exists in the other hash table.
    
    However, this can break down if you have two or more distinct usernames
    that share a numeric identifier. This is generally a bad idea, because
    the user-space model in such situations does not match the kernel-space
    reality, and in particular there is no effective kernel-level security
    boundary between such users, but it is sometimes done anyway.
    
    In this case, when the second username is looked up in the userdb, it
    overwrites (replaces) the entry in the hash table that is indexed by
    uid, freeing the DBusUserInfo. This results in both the key and the
    value in the hash table that is indexed by username becoming dangling
    pointers (use-after-free), leading to undefined behaviour, which is
    certainly not what ...
    dc94fe3d