From patchwork Fri Oct 8 21:10:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 12546471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08881C433F5 for ; Fri, 8 Oct 2021 21:10:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D638860F9E for ; Fri, 8 Oct 2021 21:10:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242456AbhJHVMd (ORCPT ); Fri, 8 Oct 2021 17:12:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbhJHVMd (ORCPT ); Fri, 8 Oct 2021 17:12:33 -0400 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE740C061570 for ; Fri, 8 Oct 2021 14:10:37 -0700 (PDT) Received: by mail-qv1-xf35.google.com with SMTP id z15so7219699qvj.7 for ; Fri, 08 Oct 2021 14:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=t2iDWdiD8CSOIQx2q5djdnCrczqYEBsrUpo5KEaNd6E=; b=a8oHVMjt2Un7Mfsuod3g8lHedMW3UK/yUYZry707ZshYA2c34fYWcVMCgk10dGlwss oJ44aD8Y7ZCpgDtZgxiLA43jMNBbKNdxS30x4zRuELae1wbw3FjfcW4ZWnaxjqRfEGFn l3KnuJOJeSIDrZQ3YyTJ33NbQMwljaN8e1E2EqVb269SctPI2t9fQXbL8nvnRvFF/93G BXuNdii0CuskUJhWXBx2dNFWsLXPddybfHptLzMCZ2+4buXCTKU/i/e/Wh0OYx2uGg4P 6iZTmmI4NitEI+7MRGiv3gq7PxlmUafp1OWI7pK8cO525ifnZiDYEexENP08bPTFf9vr d4YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=t2iDWdiD8CSOIQx2q5djdnCrczqYEBsrUpo5KEaNd6E=; b=jhIO6Rl6uEL2alPJFjMIj5GzfbOjuAlJT0w4e5+5BeNtmFkCKQ51R1LpV9aliddPTL gKakG7GalLGtMB6PHY/wzAeBcmzwxwl9c8ejYwAh9jWqHH1mY6z7p8Xl0tjmcZIE2Muu uPdGlgWcJKWqN2lyWM5b1u3pMivrTvT6aiQH3dRcbFqW3MCSDsWr0zh1kwo3uxgz6U3h gXV3QjobiidPJPpDmVZtg9KjIDVYeYKqJE+9dmJRfS0fOWhqzbZRQDkwxG7R2LgfNLzE U8Fy1gVfjsLMEDmPozdrP5btjS3WPa5c529kxQplVT7cU9fcEmCC9gTDHyrdDi9TQEXy +o1Q== X-Gm-Message-State: AOAM5300MGjx3WSGOSchlTB4GZq2W5fUWX6WxGu+KkgR7Wvc42Ewumbf cEbJc4x0sp78aZwQQoqkhSG/Ro1moe8= X-Google-Smtp-Source: ABdhPJxgr/FMh6th4hKOubUKGJEww0nIh6jfCo77SN60s6Kk6lfLlChAztjrC4iCndyocsXzE8g7lg== X-Received: by 2002:ad4:4622:: with SMTP id x2mr12506312qvv.39.1633727436586; Fri, 08 Oct 2021 14:10:36 -0700 (PDT) Received: from localhost.localdomain (c-73-200-157-122.hsd1.md.comcast.net. [73.200.157.122]) by smtp.gmail.com with ESMTPSA id u9sm332453qta.90.2021.10.08.14.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:10:36 -0700 (PDT) From: James Carter To: selinux@vger.kernel.org Cc: nicolas.iooss@m4x.org, James Carter Subject: [PATCH 1/4] libsepol: Fix potential undefined shifts Date: Fri, 8 Oct 2021 17:10:28 -0400 Message-Id: <20211008211031.393884-1-jwcart2@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org An expression of the form "1 << x" is undefined if x == 31 because the "1" is an int and cannot be left shifted by 31. Instead, use "UINT32_C(1) << x" which will be an unsigned int of at least 32 bits. Signed-off-by: James Carter --- libsepol/src/avtab.c | 2 +- libsepol/src/conditional.c | 6 +++--- libsepol/src/link.c | 4 ++-- libsepol/src/policydb.c | 4 ++-- libsepol/src/services.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libsepol/src/avtab.c b/libsepol/src/avtab.c index 93505b20..46e1e75d 100644 --- a/libsepol/src/avtab.c +++ b/libsepol/src/avtab.c @@ -376,7 +376,7 @@ int avtab_alloc(avtab_t *h, uint32_t nrules) } if (shift > 2) shift = shift - 2; - nslot = 1 << shift; + nslot = UINT32_C(1) << shift; if (nslot > MAX_AVTAB_HASH_BUCKETS) nslot = MAX_AVTAB_HASH_BUCKETS; mask = nslot - 1; diff --git a/libsepol/src/conditional.c b/libsepol/src/conditional.c index e3ede694..037dc7e2 100644 --- a/libsepol/src/conditional.c +++ b/libsepol/src/conditional.c @@ -411,13 +411,13 @@ int cond_normalize_expr(policydb_t * p, cond_node_t * cn) } /* loop through all possible combinations of values for bools in expression */ - for (test = 0x0; test < (0x1U << cn->nbools); test++) { + for (test = 0x0; test < (UINT32_C(1) << cn->nbools); test++) { /* temporarily set the value for all the bools in the * expression using the corr. bit in test */ for (j = 0; j < cn->nbools; j++) { p->bool_val_to_struct[cn->bool_ids[j] - 1]->state = - (test & (0x1 << j)) ? 1 : 0; + (test & (UINT32_C(1) << j)) ? 1 : 0; } k = cond_evaluate_expr(p, cn->expr); if (k == -1) { @@ -428,7 +428,7 @@ int cond_normalize_expr(policydb_t * p, cond_node_t * cn) } /* set the bit if expression evaluates true */ if (k) - cn->expr_pre_comp |= 0x1 << test; + cn->expr_pre_comp |= UINT32_C(1) << test; } /* restore bool default values */ diff --git a/libsepol/src/link.c b/libsepol/src/link.c index 461d2feb..7512a4d9 100644 --- a/libsepol/src/link.c +++ b/libsepol/src/link.c @@ -1291,10 +1291,10 @@ static int copy_avrule_list(avrule_t * list, avrule_t ** dst, i < module->perm_map_len[cur_perm->tclass - 1]; i++) { - if (!(cur_perm->data & (1U << i))) + if (!(cur_perm->data & (UINT32_C(1) << i))) continue; new_perm->data |= - (1U << + (UINT32_C(1) << (module-> perm_map[cur_perm->tclass - 1][i] - 1)); diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c index 7093d9b7..587ba64a 100644 --- a/libsepol/src/policydb.c +++ b/libsepol/src/policydb.c @@ -4166,7 +4166,7 @@ static sepol_access_vector_t policydb_string_to_av_perm( hashtab_search(tclass_datum->permissions.table, (hashtab_key_t)perm_name); if (perm_datum != NULL) - return 0x1U << (perm_datum->s.value - 1); + return UINT32_C(1) << (perm_datum->s.value - 1); if (tclass_datum->comdatum == NULL) return 0; @@ -4176,7 +4176,7 @@ static sepol_access_vector_t policydb_string_to_av_perm( (hashtab_key_t)perm_name); if (perm_datum != NULL) - return 0x1U << (perm_datum->s.value - 1); + return UINT32_C(1) << (perm_datum->s.value - 1); return 0; } diff --git a/libsepol/src/services.c b/libsepol/src/services.c index 673b3971..3407058f 100644 --- a/libsepol/src/services.c +++ b/libsepol/src/services.c @@ -1213,7 +1213,7 @@ int sepol_string_to_av_perm(sepol_security_class_t tclass, hashtab_search(tclass_datum->permissions.table, perm_name); if (perm_datum != NULL) { - *av = 0x1 << (perm_datum->s.value - 1); + *av = UINT32_C(1) << (perm_datum->s.value - 1); return STATUS_SUCCESS; } @@ -1225,7 +1225,7 @@ int sepol_string_to_av_perm(sepol_security_class_t tclass, perm_name); if (perm_datum != NULL) { - *av = 0x1 << (perm_datum->s.value - 1); + *av = UINT32_C(1) << (perm_datum->s.value - 1); return STATUS_SUCCESS; } out: From patchwork Fri Oct 8 21:10:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 12546473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BE0DC433FE for ; Fri, 8 Oct 2021 21:10:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6813460F9E for ; Fri, 8 Oct 2021 21:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243192AbhJHVMe (ORCPT ); Fri, 8 Oct 2021 17:12:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbhJHVMe (ORCPT ); Fri, 8 Oct 2021 17:12:34 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D410C061570 for ; Fri, 8 Oct 2021 14:10:38 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id 73so10840726qki.4 for ; Fri, 08 Oct 2021 14:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sv+WSIFY9coACSqYRvs/n2rnMq3n/kKESVVqYF0view=; b=HNNkc+lTi7mKAz+XvvonQ7oFiDbYKZAr++TJlWzDxWJZExaXf0Tm47fxRQPADl5EXN roORbeFRwRvWsz7bHTUd/TpEqED7wK/Wn+TS9tHp4btELw8vIIRm/rkaPIrxEYTNutbI DHBArXRvBKcroZqLjrHEuheSgq8bzTUiTo40mxBt++vxpY4Z4ZBifWVFiFO5vfDIczLA 909/QM5chhReFBkQPfLUC1iDk9Xq3z32lXCQ9MbNQTINuDeXZv27lvszMe7GXTSigoFV 6Wm+NxbNPe60xDitsf5QOOYflRbpniodYMqe1M8aD77sYRJgtMYytqPirXoZJ72Fmh1a J9dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sv+WSIFY9coACSqYRvs/n2rnMq3n/kKESVVqYF0view=; b=59v+5dp3qykWYYOywzlfCHp0USYvFyRi5zTM4eWe6JmD9qgBt6glq8zZbqKJjrxErv xQS960rhwSKzm5ihFArri1ZHYFUCTang916o0RFEe3BkmlwVrPqgQaKLphFcoyG7P3xK gWCdLd0kqQ5LKW+WFvB4VsP6Ys7K+iA9J9ryP4N6oBVdsROGhsNGn58FJFGL8VGvp6Yp kLT4j2+d/gOdGBsreO9ZBLttpELDkamzRz2nTPnmGfHpq6WkZM994uVqV4G+kbetRZpF BK/aqUqpCkyg4dopCsXqBgp3gkuY6qYm7nbhdBop7xhqyDyXHdx4Fn5uWEbt8HCfw+Yi 3AjA== X-Gm-Message-State: AOAM532cVfQ90ALrSH9zrcyjgEdURQDRlKsuWJzsNugaL0Q2a5Dmm6Rz U0zdlBN4cx1PjGE9HxYzmWQCbW3ft7w= X-Google-Smtp-Source: ABdhPJwmHTii51wZtfRXphkc8TPAE/ajZo7XbcTi66KCy8okQWzjZ7eRTCvS6y/ZUB/AjKO9yXpZwg== X-Received: by 2002:a37:f902:: with SMTP id l2mr4927140qkj.511.1633727437447; Fri, 08 Oct 2021 14:10:37 -0700 (PDT) Received: from localhost.localdomain (c-73-200-157-122.hsd1.md.comcast.net. [73.200.157.122]) by smtp.gmail.com with ESMTPSA id u9sm332453qta.90.2021.10.08.14.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:10:36 -0700 (PDT) From: James Carter To: selinux@vger.kernel.org Cc: nicolas.iooss@m4x.org, James Carter Subject: [PATCH 2/4] libsepol/cil: Fix potential undefined shifts Date: Fri, 8 Oct 2021 17:10:29 -0400 Message-Id: <20211008211031.393884-2-jwcart2@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008211031.393884-1-jwcart2@gmail.com> References: <20211008211031.393884-1-jwcart2@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org An expression of the form "1 << x" is undefined if x == 31 because the "1" is an int and cannot be left shifted by 31. Instead, use "UINT32_C(1) << x" which will be an unsigned int of at least 32 bits. This bug was found by the secilc-fuzzer. Signed-off-by: James Carter Acked-by: Nicolas Iooss --- libsepol/cil/src/cil_binary.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libsepol/cil/src/cil_binary.c b/libsepol/cil/src/cil_binary.c index ec5f01e5..34dc63c7 100644 --- a/libsepol/cil/src/cil_binary.c +++ b/libsepol/cil/src/cil_binary.c @@ -1225,7 +1225,7 @@ int __perm_str_to_datum(char *perm_str, class_datum_t *sepol_class, uint32_t *da goto exit; } } - *datum |= 1 << (sepol_perm->s.value - 1); + *datum |= UINT32_C(1) << (sepol_perm->s.value - 1); return SEPOL_OK; @@ -1523,7 +1523,7 @@ int cil_avrule_to_policydb(policydb_t *pdb, const struct cil_db *db, struct cil_ /* index of the u32 containing the permission */ #define XPERM_IDX(x) (x >> 5) /* set bits 0 through x-1 within the u32 */ -#define XPERM_SETBITS(x) ((1U << (x & 0x1f)) - 1) +#define XPERM_SETBITS(x) (UINT32_C(1) << (x & 0x1f)) - 1) /* low value for this u32 */ #define XPERM_LOW(x) (x << 5) /* high value for this u32 */ @@ -4760,7 +4760,7 @@ static struct cil_list *cil_classperms_from_sepol(policydb_t *pdb, uint16_t clas cil_list_init(&cp->perms, CIL_PERM); for (i = 0; i < sepol_class->permissions.nprim; i++) { struct cil_perm *perm; - if ((data & (1 << i)) == 0) continue; + if ((data & (UINT32_C(1) << i)) == 0) continue; perm = perm_value_to_cil[class][i+1]; if (!perm) goto exit; cil_list_append(cp->perms, CIL_PERM, perm); From patchwork Fri Oct 8 21:10:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 12546475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41FEDC433EF for ; Fri, 8 Oct 2021 21:10:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A16160F9E for ; Fri, 8 Oct 2021 21:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243252AbhJHVMf (ORCPT ); Fri, 8 Oct 2021 17:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbhJHVMe (ORCPT ); Fri, 8 Oct 2021 17:12:34 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0B10C061570 for ; Fri, 8 Oct 2021 14:10:38 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id m13so6202660qvk.1 for ; Fri, 08 Oct 2021 14:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yNWN4bh0vU2L/RKLTa1BdYrCKf3+K6EHZ5sn2PkLyn4=; b=gj28KluYa3GVUN/d9dcxWyYk6PvobvVZJhrgRXKNhpKiEgaak2vv9oeYVl5SdZGGAv pRm7A8IpI2D4aR4tQ7yxoRGGjKMnGvCV2SxmV6xWHHaDfyV8k/rHLY4OHykAYXRaB60+ I2jU4UE8epqoA7/yhC0UowhBHiMwBqiJSkvpHhntcVEhJyVJVR0mnZMBBppmprcQLWu+ 7zZLLhK3bQKWM6/mhFPSinXlFsJWMx40nMY5Kg2jSRT9McQijLuGgYGPRNY8+8cYTtDc TVQTCyfF9qKbKWdvTA6PXc2m9fCAZ/T4/z111etYb3EENkdH4w07kl36PJu69NeA9Q4j 8dgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yNWN4bh0vU2L/RKLTa1BdYrCKf3+K6EHZ5sn2PkLyn4=; b=tSHVKTRa2pL5DhvWivv18d708W7/SShp4kq+I19X2QumfpWcyqDKJKBBwTWrlGo/Nk b9vkg8mvF9iq1zZD3ZtgBApxF20R1HYVB12f4+gqZV72Pi5Uim5T0V+/Cu0Maj6tE3er xn7CN4ed5MMmM3td8lAVpmOjMV3voFF+TJKkVxpJ9zRJM3ywj97FcYo8OfRcOW0dxr5T q3TrRE74/sNw09j+wgarPmhgpuVGqopdGNZjAKwYCPD2rK+yn8hWOflEnPsrcqIBjN5j 24pCvKzF8/wyKK3GPMIrPY+i6HaP7c1yKLx9ee1KMukYOjU2lRyz0nE/QpZAVy2Z0TG4 V8RA== X-Gm-Message-State: AOAM532JiCmZHynsAF4yRoinc2vWK5Kfmx+S9XimJ6vwg6XR9g1aqNHc 57s00kcuwXOW5hM0tCYKg9m1HBR4cHk= X-Google-Smtp-Source: ABdhPJwK9pG3lVneaOtzUBOKivjKIkuzcDzeHGnFNZ8UgHONgWxwC506DSXkGnvJFIkmxJB9Cd/bhA== X-Received: by 2002:a0c:b30f:: with SMTP id s15mr12003011qve.23.1633727438127; Fri, 08 Oct 2021 14:10:38 -0700 (PDT) Received: from localhost.localdomain (c-73-200-157-122.hsd1.md.comcast.net. [73.200.157.122]) by smtp.gmail.com with ESMTPSA id u9sm332453qta.90.2021.10.08.14.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:10:37 -0700 (PDT) From: James Carter To: selinux@vger.kernel.org Cc: nicolas.iooss@m4x.org, James Carter Subject: [PATCH 3/4] checkpolicy: Fix potential undefined shifts Date: Fri, 8 Oct 2021 17:10:30 -0400 Message-Id: <20211008211031.393884-3-jwcart2@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008211031.393884-1-jwcart2@gmail.com> References: <20211008211031.393884-1-jwcart2@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org An expression of the form "1 << x" is undefined if x == 31 because the "1" is an int and cannot be left shifted by 31. Instead, use "UINT32_C(1) << x" which will be an unsigned int of at least 32 bits. Signed-off-by: James Carter --- checkpolicy/checkpolicy.c | 2 +- checkpolicy/policy_define.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/checkpolicy/checkpolicy.c b/checkpolicy/checkpolicy.c index 6740c6d4..926ce72c 100644 --- a/checkpolicy/checkpolicy.c +++ b/checkpolicy/checkpolicy.c @@ -794,7 +794,7 @@ int main(int argc, char **argv) case 0: printf("\nallowed {"); for (i = 1; i <= sizeof(avd.allowed) * 8; i++) { - if (avd.allowed & (1 << (i - 1))) { + if (avd.allowed & (UINT32_C(1) << (i - 1))) { v.val = i; ret = hashtab_map(cladatum-> diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c index cda3337b..d3eb6111 100644 --- a/checkpolicy/policy_define.c +++ b/checkpolicy/policy_define.c @@ -2126,7 +2126,7 @@ static int define_te_avtab_xperms_helper(int which, avrule_t ** rule) policydbp->p_class_val_to_name[i]); continue; } else { - cur_perms->data |= 1U << (perdatum->s.value - 1); + cur_perms->data |= UINT32_C(1) << (perdatum->s.value - 1); } } @@ -2142,7 +2142,7 @@ out: /* index of the u32 containing the permission */ #define XPERM_IDX(x) ((x) >> 5) /* set bits 0 through x-1 within the u32 */ -#define XPERM_SETBITS(x) ((1U << ((x) & 0x1f)) - 1) +#define XPERM_SETBITS(x) ((UINT32_C(1) << ((x) & 0x1f)) - 1) /* low value for this u32 */ #define XPERM_LOW(x) ((x) << 5) /* high value for this u32 */ @@ -2612,7 +2612,7 @@ static int define_te_avtab_helper(int which, avrule_t ** rule) } continue; } else { - cur_perms->data |= 1U << (perdatum->s.value - 1); + cur_perms->data |= UINT32_C(1) << (perdatum->s.value - 1); } next: cur_perms = cur_perms->next; @@ -3615,7 +3615,7 @@ int define_constraint(constraint_expr_t * expr) return -1; } } - node->permissions |= (1 << (perdatum->s.value - 1)); + node->permissions |= (UINT32_C(1) << (perdatum->s.value - 1)); } free(id); } From patchwork Fri Oct 8 21:10:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Carter X-Patchwork-Id: 12546477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3D39C4332F for ; Fri, 8 Oct 2021 21:10:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD48260F5E for ; Fri, 8 Oct 2021 21:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243261AbhJHVMf (ORCPT ); Fri, 8 Oct 2021 17:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbhJHVMf (ORCPT ); Fri, 8 Oct 2021 17:12:35 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B020FC061570 for ; Fri, 8 Oct 2021 14:10:39 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id ay35so2031513qkb.10 for ; Fri, 08 Oct 2021 14:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wif+ppgPYXztMvb7yzrli0enkiBCtR1mqSF5JOtF2dI=; b=pnnoJfMtbwOxH0150A2VdovFur/cPooOhrabjcxIEI0hiPLmJTpB2zmjLpQKjElkNy Fetz7fN/WUJFgzw3rVSPmw3wuZqUaFBmqVKsWWTTBoHil1mIFzqKNEaeH+Swqi1MX0iC UXMpbPztdI9yEqU5Ro91v8rqsExvqWyHDXZ7MKfgood2nnKBO9PFiPhha/gSrZVOoSDc tw2Uml+S9KKp1F+pso0VvYG6dpJG15rxlFC9kVqUQ+KMdn+wuXjzKhbmHKTFQacm8s7h wYonWmcDg/8OODPq5dRq4uY9RtCEg1Fooetj+V6TqFB40QUKiGlhdwH7/9iNnLh84evS +ZfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wif+ppgPYXztMvb7yzrli0enkiBCtR1mqSF5JOtF2dI=; b=y4M6PAI7m2UDqh5hufrIS+nDam3POD2tfZI4PZXOZzfOOcKucovXOhFg20mBt1jj++ fUYcnm+qQDkThd+EpWcJb3XpQK66AAnvovfyPSvcMbMvD71kkOc6jT/2hlyhxS1rt1Zg //jRY8M0RKzAxMOYLNO0hidkP0Tarcujqn1QGv3vFpa6SL8vdddMso2VHwG1nL6FFKRl Q0t4RoXrbXkbwrsaB1vQAdkKD8mfrgayZ5BFm7OMFAQtrOArgAyecz+nz0p5/TBGUpU/ JTJpDS2TgLqSUXfnWbt6jEs/c7ttO4H7S7v+tZ7QcV7R+h2AtqmSIWlVGAwlX6C5VNh3 xZeQ== X-Gm-Message-State: AOAM5338J32HWIZIfOlIuBsSOmFN8jNrn4rquiASq+ookDou4eMnazJS VeYZ6JiwY4ew+IRLfKCf6pyRYpIv5CU= X-Google-Smtp-Source: ABdhPJxcFwGpomOuoHXbBRjWW47VzcErnXRUWUii7QfEE717ERWMyZX1UQYZ1wvdgwUWrIwr6Bd8kQ== X-Received: by 2002:a05:620a:5f7:: with SMTP id z23mr4803891qkg.198.1633727438745; Fri, 08 Oct 2021 14:10:38 -0700 (PDT) Received: from localhost.localdomain (c-73-200-157-122.hsd1.md.comcast.net. [73.200.157.122]) by smtp.gmail.com with ESMTPSA id u9sm332453qta.90.2021.10.08.14.10.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:10:38 -0700 (PDT) From: James Carter To: selinux@vger.kernel.org Cc: nicolas.iooss@m4x.org, James Carter Subject: [PATCH 4/4] libselinux: Fix potential undefined shifts Date: Fri, 8 Oct 2021 17:10:31 -0400 Message-Id: <20211008211031.393884-4-jwcart2@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008211031.393884-1-jwcart2@gmail.com> References: <20211008211031.393884-1-jwcart2@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org An expression of the form "1 << x" is undefined if x == 31 because the "1" is an int and cannot be left shifted by 31. Instead, use "UINT32_C(1) << x" which will be an unsigned int of at least 32 bits. Signed-off-by: James Carter --- libselinux/src/mapping.c | 22 +++++++++++----------- libselinux/src/stringrep.c | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libselinux/src/mapping.c b/libselinux/src/mapping.c index 96395fd4..dd2f1039 100644 --- a/libselinux/src/mapping.c +++ b/libselinux/src/mapping.c @@ -144,9 +144,9 @@ unmap_perm(security_class_t tclass, access_vector_t tperm) access_vector_t kperm = 0; for (i = 0; i < current_mapping[tclass].num_perms; i++) - if (tperm & (1<allowed & mapping->perms[i]) - result |= 1<perms[i]) - result |= 1<allowed = result; for (i = 0, result = 0; i < n; i++) { if (avd->decided & mapping->perms[i]) - result |= 1<perms[i]) - result |= 1<decided = result; for (i = 0, result = 0; i < n; i++) if (avd->auditallow & mapping->perms[i]) - result |= 1<auditallow = result; for (i = 0, result = 0; i < n; i++) { if (avd->auditdeny & mapping->perms[i]) - result |= 1<perms[i]) - result |= 1<auditdeny = result; } } diff --git a/libselinux/src/stringrep.c b/libselinux/src/stringrep.c index 012a740a..2fe69f43 100644 --- a/libselinux/src/stringrep.c +++ b/libselinux/src/stringrep.c @@ -229,7 +229,7 @@ access_vector_t string_to_av_perm(security_class_t tclass, const char *s) size_t i; for (i = 0; i < MAXVECTORS && node->perms[i] != NULL; i++) if (strcmp(node->perms[i],s) == 0) - return map_perm(tclass, 1<perms[i]; return NULL; @@ -279,7 +279,7 @@ int security_av_string(security_class_t tclass, access_vector_t av, char **res) /* first pass computes the required length */ for (i = 0; tmp; tmp >>= 1, i++) { if (tmp & 1) { - str = security_av_perm_to_string(tclass, av & (1<>= 1, i++) { if (tmp & 1) { - str = security_av_perm_to_string(tclass, av & (1<