diff options
Diffstat (limited to 'security/keys/process_keys.c')
| -rw-r--r-- | security/keys/process_keys.c | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c index b6fdd22205b1..9139b18fc863 100644 --- a/security/keys/process_keys.c +++ b/security/keys/process_keys.c | |||
| @@ -128,13 +128,18 @@ error: | |||
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | /* | 130 | /* |
| 131 | * Install a fresh thread keyring directly to new credentials. This keyring is | 131 | * Install a thread keyring to the given credentials struct if it didn't have |
| 132 | * allowed to overrun the quota. | 132 | * one already. This is allowed to overrun the quota. |
| 133 | * | ||
| 134 | * Return: 0 if a thread keyring is now present; -errno on failure. | ||
| 133 | */ | 135 | */ |
| 134 | int install_thread_keyring_to_cred(struct cred *new) | 136 | int install_thread_keyring_to_cred(struct cred *new) |
| 135 | { | 137 | { |
| 136 | struct key *keyring; | 138 | struct key *keyring; |
| 137 | 139 | ||
| 140 | if (new->thread_keyring) | ||
| 141 | return 0; | ||
| 142 | |||
| 138 | keyring = keyring_alloc("_tid", new->uid, new->gid, new, | 143 | keyring = keyring_alloc("_tid", new->uid, new->gid, new, |
| 139 | KEY_POS_ALL | KEY_USR_VIEW, | 144 | KEY_POS_ALL | KEY_USR_VIEW, |
| 140 | KEY_ALLOC_QUOTA_OVERRUN, | 145 | KEY_ALLOC_QUOTA_OVERRUN, |
| @@ -147,7 +152,9 @@ int install_thread_keyring_to_cred(struct cred *new) | |||
| 147 | } | 152 | } |
| 148 | 153 | ||
| 149 | /* | 154 | /* |
| 150 | * Install a fresh thread keyring, discarding the old one. | 155 | * Install a thread keyring to the current task if it didn't have one already. |
| 156 | * | ||
| 157 | * Return: 0 if a thread keyring is now present; -errno on failure. | ||
| 151 | */ | 158 | */ |
| 152 | static int install_thread_keyring(void) | 159 | static int install_thread_keyring(void) |
| 153 | { | 160 | { |
| @@ -158,8 +165,6 @@ static int install_thread_keyring(void) | |||
| 158 | if (!new) | 165 | if (!new) |
| 159 | return -ENOMEM; | 166 | return -ENOMEM; |
| 160 | 167 | ||
| 161 | BUG_ON(new->thread_keyring); | ||
| 162 | |||
| 163 | ret = install_thread_keyring_to_cred(new); | 168 | ret = install_thread_keyring_to_cred(new); |
| 164 | if (ret < 0) { | 169 | if (ret < 0) { |
| 165 | abort_creds(new); | 170 | abort_creds(new); |
| @@ -170,17 +175,17 @@ static int install_thread_keyring(void) | |||
| 170 | } | 175 | } |
| 171 | 176 | ||
| 172 | /* | 177 | /* |
| 173 | * Install a process keyring directly to a credentials struct. | 178 | * Install a process keyring to the given credentials struct if it didn't have |
| 179 | * one already. This is allowed to overrun the quota. | ||
| 174 | * | 180 | * |
| 175 | * Returns -EEXIST if there was already a process keyring, 0 if one installed, | 181 | * Return: 0 if a process keyring is now present; -errno on failure. |
| 176 | * and other value on any other error | ||
| 177 | */ | 182 | */ |
| 178 | int install_process_keyring_to_cred(struct cred *new) | 183 | int install_process_keyring_to_cred(struct cred *new) |
| 179 | { | 184 | { |
| 180 | struct key *keyring; | 185 | struct key *keyring; |
| 181 | 186 | ||
| 182 | if (new->process_keyring) | 187 | if (new->process_keyring) |
| 183 | return -EEXIST; | 188 | return 0; |
| 184 | 189 | ||
| 185 | keyring = keyring_alloc("_pid", new->uid, new->gid, new, | 190 | keyring = keyring_alloc("_pid", new->uid, new->gid, new, |
| 186 | KEY_POS_ALL | KEY_USR_VIEW, | 191 | KEY_POS_ALL | KEY_USR_VIEW, |
| @@ -194,11 +199,9 @@ int install_process_keyring_to_cred(struct cred *new) | |||
| 194 | } | 199 | } |
| 195 | 200 | ||
| 196 | /* | 201 | /* |
| 197 | * Make sure a process keyring is installed for the current process. The | 202 | * Install a process keyring to the current task if it didn't have one already. |
| 198 | * existing process keyring is not replaced. | ||
| 199 | * | 203 | * |
| 200 | * Returns 0 if there is a process keyring by the end of this function, some | 204 | * Return: 0 if a process keyring is now present; -errno on failure. |
| 201 | * error otherwise. | ||
| 202 | */ | 205 | */ |
| 203 | static int install_process_keyring(void) | 206 | static int install_process_keyring(void) |
| 204 | { | 207 | { |
| @@ -212,14 +215,18 @@ static int install_process_keyring(void) | |||
| 212 | ret = install_process_keyring_to_cred(new); | 215 | ret = install_process_keyring_to_cred(new); |
| 213 | if (ret < 0) { | 216 | if (ret < 0) { |
| 214 | abort_creds(new); | 217 | abort_creds(new); |
| 215 | return ret != -EEXIST ? ret : 0; | 218 | return ret; |
| 216 | } | 219 | } |
| 217 | 220 | ||
| 218 | return commit_creds(new); | 221 | return commit_creds(new); |
| 219 | } | 222 | } |
| 220 | 223 | ||
| 221 | /* | 224 | /* |
| 222 | * Install a session keyring directly to a credentials struct. | 225 | * Install the given keyring as the session keyring of the given credentials |
| 226 | * struct, replacing the existing one if any. If the given keyring is NULL, | ||
| 227 | * then install a new anonymous session keyring. | ||
| 228 | * | ||
| 229 | * Return: 0 on success; -errno on failure. | ||
| 223 | */ | 230 | */ |
| 224 | int install_session_keyring_to_cred(struct cred *cred, struct key *keyring) | 231 | int install_session_keyring_to_cred(struct cred *cred, struct key *keyring) |
| 225 | { | 232 | { |
| @@ -254,8 +261,11 @@ int install_session_keyring_to_cred(struct cred *cred, struct key *keyring) | |||
| 254 | } | 261 | } |
| 255 | 262 | ||
| 256 | /* | 263 | /* |
| 257 | * Install a session keyring, discarding the old one. If a keyring is not | 264 | * Install the given keyring as the session keyring of the current task, |
| 258 | * supplied, an empty one is invented. | 265 | * replacing the existing one if any. If the given keyring is NULL, then |
| 266 | * install a new anonymous session keyring. | ||
| 267 | * | ||
| 268 | * Return: 0 on success; -errno on failure. | ||
| 259 | */ | 269 | */ |
| 260 | static int install_session_keyring(struct key *keyring) | 270 | static int install_session_keyring(struct key *keyring) |
| 261 | { | 271 | { |
