From patchwork Thu Jan 2 22:07:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 234741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5524AC3276C for ; Thu, 2 Jan 2020 22:24:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 26E1620863 for ; Thu, 2 Jan 2020 22:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003895; bh=NitZFmkUU14PrjVIlTGxXu1q1LKT2NOe/iiTj0wOUEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=J6ty56GUU0J3xcF5Yae89fPHYuSpmU42PeZHTIwLtNhEvA5fyc482jMIhov2c740p zA7noBf6FFraXJG4RrzBIQz7gsjpMg7UKQLjtm7mkhqdDO0hEIZSoKSJBdxYFaYQAQ ETbbC75BmBJO+CtchqsbcteXW4CDhvNBJjVoT3jc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729422AbgABWYy (ORCPT ); Thu, 2 Jan 2020 17:24:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:49418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729313AbgABWYw (ORCPT ); Thu, 2 Jan 2020 17:24:52 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7B7B920866; Thu, 2 Jan 2020 22:24:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003891; bh=NitZFmkUU14PrjVIlTGxXu1q1LKT2NOe/iiTj0wOUEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=prtbVK3sLyNp2RdsvULJ8oJljQqlgACIJ9JLh4YndTt6REyDcyTP5PsWPdB+2KYA0 ZCu8Ai32HaeWJ3IMydW5cLzliI76pLjZ7QxQSxyLm0qQRJIHmGrHbwOE0XfxEP+Nil XAZ3jBNKaxkUQ+D58MvrQDmecCIseSkN9iNfhy0M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , John Johansen , Sasha Levin Subject: [PATCH 4.14 43/91] apparmor: fix unsigned len comparison with less than zero Date: Thu, 2 Jan 2020 23:07:25 +0100 Message-Id: <20200102220434.364866728@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220356.856162165@linuxfoundation.org> References: <20200102220356.856162165@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Colin Ian King [ Upstream commit 00e0590dbaec6f1bcaa36a85467d7e3497ced522 ] The sanity check in macro update_for_len checks to see if len is less than zero, however, len is a size_t so it can never be less than zero, so this sanity check is a no-op. Fix this by making len a ssize_t so the comparison will work and add ulen that is a size_t copy of len so that the min() macro won't throw warnings about comparing different types. Addresses-Coverity: ("Macro compares unsigned to 0") Fixes: f1bd904175e8 ("apparmor: add the base fns() for domain labels") Signed-off-by: Colin Ian King Signed-off-by: John Johansen Signed-off-by: Sasha Levin --- security/apparmor/label.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/security/apparmor/label.c b/security/apparmor/label.c index c5b99b954580..ea63710442ae 100644 --- a/security/apparmor/label.c +++ b/security/apparmor/label.c @@ -1463,11 +1463,13 @@ static inline bool use_label_hname(struct aa_ns *ns, struct aa_label *label, /* helper macro for snprint routines */ #define update_for_len(total, len, size, str) \ do { \ + size_t ulen = len; \ + \ AA_BUG(len < 0); \ - total += len; \ - len = min(len, size); \ - size -= len; \ - str += len; \ + total += ulen; \ + ulen = min(ulen, size); \ + size -= ulen; \ + str += ulen; \ } while (0) /** @@ -1602,7 +1604,7 @@ int aa_label_snxprint(char *str, size_t size, struct aa_ns *ns, struct aa_ns *prev_ns = NULL; struct label_it i; int count = 0, total = 0; - size_t len; + ssize_t len; AA_BUG(!str && size != 0); AA_BUG(!label);