Skip to content

Commit

Permalink
KEYS: Call ->free_preparse() even after ->preparse() returns an error
Browse files Browse the repository at this point in the history
Call the ->free_preparse() key type op even after ->preparse() returns an
error as it does cleaning up type stuff.

Signed-off-by: David Howells <[email protected]>
Acked-by: Steve Dickson <[email protected]>
Acked-by: Jeff Layton <[email protected]>
Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
dhowells committed Jul 22, 2014
1 parent 7dfa0ca commit 4d8c025
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Documentation/security/keys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,9 @@ The structure has a number of fields, some of which are mandatory:
This method is only required if the preparse() method is provided,
otherwise it is unused. It cleans up anything attached to the
description, type_data and payload fields of the key_preparsed_payload
struct as filled in by the preparse() method.
struct as filled in by the preparse() method. It will always be called
after preparse() returns successfully, even if instantiate() or update()
succeed.


(*) int (*instantiate)(struct key *key, struct key_preparsed_payload *prep);
Expand Down
9 changes: 4 additions & 5 deletions security/keys/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,17 @@ int key_instantiate_and_link(struct key *key,
if (keyring) {
ret = __key_link_begin(keyring, &key->index_key, &edit);
if (ret < 0)
goto error_free_preparse;
goto error;
}

ret = __key_instantiate_and_link(key, &prep, keyring, authkey, &edit);

if (keyring)
__key_link_end(keyring, &key->index_key, edit);

error_free_preparse:
error:
if (key->type->preparse)
key->type->free_preparse(&prep);
error:
return ret;
}

Expand Down Expand Up @@ -822,7 +821,7 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
ret = index_key.type->preparse(&prep);
if (ret < 0) {
key_ref = ERR_PTR(ret);
goto error_put_type;
goto error_free_prep;
}
if (!index_key.description)
index_key.description = prep.description;
Expand Down Expand Up @@ -964,9 +963,9 @@ int key_update(key_ref_t key_ref, const void *payload, size_t plen)

up_write(&key->sem);

error:
if (key->type->preparse)
key->type->free_preparse(&prep);
error:
return ret;
}
EXPORT_SYMBOL(key_update);
Expand Down

0 comments on commit 4d8c025

Please sign in to comment.