From patchwork Wed Jan 25 09:34:29 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: 9536609 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 82189601D7 for ; Wed, 25 Jan 2017 09:34:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C51E205F6 for ; Wed, 25 Jan 2017 09:34:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F8A026E94; Wed, 25 Jan 2017 09:34:55 +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 16096205F6 for ; Wed, 25 Jan 2017 09:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751507AbdAYJex (ORCPT ); Wed, 25 Jan 2017 04:34:53 -0500 Received: from mout.web.de ([217.72.192.78]:58206 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751572AbdAYJew (ORCPT ); Wed, 25 Jan 2017 04:34:52 -0500 Received: from [192.168.1.2] ([77.181.222.247]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0M4ZTk-1cI5Tm1SYu-00yliy; Wed, 25 Jan 2017 10:34:30 +0100 Subject: [PATCH 3/3] ima_fs: Move three error code assignments in ima_write_policy() To: linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org, Dmitry Kasatkin , James Morris , Mimi Zohar , "Serge E. Hallyn" References: Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: Date: Wed, 25 Jan 2017 10:34:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: X-Provags-ID: V03:K0:yegdivtGTCu0xhsabtc2p/PT1iqKTgb82Z/gKf+N0bjjsZ7M2FZ TSATAUGsefdiRYqc+hltBIgN5js/GzFO0AaA0KFIRZX1Yt5f+nK8flUA/Fv6Niu993+gx+I CcMNV0Gmp99Zhx/Tj0iTZjrhAUTrKPuXCeWrxQdWkes33vw5iwiCLcmHIH+sQEIqkpT9pE6 hOkezUDRZHz3WLISkNSng== X-UI-Out-Filterresults: notjunk:1; V01:K0:d/1eZ70P768=:CuQCIAgeJx2OrY5k1iK6LV HDEUUOUSOVkBzQReDElp39EAB/vJY+LgR19MfnSYYpfu3CXTkH1XKzdVKEWaUTOVV3p9qQhvg wA3zDTYPEV6F94i7rTq3ZcvKWP2JNXGpzFJt50hX/vcbqdz03NdSUwaV8k9Ci/YCN22JGThLg VToSjHolThtJ5CMImDE+gUwqEAq4Yt8BeGCCn7U2t6asD14mNQ5TGxE/tvn53+gZMCzSD7NX8 tYIBpY3QuNN6oAGU6Rebfsqi6+ly+MPyF/mBomg/pLS3PCZjK4MpNfVbRfDSfZVmNjv9B5357 vNrccHdhWBs0QhJQfPOb+hqo3e2JbsTqt3386LYTxfyZp5IORWiEVr665gFiX6UihkCkFB/7U mvVNqf3AbMHTWTRMdX1fQHfkm8mkw8OQRb3epdpsrdptCrdBArnCLRvN+xrC9es0z0mT9dca3 gvpKmY5lxOJoq/6a+puL55fHIPYpZKgSKYK8CiuhhizPZGEnqsiTE5IPZevIGiBvbTxUIw9wN p4iWjdpzkyVHLs1TQzdjXoKJWlSdRbDHPyBdqCpXGVE+gyHuLLZcVsBJ9HVKwLXDn/5/LaZE3 Sjmw5gSeu6aQtPJWer/P3iYiwB2VRW4Aeyo5oJCX3oZ6ZirybQ2hCzVQ1pYY/fIC3TsDEJgY0 jRAs9UnUJv4Rm7RfLAEhGBPXPrhPO2EXAupVoYyPk9JTJso5goD9GcHo9F5nR/xO8RQ9q0ROo BfhNv7tCZOYOmPI/Kjmse0t2GI003SkMMvsX9XnD56VUf0ISV9o7rkE5mBlSwPS8kG4Q+eoTO UCqOYY2 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 22:47:07 +0100 A local variable was set to an error code in three 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/ima/ima_fs.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c index 98304411915d..a50c26f9772c 100644 --- a/security/integrity/ima/ima_fs.c +++ b/security/integrity/ima/ima_fs.c @@ -317,21 +317,24 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, /* No partial writes. */ result = -EINVAL; - if (*ppos != 0) + if (*ppos != 0) { + result = -EINVAL; goto reset_validity; + } - result = -ENOMEM; if (datalen >= PAGE_SIZE) datalen = PAGE_SIZE - 1; data = kmalloc(datalen + 1, GFP_KERNEL); - if (!data) + if (!data) { + result = -ENOMEM; goto reset_validity; + } *(data + datalen) = '\0'; - - result = -EFAULT; - if (copy_from_user(data, buf, datalen)) + if (copy_from_user(data, buf, datalen)) { + result = -EFAULT; goto out_free; + } result = mutex_lock_interruptible(&ima_write_mutex); if (result < 0)