From patchwork Fri May 12 09:29:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13238942 X-Patchwork-Delegate: plautrba@redhat.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AB43C77B7C for ; Fri, 12 May 2023 09:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240164AbjELJaK (ORCPT ); Fri, 12 May 2023 05:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbjELJaJ (ORCPT ); Fri, 12 May 2023 05:30:09 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E816D8 for ; Fri, 12 May 2023 02:30:08 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-50bd2d7ba74so87486865a12.1 for ; Fri, 12 May 2023 02:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1683883807; x=1686475807; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=8EBCVPZ4ojH9zBDKq1crcPMevnTTfX0aXVLhJKQUVjM=; b=IA8GfZ+AyLVBerTfJ+xm9n0Uye83Aerqvpnl85j15Z8IYUUhO+FqQeTd12s9dRRIcF F99JbqTCYBqgyZRtol0VGCSJFkCGVH7j2T6ctgt9uexOtl2GSxF4FRqmVhiu5ZSeYTfT AN+4iLNxhQrqzZrpRL3rT7gqfWRIxQX8CzFoHWcYbQpK2gwhzrV/O7HsEKw5oi6XMMYL Zk+BEtTI+WqO4WC3x1wibYZBhcbPZpMC4wUHpywDGzxUe3Z8vv8OPk6tL2zmmPHJq+kZ EEdn5JH6lgQwaa5hPgNSQYKsxitoI2aW4hNXXCISncKvqioG5pPCv5xpkOSTxAZ+EgoW 4OXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683883807; x=1686475807; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8EBCVPZ4ojH9zBDKq1crcPMevnTTfX0aXVLhJKQUVjM=; b=WctO4TUN4Y6q7mr8ClhpMT1oB2TcQFpg2MN/I+IrqTqgScWeGnJ1k9AkpHid8YTJza CAKHW8WTihahuSyBm3L7HiFKQB722AksJj7zjDTt9BhAIkwNv1iuVV38QNGfnkq4CaVa kmHQEO0wNCTCXyw25ZYUh4ID7CUYI+x1xl4qdag9GMjJ0IdS9sWUp2Qx/F1EfxJVLED6 gu+909Pg3i9510a8cYd3BZFNERBguJHjdxyqBJVUdu228nldwrgppTn22RTID2lZuqrU XdBPtfVbr+NJ/CVQ8JzsL8SIlthjdqARioXyHDJ2cTrQvXXgsFrdZhqo1IIZ8kNeE9sH SCxQ== X-Gm-Message-State: AC+VfDxpErnUVyNTnnv7r9fcazCIy5zh/hOKB7oZZ5I7lrV8i+RtZ1xQ ilTzKh86PpkT3pbULkhbt5dCrje+tf6uGw== X-Google-Smtp-Source: ACHHUZ4sPfhT6a7IbzoakMr4KYhmGgX5Dimldl8lrDz1hYcnorynErQcGshECpjvDhzM/cZryPg4Eg== X-Received: by 2002:a17:906:da8c:b0:94a:653b:ba41 with SMTP id xh12-20020a170906da8c00b0094a653bba41mr7921015ejb.15.1683883806770; Fri, 12 May 2023 02:30:06 -0700 (PDT) Received: from debianHome.localdomain (dynamic-095-116-181-041.95.116.pool.telefonica.de. [95.116.181.41]) by smtp.gmail.com with ESMTPSA id tc19-20020a1709078d1300b00969f2d5267asm4636356ejc.114.2023.05.12.02.30.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 02:30:05 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 1/5] libsepol: validate some object contexts Date: Fri, 12 May 2023 11:29:57 +0200 Message-Id: <20230512093001.49208-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Ensure various object context entries have a name, since they are duplicated via strdup(3), and the order for ports and memory regions is valid. Signed-off-by: Christian Göttsche Acked-by: James Carter --- libsepol/src/policydb_validate.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c index 301aa200..e0d290ff 100644 --- a/libsepol/src/policydb_validate.c +++ b/libsepol/src/policydb_validate.c @@ -1149,6 +1149,8 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, valid case OCON_NETIF: if (validate_context(&octx->context[1], flavors, p->mls)) goto bad; + if (!octx->u.name) + goto bad; break; case OCON_PORT: if (octx->u.port.low_port > octx->u.port.high_port) @@ -1163,6 +1165,34 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, valid default: goto bad; } + if (!octx->u.name) + goto bad; + break; + case OCON_IBPKEY: + if (octx->u.ibpkey.low_pkey > octx->u.ibpkey.high_pkey) + goto bad; + break; + case OCON_IBENDPORT: + if (!octx->u.ibendport.dev_name) + goto bad; + break; + } + } else if (p->target_platform == SEPOL_TARGET_XEN) { + switch(i) { + case OCON_XEN_IOPORT: + if (octx->u.ioport.low_ioport > octx->u.ioport.high_ioport) + goto bad; + break; + case OCON_XEN_IOMEM: + if (octx->u.iomem.low_iomem > octx->u.iomem.high_iomem) + goto bad; + if (p->policyvers < POLICYDB_VERSION_XEN_DEVICETREE && octx->u.iomem.high_iomem > 0xFFFFFFFFULL) + goto bad; + break; + case OCON_XEN_DEVICETREE: + if (!octx->u.name) + goto bad; + break; } } } From patchwork Fri May 12 09:29:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13238943 X-Patchwork-Delegate: plautrba@redhat.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F328C77B75 for ; Fri, 12 May 2023 09:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240311AbjELJaL (ORCPT ); Fri, 12 May 2023 05:30:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231767AbjELJaK (ORCPT ); Fri, 12 May 2023 05:30:10 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 606A3EA for ; Fri, 12 May 2023 02:30:09 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-50bc1612940so17483500a12.2 for ; Fri, 12 May 2023 02:30:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1683883808; x=1686475808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=r+VSt7J7nLm19MMKo+1ALSSpQAvSm18sJcPCcmx8kgU=; b=pv6eNqZ8A3ZT7ZVVkeVXiwdqmU1LGDKa+TlWAaTjIv4/LPR4ngHf2Z00UTYaR5wFV2 c7IGre/UgYstRVtTXJRfu73fWqX7iUPh+GzX0nWt2fuoqJRqjHgWZ4RGxmmSRfQJNfa/ oeUNXKXzNjxAs4s+QMudOxYuvsvC/+sxuAD0F5t11hDmr8Z81/6jJWXXfl0ckmohMA+g f0AyJXQ1tnJTf8h1rW5/KDlxZUhiy/EP707o1S8Yzgz/zg3Jb3r0A0vzrHl/5GGIE+yu D0E/438c25Li2fvmxfhU8DsBl3pHfn3O4dcJy+ObqOt+82nzWxl1HftVBVMOBDC16Fj+ oEcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683883808; x=1686475808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r+VSt7J7nLm19MMKo+1ALSSpQAvSm18sJcPCcmx8kgU=; b=XNcQulwGd8hygg6yyglR9RMoqvRSTP72jCFk9Dt8K8QumjVtue1yxSAyQYBDjLMayn CLS65OplNVKmDnhQH+8RknQRywKvj8VtLufYy6pUibMY2tOMbJAqxPzY8/mG4QxD8qMf Gqrd6maNhjcuaDny3DRqDy9yeMuCZzntnkbezbJN2gXghraMJlAX3oEa5BevbqeBw2dr PbImdAPO9tTy4fmfDl3vITJiTj7lmnzEB7kvoHZuz3f6/CHYltVTa9mjmEewqEK1SNEA NG7kyAFDHjI9wIRzRKD/V1ofxQ2VTFUpepQ8oJHodBsi7YaHhUKV7Gpe7PDVO9sgPA+t qq6Q== X-Gm-Message-State: AC+VfDyLAAGu7kH8tHm6fnPT3WD+XnX32vfKmdPg/T6Vsfe7nDPsPpj3 cmBfy8Ueq57TqWIYLUUWshqVHnSEwr1D2w== X-Google-Smtp-Source: ACHHUZ7j23YtplhDMLTCmIpAWiNbYS7yt2O9nsLUAuE/VeiHKJ4MaxFPcYtNhYXaUeNhGzrUcXm/Zg== X-Received: by 2002:a17:906:9b8b:b0:96a:7de4:dd24 with SMTP id dd11-20020a1709069b8b00b0096a7de4dd24mr3469006ejc.66.1683883807670; Fri, 12 May 2023 02:30:07 -0700 (PDT) Received: from debianHome.localdomain (dynamic-095-116-181-041.95.116.pool.telefonica.de. [95.116.181.41]) by smtp.gmail.com with ESMTPSA id tc19-20020a1709078d1300b00969f2d5267asm4636356ejc.114.2023.05.12.02.30.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 02:30:07 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 2/5] libsepol: validate old style range trans classes Date: Fri, 12 May 2023 11:29:58 +0200 Message-Id: <20230512093001.49208-2-cgzones@googlemail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512093001.49208-1-cgzones@googlemail.com> References: <20230512093001.49208-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org For old style range transition rules the class defaults to process. However the policy might not declare the process class leading to setting a wrong bit later on via: if (ebitmap_set_bit(&rtr->tclasses, rt->target_class - 1, 1)) UBSAN report: policydb.c:3684:56: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'uint32_t' (aka 'unsigned int') Signed-off-by: Christian Göttsche --- libsepol/src/policydb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c index b79c19b9..605d290a 100644 --- a/libsepol/src/policydb.c +++ b/libsepol/src/policydb.c @@ -3650,10 +3650,10 @@ static int range_read(policydb_t * p, struct policy_file *fp) if (rc < 0) goto err; rt->target_class = le32_to_cpu(buf[0]); - if (!value_isvalid(rt->target_class, p->p_classes.nprim)) - goto err; } else rt->target_class = p->process_class; + if (!value_isvalid(rt->target_class, p->p_classes.nprim)) + goto err; r = calloc(1, sizeof(*r)); if (!r) goto err; From patchwork Fri May 12 09:29:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13238944 X-Patchwork-Delegate: plautrba@redhat.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22978C7EE24 for ; Fri, 12 May 2023 09:30:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231767AbjELJaM (ORCPT ); Fri, 12 May 2023 05:30:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbjELJaL (ORCPT ); Fri, 12 May 2023 05:30:11 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4475BD8 for ; Fri, 12 May 2023 02:30:10 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-965a68abfd4so1834099566b.2 for ; Fri, 12 May 2023 02:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1683883809; x=1686475809; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=P0If2pepsqik4t85PEHjhB90HWHLvXo9jxqnqdDSP4U=; b=P0a4u7V+4y4ySa+ALLMYkXbFLZVikIAorte0VIOezVhmSXnDTPs6SlxEWU71kEXuC3 hDbj8WeSCagNa1bMrGUa7d/rTnxWcqeupoZ/+wy/cfLRYuOrvnRbAFW+GdMepN6ZA4Md /mHxt46yqxxqnzI4syugYsv88EF9Sdh9xrIwSkaPegY/vtCFydU6L3qwD0Aqa07hHcxp mZD+dUf9G3TrffcP7Az6NoeLsZQEpM5+xcCFHK6COLRE+CcS8AXiJx7IKkbKfHZvLtk0 Lwv4TyMtRPrBTJ2phMjb6l4Ss6kSA8Va4cZUfsMQQsC485xrkvOob++hMLLH4lZnMKlL VpcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683883809; x=1686475809; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P0If2pepsqik4t85PEHjhB90HWHLvXo9jxqnqdDSP4U=; b=cIKf4u8tvj1LFYG69lYME2eMXrw/Way3e2VEQCNzZHOrLFW39hXxhHbAXgCWln0U8i xLNKGEEimMgdeNrMT8NNj239tEzTmrz/v9Q/+rgDONkt+RSEVaP435bvuI+3iNxIcx+h Fc0ui1DhTEoyCMsFMXKX6ve7V2PzyzY0AoIOBINmHz1rF8wIMENJAx0vBMPCk0xjjRXi XKsoOpkXie1U2hwDyLGOsZEIXY19amANyC8b/alUiHsp4lNSTyuSqsGTmT+0+6EoDTlV 6jLzhEdl7dEVR3zno11VmRsfsjavmeKxkPIzXbliudb2wjXnzYl14JXY0GHTGTHL4o3u xE+Q== X-Gm-Message-State: AC+VfDzce7WJLEzeEMkfwEdL7HZb53qLujnxQAAglnc2C7MsycoSLbOs d9FrGPwL5xonz/aItx+25uhgEeChTh6uBQ== X-Google-Smtp-Source: ACHHUZ6nYuBHQ/uIiZjiFSJz4C6yfbRFIH04wv4EMe6dpDQ8k/T0RdM/XeKL9Qr95EC6u6nI24fmYw== X-Received: by 2002:a17:907:2d0c:b0:966:5c04:2c5a with SMTP id gs12-20020a1709072d0c00b009665c042c5amr16945747ejc.69.1683883808576; Fri, 12 May 2023 02:30:08 -0700 (PDT) Received: from debianHome.localdomain (dynamic-095-116-181-041.95.116.pool.telefonica.de. [95.116.181.41]) by smtp.gmail.com with ESMTPSA id tc19-20020a1709078d1300b00969f2d5267asm4636356ejc.114.2023.05.12.02.30.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 02:30:07 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 3/5] libsepol: validate: check low category is not bigger than high Date: Fri, 12 May 2023 11:29:59 +0200 Message-Id: <20230512093001.49208-3-cgzones@googlemail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512093001.49208-1-cgzones@googlemail.com> References: <20230512093001.49208-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Signed-off-by: Christian Göttsche --- libsepol/src/policydb_validate.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c index e0d290ff..b34f83ec 100644 --- a/libsepol/src/policydb_validate.c +++ b/libsepol/src/policydb_validate.c @@ -545,6 +545,8 @@ static int validate_mls_semantic_cat(const mls_semantic_cat_t *cat, const valida goto bad; if (validate_value(cat->high, cats)) goto bad; + if (cat->low > cat->high) + goto bad; } return 0; From patchwork Fri May 12 09:30:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13238945 X-Patchwork-Delegate: plautrba@redhat.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1D73C77B7C for ; Fri, 12 May 2023 09:30:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbjELJaN (ORCPT ); Fri, 12 May 2023 05:30:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240331AbjELJaM (ORCPT ); Fri, 12 May 2023 05:30:12 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDDB8F7 for ; Fri, 12 May 2023 02:30:10 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-9659e9bbff5so1776457266b.1 for ; Fri, 12 May 2023 02:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1683883809; x=1686475809; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6q9LwskrCelAeYHCmxT4xjuIKOqph/7licKqVLZWj1M=; b=It5XRjXaY4wJm1IAU/mDBfmLuj4raHE0mFcrcfb37ZsMj2+rXB9zlFpCj9RJrN6kMN kVfOgLkiGcOTwzmHseygvMDgeodLLVAG0iuiAG3rIJBF+jkdhp00CaZ23WOoXf+ARXuu fa8jYeWYwxqEWLNprqvZuVsQksN1yRJyuwURr6jTIS5ykBrzQ929rHc5JqiI1Em0KcbU vS7rt7TV1h3fc87KR5pQ0zccq5qPlwMgUoUmG1PKW/p4k7K39E2DsfAd2n20H23RnUSk xx28uyDmCeJAi+jgmQLokSjZ9i5GmmwlOA5+D4aGR/GvsbPnM7KbswG+TbHFYYTrf4OA tzRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683883809; x=1686475809; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6q9LwskrCelAeYHCmxT4xjuIKOqph/7licKqVLZWj1M=; b=dJD9c7p0t+o1QV9OPu0O02xvkyZ7/fYcvPnqc4ZaKQkSwhHkLQZImlCUludrlpIigL 9NFE2oskCA/i5tqEMvG3V8tayUEy1E3EaXG9h8zixaEgjyR4BlPPU6YzolSCTsvaNXts 0xMnL54/pzSqYGI6cNU3Bm8SQ7KSHMINghFjjhfc5PQCjpbd6rVQ75UBBsAMGRqNj7CF GWWfOrT/5Tx6F3cuU4H54oKVNI0HWXLKBlogbshtBkq6Xl7wbzr3RTGQty15igEgfjE2 my3+cpVGGiQbZm5FWpMUzXvoeE+ag4PRT/YHdD2F/Jqz2QQ3lSOwoeU9rE5874xcWgSM 5DAw== X-Gm-Message-State: AC+VfDy4wCqvB59MqZQeqWSMosmNrT0x8kSggLP1UpORAo2L2kO7XwMx Xk4VfT59+HK402bpj2RRGmiEhm3cTPaPvA== X-Google-Smtp-Source: ACHHUZ7/G0NzyP7NIO5/KBhkWyDerId3p+3+vMdXOQnTOOZVceNtHjOzD9jl/ppxsUzi3uEbe9pkIw== X-Received: by 2002:a17:907:368a:b0:94e:13e9:3926 with SMTP id bi10-20020a170907368a00b0094e13e93926mr22055425ejc.19.1683883809294; Fri, 12 May 2023 02:30:09 -0700 (PDT) Received: from debianHome.localdomain (dynamic-095-116-181-041.95.116.pool.telefonica.de. [95.116.181.41]) by smtp.gmail.com with ESMTPSA id tc19-20020a1709078d1300b00969f2d5267asm4636356ejc.114.2023.05.12.02.30.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 02:30:08 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 4/5] libsepol: validate: reject XEN policy with xperm rules Date: Fri, 12 May 2023 11:30:00 +0200 Message-Id: <20230512093001.49208-4-cgzones@googlemail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512093001.49208-1-cgzones@googlemail.com> References: <20230512093001.49208-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org XEN policies with extended permissions are not supported, e.g. writing them will fail (see write.c:avrule_write()). Signed-off-by: Christian Göttsche --- libsepol/src/policydb_validate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c index b34f83ec..3540f34a 100644 --- a/libsepol/src/policydb_validate.c +++ b/libsepol/src/policydb_validate.c @@ -799,6 +799,8 @@ static int validate_avtab_key(const avtab_key_t *key, int conditional, const pol case AVTAB_XPERMS_ALLOWED: case AVTAB_XPERMS_AUDITALLOW: case AVTAB_XPERMS_DONTAUDIT: + if (p->target_platform != SEPOL_TARGET_SELINUX) + goto bad; if (conditional) goto bad; break; @@ -910,6 +912,8 @@ static int validate_avrules(sepol_handle_t *handle, const avrule_t *avrule, int } if (avrule->specified & AVRULE_XPERMS) { + if (p->target_platform != SEPOL_TARGET_SELINUX) + goto bad; if (!avrule->xperms) goto bad; switch (avrule->xperms->specified) { From patchwork Fri May 12 09:30:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13238946 X-Patchwork-Delegate: plautrba@redhat.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A73BC7EE25 for ; Fri, 12 May 2023 09:30:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240336AbjELJaO (ORCPT ); Fri, 12 May 2023 05:30:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240334AbjELJaN (ORCPT ); Fri, 12 May 2023 05:30:13 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEAF4EA for ; Fri, 12 May 2023 02:30:11 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-94a342f7c4cso1739015066b.0 for ; Fri, 12 May 2023 02:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1683883810; x=1686475810; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=t7fAFrJi6g0l5X8kikH/00TL4391NKpMBCM8Yjjpch8=; b=Swmtq8+tmMkflCgpxeZ0cQYuoTQjV4RLKlEZ9+SMCV2XBxRLY/myoL7jb8De9au6BF Qel3y9NFGuG4EV7ky9MVrcHcqURClPPti62SBOTHq3T6Eite2TBbOFYcMGcF9N6/9eR0 /vVri3dZ9x72KGSVgyRO4My33b9y8+Wlo/WZNdUhVa9Nrwtux/fygDWc6CVRyQuppGua 0UN/MwTqLExYKvB4biWpupAZ1BGLU6/sbXxnBGsCXOCn8mLmUhHopCuaAmL/pfpJZN6x LpV8ldXzU/KswHZhXokwJniAPGquTLrOibErk4JH9LPV2KD+3mmETtGjwgNmmKd3xNRD yIng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683883810; x=1686475810; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t7fAFrJi6g0l5X8kikH/00TL4391NKpMBCM8Yjjpch8=; b=Ja+/f7zkciFRit1VCsGvU4V+i7tiw/aiSg99IiLDcGOzkFtW6mkbkz+u5aLcU90cK4 kUfByfHOIGqUYCABnAxjlFBvsAxXW/2i3bQBkdev2wO6yMTC93qd5XV3IFNvOb6TWOWP XeIdn/g0S+z07IPKFgtDP6L+ThPaRgjks4tLMqTazwQVc3yTZkiEtM7CarlC1uSF+5Oy mfpkRWafoSRxnWOOD3MNeewzXYRiOagLkISOHRMV0s/0wzymPVjfZl3Xaa8iGR232T8t aqGrIIh7e+dePQAo0sFssXp25heBLrDTVoMXOt2wIM/J904G4hitXfiN6Qt62ZlOjYt1 Ye5A== X-Gm-Message-State: AC+VfDz6PUuH32EDbkiU7TGBSyc27+RvXtRlfrDNvdHEaOvchQK3I0p/ zHY7jUmN8o57ZgFLfIKommclRZra2aw5ew== X-Google-Smtp-Source: ACHHUZ72tJg1cHxaR7Vp0rtlViW/swx/SKEq7YLBa+gY9k2dMpUz1Q/WZ5NnSb+yogAzx6qjT6u0vg== X-Received: by 2002:a17:906:974b:b0:957:943e:7416 with SMTP id o11-20020a170906974b00b00957943e7416mr24514180ejy.15.1683883810168; Fri, 12 May 2023 02:30:10 -0700 (PDT) Received: from debianHome.localdomain (dynamic-095-116-181-041.95.116.pool.telefonica.de. [95.116.181.41]) by smtp.gmail.com with ESMTPSA id tc19-20020a1709078d1300b00969f2d5267asm4636356ejc.114.2023.05.12.02.30.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 02:30:09 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 5/5] libsepol: expand: skip invalid cat Date: Fri, 12 May 2023 11:30:01 +0200 Message-Id: <20230512093001.49208-5-cgzones@googlemail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512093001.49208-1-cgzones@googlemail.com> References: <20230512093001.49208-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Bail out on expanding levels with invalid low category. UBSAN report: expand.c:952:21: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'uint32_t' (aka 'unsigned int') Signed-off-by: Christian Göttsche --- libsepol/src/expand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsepol/src/expand.c b/libsepol/src/expand.c index c08d3a35..8795229a 100644 --- a/libsepol/src/expand.c +++ b/libsepol/src/expand.c @@ -943,7 +943,7 @@ int mls_semantic_level_expand(mls_semantic_level_t * sl, mls_level_t * l, return -1; } for (cat = sl->cat; cat; cat = cat->next) { - if (cat->low > cat->high) { + if (!cat->low || cat->low > cat->high) { ERR(h, "Category range is not valid %s.%s", p->p_cat_val_to_name[cat->low - 1], p->p_cat_val_to_name[cat->high - 1]);