From patchwork Fri Nov 10 20:30:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10053713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C70F360365 for ; Fri, 10 Nov 2017 20:30:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF0452B3EB for ; Fri, 10 Nov 2017 20:30:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3FCD2B42A; Fri, 10 Nov 2017 20:30:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 780EB2B3EB for ; Fri, 10 Nov 2017 20:30:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754092AbdKJUap (ORCPT ); Fri, 10 Nov 2017 15:30:45 -0500 Received: from mout.web.de ([212.227.15.3]:63517 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750799AbdKJUam (ORCPT ); Fri, 10 Nov 2017 15:30:42 -0500 Received: from [192.168.1.3] ([77.182.5.151]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MOj5C-1eG1Mw1Wdi-0063ao; Fri, 10 Nov 2017 21:30:30 +0100 Subject: [PATCH 2/2] KEYS: trusted: Use common error handling code in tpm_unseal() From: SF Markus Elfring To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, David Howells , James Morris , Mimi Zohar , "Serge E. Hallyn" Cc: LKML , kernel-janitors@vger.kernel.org References: <479805df-edaf-1e9a-57be-d7c4f38e9d31@users.sourceforge.net> Message-ID: <3470e9c8-f7d8-247c-9e69-5301f71c3982@users.sourceforge.net> Date: Fri, 10 Nov 2017 21:30:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <479805df-edaf-1e9a-57be-d7c4f38e9d31@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:FqO39uoaFbhq4wPs/x64xZpeeQuTmoR/yvv6GKReASsc8RXNCUy rZ0Bfmyl+k6MBjpzReMqLT+oxGW5Ig6WTzA8tWlelZooIkSeE2MhDuTweyaul5WDIwUXQYn 2tP70AtI8iiJyRBxC92RXQIMk7O7VlxEhAKCLg1Ioc/cGIlT2j8eNJWTZSrGM1jbhnh3lP1 eobRW9s+ZFfJZz1gQczWw== X-UI-Out-Filterresults: notjunk:1; V01:K0:U94RMlWQ8fI=:IBWosIT3IerXfGY5OZaes/ aHVIKxFatP2REQVCebMYr6MjfC1aGy9ZDXe4mUcRzSiE9zZcNvUi2dDPlgZGENqnUiT1/PJON dmM/NqpnTBt4dSygoY8OXBwnmn2B6HQ9IKI6UVRr63uE2z9OzCGLxQs5A8MozcqlQl5CqjKLH j3HtmQrGKDyr9nBCgpWXdKbJzN8zjfSbsfTDbeO1tYUz06gzDCCSFBSivQStpB3DdG0wBXQh/ rZ/N6OFGT+OBj3ZmDMVAC0J2y0yPgqu/iH/YfxTaogXEnpUsp0hEHcLVYlB5aSp3aMOqEVaaX Owra17/1Ivdr/bzFvNAUH8bLZH83ODNxmDvJeql2xQG+rQWREH39nbcHUT/+YhATrbquL9DZX fCWvGol5jloNREMCDEg8QiR4H1Vof45jCJxkCVzU6vI81kcxlS4Y2BwWdG/4PDdF79iVqOBIj KAhVitC2GF0gs95qYJyUonu4DHj2Qc4JNjG5vs3NLyJzt6Z/AQs+RqWV7SsST/+ISpbV73FEd 2+WGDqANlowx9f23eX6RS2wf003pHsznUCLhTmQ5IDnL3lT/Bbt8YgPlo2z58/onZPQhfKYS0 edxV3BgzCwJd5HtTrtFvuFMVZfrdXWzGyguVxKW5dsC+ASej2F9fVrT8hX/GG+CR42pCIaBcF 2EMEMhUD2APh4zvpgwLCfvGBxFgTMfZsgAVOv+qHrxu2TnX7kvWKGJXAJEXYwVbpHWO8eTCbT XKHTlsFfthe0kUnM9jDGmNeMRDKS6xxOv547f7My2/ZCe/lmmVsqEqbTdTktFgIM6lBAZfZ1Q EnRcvNe8w0qNs0Zf5vAlzNkOdpkUiWK7UGszYFCV0fJtzugfUs= Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring 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 --- 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; } /*