]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
apparmor: fix unsigned len comparison with less than zero
authorColin Ian King <colin.king@canonical.com>
Thu, 27 Jun 2019 13:09:04 +0000 (14:09 +0100)
committerKhalid Elmously <khalid.elmously@canonical.com>
Wed, 29 Jan 2020 04:47:27 +0000 (23:47 -0500)
BugLink: https://bugs.launchpad.net/bugs/1860602
[ 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 <colin.king@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
security/apparmor/label.c

index 324fe5c60f8781c952138d0a764a5c2223f6353b..515dac29d38a0c0987a8b4cc052df6b9b0621769 100644 (file)
@@ -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);