• Zbigniew Jędrzejewski-Szmek's avatar
    Check gid and uid initalization in PolkitUnixUser and Group objects · fbaab32c
    Zbigniew Jędrzejewski-Szmek authored
    When a user or group above INT32_MAX is created, the numeric uid or
    gid wraps around to negative when the value is assigned to gint, and
    polkit gets confused. Let's refuse such uids and gids.
    
    This patch just refuses to initialize uid and gid values to negative.
    A nicer fix is to change the underlying type to e.g. gint64 to allow
    the full range of values in uid_t and gid_t to be represented. But
    this cannot be done without breaking the API, so likely new functions
    will have to be added (a polkit_unix_user_new variant that takes a
    gint64, and the same for _group_new, _set_uid, _get_uid, _set_gid,
    _get_gid, etc.). This will require a bigger patch.
    
    Fixes polkit/polkit#74.
    
    Example sessions from uid=4000000000:
    
    Dec 03 14:35:08 krowka polkitd[21432]: system-bus-name::1.41869 is inquiring whether system-bus-name::1.79432 is authorized for org.freedesktop.systemd1.manage-units
    Dec 03 14:35:08 krowka polkitd[21432]:  user of caller is unix-user:root
    Dec 03 14:35:08 krowka polkitd[21432]: polkit_unix_user_new: assertion 'uid >= 0' failed
    Dec 03 14:35:08 krowka polkitd[21432]: polkit_identity_to_string: assertion 'POLKIT_IS_IDENTITY (identity)' failed
    Dec 03 14:35:08 krowka polkitd[21432]:  user of subject is (null)
    Dec 03 14:35:08 krowka polkitd[21432]: polkit_identity_equal: assertion 'POLKIT_IS_IDENTITY (b)' failed
    Dec 03 14:35:08 krowka polkitd[21432]: checking whether system-bus-name::1.79432 is authorized for org.freedesktop.systemd1.manage-units
    Dec 03 14:35:08 krowka polkitd[21432]: polkit_unix_user_new: assertion 'uid >= 0' failed
    Dec 03 14:35:08 krowka polkitd[21432]:
    Dec 03 14:35:08 krowka polkitd[21432]: polkit_authorization_result_get_is_challenge: assertion 'POLKIT_IS_AUTHORIZATION_RESULT (result)' failed
    Dec 03 14:35:08 krowka polkitd[21432]: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
    Dec 03 14:35:08 krowka polkitd[21432]: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
    Dec 03 14:35:08 krowka polkitd[21432]: polkit_authorization_result_get_details: assertion 'POLKIT_IS_AUTHORIZATION_RESULT (result)' failed
    Dec 03 14:35:08 krowka polkitd[21432]: polkit_authorization_result_get_is_challenge: assertion 'POLKIT_IS_AUTHORIZATION_RESULT (result)' failed
    Dec 03 14:35:08 krowka polkitd[21432]: polkit_authorization_result_get_is_authorized: assertion 'POLKIT_IS_AUTHORIZATION_RESULT (result)' failed
    Dec 03 14:35:08 krowka polkitd[21432]: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
    Dec 03 14:35:08 krowka polkitd[21432]: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
    fbaab32c
polkitunixgroup.c 6.99 KB