From patchwork Fri May 4 14:09:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10380827 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 CA4D560353 for ; Fri, 4 May 2018 14:57:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAD6D29491 for ; Fri, 4 May 2018 14:57:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACF2F294C0; Fri, 4 May 2018 14:57:18 +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 301DB29491 for ; Fri, 4 May 2018 14:57:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751272AbeEDO5R (ORCPT ); Fri, 4 May 2018 10:57:17 -0400 Received: from gateway20.websitewelcome.com ([192.185.59.4]:48787 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750820AbeEDO5Q (ORCPT ); Fri, 4 May 2018 10:57:16 -0400 X-Greylist: delayed 1502 seconds by postgrey-1.27 at vger.kernel.org; Fri, 04 May 2018 10:57:16 EDT Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 6CD2D400D4570 for ; Fri, 4 May 2018 09:09:17 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id EbOffOZuAA3CSEbOffSjKo; Fri, 04 May 2018 09:09:17 -0500 X-Authority-Reason: nr=8 Received: from [187.172.56.86] (port=49240 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.89_1) (envelope-from ) id 1fEbOe-0013Fy-RZ; Fri, 04 May 2018 09:09:16 -0500 Date: Fri, 4 May 2018 09:09:14 -0500 From: "Gustavo A. R. Silva" To: John Johansen , James Morris , "Serge E. Hallyn" Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , kernel-janitors@vger.kernel.org Subject: [PATCH v2] apparmor: secid: fix error return value in error handling path Message-ID: <20180504140914.GA16787@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.172.56.86 X-Source-L: No X-Exim-ID: 1fEbOe-0013Fy-RZ X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [187.172.56.86]:49240 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 4 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Currently, function apparmor_secid_to_secctx returns always zero, no matter if the value returned by aa_label_asxprint is negative (which implies that an error has occurred). Notice that *seclen* is of type u32 (32 bits, unsigned), and a less-than-zero comparison of an unsigned value is never true. Fix this by temporarily storing the value returned by aa_label_asxprint into a variable of type int (signed) for its further evaluation. Addresses-Coverity-ID: 1468514 ("Unsigned compared against 0") Fixes: c092921219d2 ("apparmor: add support for mapping secids and using secctxes") Signed-off-by: Gustavo A. R. Silva --- Changes is v2: - Update changelog. - Fix misaligned lines. security/apparmor/secid.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index 5029248..efaa0d9 100644 --- a/security/apparmor/secid.c +++ b/security/apparmor/secid.c @@ -142,6 +142,7 @@ int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) { /* TODO: cache secctx and ref count so we don't have to recreate */ struct aa_label *label = aa_secid_to_label(secid); + int seclen_tmp; AA_BUG(!secdata); AA_BUG(!seclen); @@ -150,17 +151,21 @@ int apparmor_secid_to_secctx(u32 secid, char **secdata, u32 *seclen) return -EINVAL; if (secdata) - *seclen = aa_label_asxprint(secdata, root_ns, label, - FLAG_SHOW_MODE | FLAG_VIEW_SUBNS | - FLAG_HIDDEN_UNCONFINED | - FLAG_ABS_ROOT, GFP_ATOMIC); + seclen_tmp = aa_label_asxprint(secdata, root_ns, label, + FLAG_SHOW_MODE | + FLAG_VIEW_SUBNS | + FLAG_HIDDEN_UNCONFINED | + FLAG_ABS_ROOT, GFP_ATOMIC); else - *seclen = aa_label_snxprint(NULL, 0, root_ns, label, - FLAG_SHOW_MODE | FLAG_VIEW_SUBNS | - FLAG_HIDDEN_UNCONFINED | - FLAG_ABS_ROOT); - if (*seclen < 0) + seclen_tmp = aa_label_snxprint(NULL, 0, root_ns, label, + FLAG_SHOW_MODE | + FLAG_VIEW_SUBNS | + FLAG_HIDDEN_UNCONFINED | + FLAG_ABS_ROOT); + if (seclen_tmp < 0) return -ENOMEM; + else + *seclen = seclen_tmp; return 0; }