Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17927911ybl; Thu, 2 Jan 2020 15:00:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxGE1V4rq/pDLOeaUis4KsA32c1PRHkzTjgaPP83EcSvsb6Mvi6pMA9KSTT7YDkDw7+dsrI X-Received: by 2002:a9d:6e98:: with SMTP id a24mr77426673otr.109.1578006019519; Thu, 02 Jan 2020 15:00:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578006019; cv=none; d=google.com; s=arc-20160816; b=lmD3AWhMdO2MNVa2UBfQuEDr/i1jQuRwoMFAc2VargmGRqn488jyWf/0uDkw53n7/I UhUL6ef1M90iAevwExal9/FmjGAptqFWKRL/e2jR3jbEn67QmiJSzsWisO66PkeDl8Wj FSfeajtojNcKJuvWlQGeL9XB1RHtB9btioqT5/8pJWVYD9kxD13isMWD288bY1tbPXnk 7zdrUV0r9K3mKUKNOzAAPfC5QWf2FSWIZJjfFiROBo1rwJqrQN/2nGJzGHGaxalzNMyp exJShsXTmtF1+1mSUT8tYifrSymIPgB+nDzdBkc8EUPhP5M/u1qhJM4R3HjKqdN/yJMN 5Yjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ktmCFfZzJYLyqrzJOV+m4ZSR9WhklgV/iaTewAzdZbg=; b=bxsn1B/MD7HAudTypaXM2q1r0fLd4PSyfgIx3/wbJzGl06x2SFHxulaj5PwjB24php hoon+gxywUns8+d/PYhrN+tZnmow1luyC9ygXu11O5Rz5WR6KuyG8No7jx02XnEpJpWb X8FjxXqCi/Es2bWi/OK1pv8YUoXM4gibWR+lm/b54QOPrQC/5O6LeCMYDO26uOyh0Sld pQR8g614nO4E/iGVlDCZiC3L6WbNENPoLWa0JnXvymtHn4PqMvYXD/eDS1zVbVQikcjt hKF2HtqoWTuCF1ovYUle4+t3lCqT/AWrHu/+t7xIOhBLMsQnK22KA2D5qk8C13r9HTl3 bSrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EGKxekhb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 17si12557235oix.22.2020.01.02.15.00.07; Thu, 02 Jan 2020 15:00:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EGKxekhb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727954AbgABW6z (ORCPT + 99 others); Thu, 2 Jan 2020 17:58:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:55600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728001AbgABWPC (ORCPT ); Thu, 2 Jan 2020 17:15:02 -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 1FFA024649; Thu, 2 Jan 2020 22:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003301; bh=KHMm0neWLyWoQiQj8vd+QVGhRlKjHrs6P4ShXL59hT0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EGKxekhbSARv5WzxcjyFt5SfCOFneYAJXEaU7TkH61UGUZOjtv37dnOBoLXgSvYgF O5vlghkbRQMPC8YqEpPQ7K5JmryjfUO7OoPMMfvOdgLNTgej6i0bBLKd+Q71YSTO2f egxElNhDp4VNx3jhWw31U3NReW7zVdTU3t7Wf+V4= 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 5.4 104/191] apparmor: fix unsigned len comparison with less than zero Date: Thu, 2 Jan 2020 23:06:26 +0100 Message-Id: <20200102215841.088282465@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 59f1cc2557a7..470693239e64 100644 --- a/security/apparmor/label.c +++ b/security/apparmor/label.c @@ -1458,11 +1458,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) /** @@ -1597,7 +1599,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); -- 2.20.1