From: "Serge E. Hallyn" <serge@hallyn.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Sumit Garg <sumit.garg@linaro.org>,
James Bottomley <jejb@linux.ibm.com>,
Jarkko Sakkinen <jarkko@kernel.org>,
Mimi Zohar <zohar@linux.ibm.com>,
David Howells <dhowells@redhat.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
linux-integrity@vger.kernel.org, keyrings@vger.kernel.org,
linux-security-module@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] KEYS: trusted: fix a couple error pointer dereferences
Date: Wed, 14 Apr 2021 09:07:34 -0500 [thread overview]
Message-ID: <20210414140734.GB11180@mail.hallyn.com> (raw)
In-Reply-To: <YHaG+p5nlOXQFp1n@mwanda>
On Wed, Apr 14, 2021 at 09:08:58AM +0300, Dan Carpenter wrote:
> If registering "reg_shm_out" fails, then it is an error pointer and the
> error handling will call tee_shm_free(reg_shm_out) which leads to an
> error pointer dereference and an Oops.
>
> I've re-arranged it so we only free things that have been allocated
> successfully.
>
> Fixes: 6dd95e650c8a ("KEYS: trusted: Introduce TEE based Trusted Keys")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> security/keys/trusted-keys/trusted_tee.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
>
> diff --git a/security/keys/trusted-keys/trusted_tee.c b/security/keys/trusted-keys/trusted_tee.c
> index 2ce66c199e1d..45f96f6ed673 100644
> --- a/security/keys/trusted-keys/trusted_tee.c
> +++ b/security/keys/trusted-keys/trusted_tee.c
> @@ -65,7 +65,7 @@ static int trusted_tee_seal(struct trusted_key_payload *p, char *datablob)
> int ret;
> struct tee_ioctl_invoke_arg inv_arg;
> struct tee_param param[4];
> - struct tee_shm *reg_shm_in = NULL, *reg_shm_out = NULL;
> + struct tee_shm *reg_shm_in, *reg_shm_out;
I don't have this file (trusted_tee.c) in my tree and there's no lore
link here to previous what threads this depends on. Based on the
context I can't verify that reg_shm_in will always be initialized
before you get to the free_shm_in label.
>
> memset(&inv_arg, 0, sizeof(inv_arg));
> memset(¶m, 0, sizeof(param));
> @@ -84,7 +84,7 @@ static int trusted_tee_seal(struct trusted_key_payload *p, char *datablob)
> if (IS_ERR(reg_shm_out)) {
> dev_err(pvt_data.dev, "blob shm register failed\n");
> ret = PTR_ERR(reg_shm_out);
> - goto out;
> + goto free_shm_in;
> }
>
> inv_arg.func = TA_CMD_SEAL;
> @@ -109,11 +109,9 @@ static int trusted_tee_seal(struct trusted_key_payload *p, char *datablob)
> p->blob_len = param[1].u.memref.size;
> }
>
> -out:
> - if (reg_shm_out)
> - tee_shm_free(reg_shm_out);
> - if (reg_shm_in)
> - tee_shm_free(reg_shm_in);
> + tee_shm_free(reg_shm_out);
> +free_shm_in:
> + tee_shm_free(reg_shm_in);
>
> return ret;
> }
> @@ -126,7 +124,7 @@ static int trusted_tee_unseal(struct trusted_key_payload *p, char *datablob)
> int ret;
> struct tee_ioctl_invoke_arg inv_arg;
> struct tee_param param[4];
> - struct tee_shm *reg_shm_in = NULL, *reg_shm_out = NULL;
> + struct tee_shm *reg_shm_in, *reg_shm_out;
>
> memset(&inv_arg, 0, sizeof(inv_arg));
> memset(¶m, 0, sizeof(param));
> @@ -145,7 +143,7 @@ static int trusted_tee_unseal(struct trusted_key_payload *p, char *datablob)
> if (IS_ERR(reg_shm_out)) {
> dev_err(pvt_data.dev, "key shm register failed\n");
> ret = PTR_ERR(reg_shm_out);
> - goto out;
> + goto free_shm_in;
> }
>
> inv_arg.func = TA_CMD_UNSEAL;
> @@ -170,11 +168,9 @@ static int trusted_tee_unseal(struct trusted_key_payload *p, char *datablob)
> p->key_len = param[1].u.memref.size;
> }
>
> -out:
> - if (reg_shm_out)
> - tee_shm_free(reg_shm_out);
> - if (reg_shm_in)
> - tee_shm_free(reg_shm_in);
> + tee_shm_free(reg_shm_out);
> +free_shm_in:
> + tee_shm_free(reg_shm_in);
>
> return ret;
> }
> --
> 2.30.2
next prev parent reply other threads:[~2021-04-14 14:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-14 6:08 [PATCH] KEYS: trusted: fix a couple error pointer dereferences Dan Carpenter
2021-04-14 14:07 ` Serge E. Hallyn [this message]
2021-04-16 12:45 ` Sumit Garg
2021-04-16 14:08 ` Serge E. Hallyn
2021-04-16 12:42 ` Sumit Garg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210414140734.GB11180@mail.hallyn.com \
--to=serge@hallyn.com \
--cc=dan.carpenter@oracle.com \
--cc=dhowells@redhat.com \
--cc=jarkko@kernel.org \
--cc=jejb@linux.ibm.com \
--cc=jmorris@namei.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=sumit.garg@linaro.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox