From patchwork Tue Jan 24 18:44:45 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: 9535665 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 ABAB3604A0 for ; Tue, 24 Jan 2017 18:45:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D6D226C2F for ; Tue, 24 Jan 2017 18:45:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 818E626E76; Tue, 24 Jan 2017 18:45:57 +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=ham 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 32B0126E3E for ; Tue, 24 Jan 2017 18:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750882AbdAXSpZ (ORCPT ); Tue, 24 Jan 2017 13:45:25 -0500 Received: from mout.web.de ([212.227.17.12]:57468 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751086AbdAXSpX (ORCPT ); Tue, 24 Jan 2017 13:45:23 -0500 Received: from [192.168.1.2] ([77.181.182.246]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MY712-1d0wm21gqu-00Unkf; Tue, 24 Jan 2017 19:44:59 +0100 To: linux-ima-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, James Morris , Mimi Zohar , "Serge E. Hallyn" Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] evm: Move two error code assignments in evm_set_key() Message-ID: Date: Tue, 24 Jan 2017 19:44:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 X-Provags-ID: V03:K0:/UQv5eUtXWWzetBwxBQBNtIHGtasNnOrOoGwDcYJOxMcZBWOXXw 5CQht/EjDG4e8tMx3Ja7mEGKjldog7dHU41r/Qw6iMWwSvocxE3JtJE9ztU2qQ8HHrgaoag NL6d/hkS86NukbESnEc3GZqx6AJOsC8Y7Sc087IUG+VUyMb806J1qGjqEbgD1JOKhc7U1Sc PFHyKhk8XcYuEOEFBZ75w== X-UI-Out-Filterresults: notjunk:1; V01:K0:pKP74d3Qzjw=:gJ1IIz9hDpl50+fUjAHheH 75BqYs4zMmSXBnU/xqiNwRE1vPy8pyBNIeOot8GmXkkYPW8Y8Q2naMIb9Cp40yxtBSLeE/wHX 19oSPmLDNL/OG+0hW1deeS/+gE8Ozw0e/Ce1MfDvq9kxdsIkkzh9J/rslnLolTstfMJQ0LJ9t iSJbKPwVo7AfYFsySi+D0UoD4PnNlMyxkKOGPFLNJstHnYjPESIismszUM/1S2CexqrUVa0Ya cXDDV85WHDuc7ciYwXUATNXUKI0QjrHqy38qURs+4v2wCfk+RaES2MStOWXtv553PEdvkp4OW 9brMkcs7Bt8RQoFw2e8UEaG3mAb6OQsw7D4rIg0QVwoMIBYuNJP4hVu47GiICaCNe2op2l58n 0LhabRexLymAH7GUk3c7Cyz7Q/d74sRhpxwx8AKqEdTU88v9svqQJgmsPlo3tsjM+2azhd7BB ui+KeuqBsRZCvQb7hbgoRvckaGIxcB43cS8+QgkXUGP+3zEGuXJKKvVllrNSdsQLwSY6Y1bWD AgSh6FtvMpbIxbxaxJrpxPDTWOkZkFN8Ix9+A+NUnX3ctRIcS591VfIxuT43I9DQxrkGfsH7m p+eWfmFjfMBDjngy+sI8NYYwESD7WGNBgz6FAbwxp42qCFKC1J06gS0ZrHEvD5f+qtfQW3laS Dy9I90Vy7JA7F7sr4/rcyJiVlWGNpDRgHZQtOsLeP9bA6gQvEB+XbewNee7fLxL1eAIoarP0r JrA9GXNTI/A+7B5PsmDJly2+Bc7UUi4dgvGt0qusocrIqnz88m94MKJRaQRGa7eHWnMkla3Tf tWRiZGm Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Tue, 24 Jan 2017 19:37:20 +0100 A local variable was set to an error code in two cases before a concrete error situation was detected. Thus move the corresponding assignments into if branches to indicate a software failure there. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- security/integrity/evm/evm_crypto.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c index d7f282d75cc1..71bc204e2ee8 100644 --- a/security/integrity/evm/evm_crypto.c +++ b/security/integrity/evm/evm_crypto.c @@ -53,12 +53,14 @@ int evm_set_key(void *key, size_t keylen) { int rc; - rc = -EBUSY; - if (test_and_set_bit(EVM_SET_KEY_BUSY, &evm_set_key_flags)) + if (test_and_set_bit(EVM_SET_KEY_BUSY, &evm_set_key_flags)) { + rc = -EBUSY; goto busy; - rc = -EINVAL; - if (keylen > MAX_KEY_SIZE) + } + if (keylen > MAX_KEY_SIZE) { + rc = -EINVAL; goto inval; + } memcpy(evmkey, key, keylen); evm_initialized |= EVM_INIT_HMAC; pr_info("key initialized\n");