KEYS: fix cred refcount leak in request_key_auth_new()
authorEric Biggers <ebiggers@google.com>
Thu, 21 Sep 2017 20:57:40 +0000 (13:57 -0700)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 1 Jan 2018 20:50:51 +0000 (20:50 +0000)
commit3b9c8a06857e48471028f8446176ff8664911626
treef0d2bad22719c531024d16e18ace0e0e401aa3e7
parentc1f10c6b89f3b32eb701395e64244d1c872ae586
KEYS: fix cred refcount leak in request_key_auth_new()

commit 44d8143340a99b167c74365e844516b73523c087 upstream.

In request_key_auth_new(), if key_alloc() or key_instantiate_and_link()
were to fail, we would leak a reference to the 'struct cred'.  Currently
this can only happen if key_alloc() fails to allocate memory.  But it
still should be fixed, as it is a more severe bug waiting to happen.

Fix it by cleaning things up to use a helper function which frees a
'struct request_key_auth' correctly.

Fixes: d84f4f992cbd ("CRED: Inaugurate COW credentials")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
security/keys/request_key_auth.c