Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11793288pjo; Thu, 2 Jan 2020 14:22:45 -0800 (PST) X-Google-Smtp-Source: APXvYqyBOvLCTi+ZDbq4mnq+HcGrCB+REvop4cNO2kdN4/xHkJXGB+p3J6f9m/HHShIZfcZKonDZ X-Received: by 2002:a9d:6c01:: with SMTP id f1mr89801184otq.133.1578003765784; Thu, 02 Jan 2020 14:22:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578003765; cv=none; d=google.com; s=arc-20160816; b=AN2mHN2BSqk52NrUSsG2ts2hoQ2GI+1bIbCMLU5XvFmaaZhQbFnH6PwEV+Tqbnuevz vRocvsSP/5JkVVaIUiZm2PdLByjNiZl5NNriAKNwq3sP2ZURmq1GHwdsleAxuj9dvoCT bBhpNG+AR/qqCsFYD/4LWpGXVI7B549v1tYNnOIxiGlxB5sVCnD9xSgAM8uxONoEbjOq DZc8u8wL2EJv8vW+6YuumKsmP0P7NNisQ2mmG4MtqBzjxokO1HHHwzYL7Y2opF7w3VZg iUkYY6bwyVRU9hvFWKUPKRzIsUMRnYT1tAGnefs6zHoq+lUHEyydSQ1xNEa1Au1MILGX CzjA== 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=WLPQHPw/4q0+bP0aXKov7kkSpkt6hCv/gzfrcm/QwZM=; b=pOztjDH6gGcW918vEa0hjlQvNiOKPfjEyxNResP/emwlaLwPlvss0KGpSq91ZYyiFv FxQFGzo4vWVPafVNWNqBP9SbMwDCdoagFWyyCZr/ULcc5AkSqigudTNbDxKPC+l3WUMk j0i2cAgYDmcBm77Dxx1+uYUqtrA9NbU0CCc4uCNksJUYldNQx2p65/cL0dhFis3x37sP fFbehAH+kZm0Y1oQ8CBwgrzc6ch2BCXrVT+eDVwzyeaBDJ28kHTk/sDAUk0H7w5IUA2s XSC8yCg9FfBr9CuStqi7jx/fHfVnBShEmx4TgErYXUepsOzVs2R4pzKP8srSsiUCLsCU efBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bB6N+WIf; 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 g6si10411284otk.171.2020.01.02.14.22.34; Thu, 02 Jan 2020 14:22:45 -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=bB6N+WIf; 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 S1728506AbgABWU4 (ORCPT + 99 others); Thu, 2 Jan 2020 17:20:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:39156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726927AbgABWUy (ORCPT ); Thu, 2 Jan 2020 17:20:54 -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 6DC3D21582; Thu, 2 Jan 2020 22:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003653; bh=1HQOmY+/vAg36JcMkUhBh/Zavmr/ssHnliyiwLhDux8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bB6N+WIfWcBohw6kFVbm0kr73+AXu3u8hAWou9a/s55o4hJAgKpqm7dnwBt+PP40c 4R5Ci+b5/6kP55tniOSaMux8DAX2DDfcvinDudilU2S6VEuoEHvcp0d09Fsak7Z4gw E2UNVdIlPJG9DaUNB7N8enrbFJ1mY/bBnBdmkngI= 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.19 059/114] apparmor: fix unsigned len comparison with less than zero Date: Thu, 2 Jan 2020 23:07:11 +0100 Message-Id: <20200102220034.968393658@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220029.183913184@linuxfoundation.org> References: <20200102220029.183913184@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 ba11bdf9043a..2469549842d2 100644 --- a/security/apparmor/label.c +++ b/security/apparmor/label.c @@ -1462,11 +1462,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) /** @@ -1601,7 +1603,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