From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 9A083C00454 for ; Wed, 11 Dec 2019 15:31:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 702972173E for ; Wed, 11 Dec 2019 15:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576078272; bh=Sqt1QQ5TgmAeKM99E7qB9AJtymygBlvwZg1hB0TiU7c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZR2SMe9LrVueg3nQLHX1MAkrwDkCilyFexVKjxU0DxrfyJKgoDTB0K1x0ML6EliaS ZkUy/Y4So0eCxiebQq8MsfQ5idGCwcvgcuf9P8UwReFG79zJ1qFm0qpb3seL2TVVdp raaryqwaMCPleB/7QAmg+ayiy7Z4SC7N+9xybSHs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387426AbfLKPbI (ORCPT ); Wed, 11 Dec 2019 10:31:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:36156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387862AbfLKP3W (ORCPT ); Wed, 11 Dec 2019 10:29:22 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43E732467A; Wed, 11 Dec 2019 15:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576078161; bh=Sqt1QQ5TgmAeKM99E7qB9AJtymygBlvwZg1hB0TiU7c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dK9jmo//HBK8wrVT8FYjF/93CIIXhmRMpT7UWJGLE5poP9a7HPp9AAQu0ESS3dOmj mFR9b0TWS6Yokvt4OMSu964H+wxhtjEnHH7T8KnyW+v8dNwe2W9M8S9cwQLZV+qWdT 9MoZUGD2Xo+1iflM/fJQZgxZ6682VmDfF8jT0DfQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Colin Ian King , John Johansen , Sasha Levin , linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 46/58] apparmor: fix unsigned len comparison with less than zero Date: Wed, 11 Dec 2019 10:28:19 -0500 Message-Id: <20191211152831.23507-46-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191211152831.23507-1-sashal@kernel.org> References: <20191211152831.23507-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 c5b99b954580c..ea63710442ae5 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); -- 2.20.1