From patchwork Fri May 4 14:15:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 10380701 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 A3C6A6037D for ; Fri, 4 May 2018 14:15:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 855FA29480 for ; Fri, 4 May 2018 14:15:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 794D229482; Fri, 4 May 2018 14:15:17 +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 E6AE729480 for ; Fri, 4 May 2018 14:15:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751240AbeEDOPQ (ORCPT ); Fri, 4 May 2018 10:15:16 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:34046 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751196AbeEDOPP (ORCPT ); Fri, 4 May 2018 10:15:15 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1fEbUO-0000Nq-IM; Fri, 04 May 2018 14:15:12 +0000 From: Colin King To: John Johansen , James Morris , "Serge E . Hallyn" , linux-security-module@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] apparmor: fix error return check with a u32 being less than zero Date: Fri, 4 May 2018 15:15:11 +0100 Message-Id: <20180504141511.19793-1-colin.king@canonical.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King The check for *seclen being less than zero for an error condtion check is never true as it is a u32 and hence cannot be less than zero. Fix this by using an int ret for error return checking and assigning *seclen to this. Detected by CoverityScan, CID#1468514 ("Unsigned comparison against 0") Fixes: c092921219d2 ("apparmor: add support for mapping secids and using secctxes") Signed-off-by: Colin Ian King --- security/apparmor/secid.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c index 502924853986..9c431e9a9836 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 ret; AA_BUG(!secdata); AA_BUG(!seclen); @@ -150,16 +151,17 @@ 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); + ret = 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) + ret = aa_label_snxprint(NULL, 0, root_ns, label, + FLAG_SHOW_MODE | FLAG_VIEW_SUBNS | + FLAG_HIDDEN_UNCONFINED | + FLAG_ABS_ROOT); + *seclen = ret; + if (ret < 0) return -ENOMEM; return 0;