Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:security\keys\keyctl.c Create Date:2022-07-28 18:20:18
Last Modify:2020-03-18 07:59:52 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Change the ownership of a key* The key must grant the caller Setattr permission for this to work, though* the key need not be fully instantiated yet. For the UID to be changed, or* for the GID to be changed to a group the caller is not a member of, the

Proto:long keyctl_chown_key(key_serial_t id, uid_t user, gid_t group)

Type:long

Parameter:

TypeParameterName
key_serial_tid
uid_tuser
gid_tgroup
882  struct key_user * newowner, * zapowner = NULL
889  uid = make_kuid(current_user_ns(), user)
890  gid = make_kgid(current_user_ns(), group)
891  ret = -EINVAL
892  If ((user != (uid_t) - 1) && !uid_valid(uid)) Then Go to error
894  If ((group != (gid_t) - 1) && !gid_valid(gid)) Then Go to error
897  ret = 0
898  If (user == (uid_t) - 1 && group == (gid_t) - 1) Then Go to error
901  key_ref = Look up a key ID given us by userspace with a given permissions mask to get* the key it refers to.* Flags can be passed to request that special keyrings be created if referred* to directly, to permit partially constructed keys to be found and to skip
903  If IS_ERR(key_ref) Then
904  ret = PTR_ERR(key_ref)
905  Go to error
908  key = key_ref_to_ptr(key_ref)
911  ret = -EACCES
912  lock for writing
914  If Not Check operation authority Then
916  If (user != (uid_t) - 1 && !uid_eq(uid, uid)) Then Go to error_put
921  If (group != (gid_t) - 1 && !gid_eq(gid, gid) && !in_group_p(gid)) Then Go to error_put
926  If (user != (uid_t) - 1 && !uid_eq(uid, uid)) Then
927  ret = -ENOMEM
928  newowner = Get the key quota record for a user, allocating a new record if one doesn't* already exist.
929  If Not newowner Then Go to error_put
939  spin_lock( & lock)
948  spin_unlock( & lock)
950  spin_lock( & lock)
951  qnkeys--
953  spin_unlock( & lock)
956  atomic_dec( & nkeys)
957  atomic_inc( & umber of keys )
960  atomic_dec( & nikeys)
964  zapowner = owner of this key
965  owner of this key = newowner
966  uid = uid
970  If (group != (gid_t) - 1) Then gid = gid
973  ret = 0
975  error_put :
976  lease a write lock
977  key_put - Discard a reference to a key.*@key: The key to discard a reference from.* Discard a reference to a key, and when all the references are gone, we* schedule the cleanup task to come and pull it out of the tree in process
978  If zapowner Then Dispose of a user structure
980  error :
981  Return ret
983  quota_overrun :
984  spin_unlock( & lock)
985  zapowner = newowner
986  ret = -EDQUOT
987  Go to error_put
Caller
NameDescribe
SYSCALL_DEFINE5The key control system call
COMPAT_SYSCALL_DEFINE5The key control system call, 32-bit compatibility version for 64-bit archs