• Yang Xu's avatar
    KEYS: reaching the keys quotas correctly · 2e356101
    Yang Xu authored
    Currently, when we add a new user key, the calltrace as below:
    
    add_key()
      key_create_or_update()
        key_alloc()
        __key_instantiate_and_link
          generic_key_instantiate
            key_payload_reserve
              ......
    
    Since commit a08bf91c ("KEYS: allow reaching the keys quotas exactly"),
    we can reach max bytes/keys in key_alloc, but we forget to remove this
    limit when we reserver space for payload in key_payload_reserve. So we
    can only reach max keys but not max bytes when having delta between plen
    and type->def_datalen. Remove this limit when instantiating the key, so we
    can keep consistent with key_alloc.
    
    Also, fix the similar problem in keyctl_chown_key().
    
    Fixes: 0b77f5bf ("keys: make the keyring quotas controllable through /proc/sys")
    Fixes: a08bf91c ("KEYS: allow reaching the keys quotas exactly")
    Cc: stable@vger.kernel.org # 5.0.x
    Cc: Eric Biggers <ebiggers@google.com>
    Signed-off-by: default avatarYang Xu <xuyang2018.jy@cn.fujitsu.com>
    Reviewed-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
    Reviewed-by: default avatarEric Biggers <ebiggers@google.com>
    Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
    2e356101
key.c 31.1 KB