| .. | .. |
|---|
| 980 | 980 | ret = -EACCES; |
|---|
| 981 | 981 | down_write(&key->sem); |
|---|
| 982 | 982 | |
|---|
| 983 | | - if (!capable(CAP_SYS_ADMIN)) { |
|---|
| 983 | + { |
|---|
| 984 | + bool is_privileged_op = false; |
|---|
| 985 | + |
|---|
| 984 | 986 | /* only the sysadmin can chown a key to some other UID */ |
|---|
| 985 | 987 | if (user != (uid_t) -1 && !uid_eq(key->uid, uid)) |
|---|
| 986 | | - goto error_put; |
|---|
| 988 | + is_privileged_op = true; |
|---|
| 987 | 989 | |
|---|
| 988 | 990 | /* only the sysadmin can set the key's GID to a group other |
|---|
| 989 | 991 | * than one of those that the current process subscribes to */ |
|---|
| 990 | 992 | if (group != (gid_t) -1 && !gid_eq(gid, key->gid) && !in_group_p(gid)) |
|---|
| 993 | + is_privileged_op = true; |
|---|
| 994 | + |
|---|
| 995 | + if (is_privileged_op && !capable(CAP_SYS_ADMIN)) |
|---|
| 991 | 996 | goto error_put; |
|---|
| 992 | 997 | } |
|---|
| 993 | 998 | |
|---|
| .. | .. |
|---|
| 1088 | 1093 | down_write(&key->sem); |
|---|
| 1089 | 1094 | |
|---|
| 1090 | 1095 | /* if we're not the sysadmin, we can only change a key that we own */ |
|---|
| 1091 | | - if (capable(CAP_SYS_ADMIN) || uid_eq(key->uid, current_fsuid())) { |
|---|
| 1096 | + if (uid_eq(key->uid, current_fsuid()) || capable(CAP_SYS_ADMIN)) { |
|---|
| 1092 | 1097 | key->perm = perm; |
|---|
| 1093 | 1098 | notify_key(key, NOTIFY_KEY_SETATTR, 0); |
|---|
| 1094 | 1099 | ret = 0; |
|---|