From: SF Markus Elfring <elfring@users.sourceforge.net>
To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org,
linux-security-module@vger.kernel.org,
David Howells <dhowells@redhat.com>,
James Morris <james.l.morris@oracle.com>,
Mimi Zohar <zohar@linux.vnet.ibm.com>,
"Serge E. Hallyn" <serge@hallyn.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 2/2] KEYS: trusted: Use common error handling code in tpm_unseal()
Date: Fri, 10 Nov 2017 21:30:25 +0100 [thread overview]
Message-ID: <3470e9c8-f7d8-247c-9e69-5301f71c3982@users.sourceforge.net> (raw)
In-Reply-To: <479805df-edaf-1e9a-57be-d7c4f38e9d31@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 10 Nov 2017 21:15:53 +0100
* Add a jump target so that a specific error message is stored only once
at the end of this function implementation.
* Replace two calls of the macro "pr_info" by goto statements.
* Adjust two condition checks.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/keys/trusted.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/security/keys/trusted.c b/security/keys/trusted.c
index fd06d0c5323b..a295eaae40ba 100644
--- a/security/keys/trusted.c
+++ b/security/keys/trusted.c
@@ -591,15 +591,12 @@ static int tpm_unseal(struct tpm_buf *tb,
/* sessions for unsealing key and data */
ret = oiap(tb, &authhandle1, enonce1);
- if (ret < 0) {
- pr_info("trusted_key: oiap failed (%d)\n", ret);
- return ret;
- }
+ if (ret)
+ goto report_failure;
+
ret = oiap(tb, &authhandle2, enonce2);
- if (ret < 0) {
- pr_info("trusted_key: oiap failed (%d)\n", ret);
- return ret;
- }
+ if (ret)
+ goto report_failure;
ordinal = htonl(TPM_ORD_UNSEAL);
keyhndl = htonl(SRKHANDLE);
@@ -654,6 +651,10 @@ static int tpm_unseal(struct tpm_buf *tb,
}
memcpy(data, tb->data + TPM_DATA_OFFSET + sizeof(uint32_t), *datalen);
return 0;
+
+report_failure:
+ pr_info("trusted_key: oiap failed (%d)\n", ret);
+ return ret;
}
/*
--
2.15.0
prev parent reply other threads:[~2017-11-10 20:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-10 20:28 [PATCH 0/2] security/keys/trusted: Fine-tuning for two function implementations SF Markus Elfring
2017-11-10 20:29 ` [PATCH 1/2] KEYS: trusted: Use common error handling code in trusted_update() SF Markus Elfring
2017-11-10 20:52 ` Julia Lawall
2017-11-11 9:37 ` SF Markus Elfring
2017-11-10 20:30 ` SF Markus Elfring [this message]
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=3470e9c8-f7d8-247c-9e69-5301f71c3982@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=dhowells@redhat.com \
--cc=james.l.morris@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=zohar@linux.vnet.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;
as well as URLs for NNTP newsgroup(s).