From patchwork Wed Nov 1 16:38:28 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: 13442915 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 807C6C4332F for ; Wed, 1 Nov 2023 16:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343951AbjKAQil (ORCPT ); Wed, 1 Nov 2023 12:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344048AbjKAQik (ORCPT ); Wed, 1 Nov 2023 12:38:40 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72B84111 for ; Wed, 1 Nov 2023 09:38:34 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-5230a22cfd1so12160352a12.1 for ; Wed, 01 Nov 2023 09:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1698856713; x=1699461513; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=3tx2QOnzAxBCHzl4Tm9cho3HgpSgaUw+gqI0Kv9GR60=; b=dZVNojZ2G1ozwgrPS7Rd/DC2VO8l4MPNURgk5rP7B1mJfc2SxfuYGdTw7O+LshuIUN ae0ZtOshpBpY3ph3lpWWWcYW34yhTnyKXG/pflftozUyfV1zW+4WBBf6GP637bBaKwt7 98y94ebBRHk87UxMQxhto+yO5WiE7hT7y+liFjEfN7CoAmj0CsxMvs0LQ9e7eJaeub6y 2AiEDm6+dz4eDZTRBcO9kSyGHYjxG6MxMZc5SpLa3dS9B06cAdSdwJMUXwOs2FYm4vP0 YAIm1FQhZjkyTa+FyImX35muCJ2i95IQJ8mWJzoJKHTKWl8nUwSt8Y7IHVA/sdXVD5hn 9wwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698856713; x=1699461513; 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=3tx2QOnzAxBCHzl4Tm9cho3HgpSgaUw+gqI0Kv9GR60=; b=XM0ly9eIFDY0dYgozBCSV7boHLh9vD8ETDSBqRYFw5hGHJwWYWgtjvcH2TjodhSgjV pxyd1EhmtGfzMTHiAdLTE6XULA3NJPq3r7xpdilr3KoC07M9oAh7Nb+Z4RdI+z6bn9XN OO7zHq3Z9gLKxMWT8dYWD4D2X5nu4+L4Y8TDxQXHdSgvMSA5a2RJgH4KzYKzM2qLDqqE 6yIQEuEydtPuLk4Mg+RpobqjRtAVwvSriWQ8bTVUps2AtsteZz2HBEHfcEOgqr1uFMU3 y3bmDBKXt/y5qt3hkv4Od0PJ5RpYpKMeWb4KWYzOfYltWmn2GB5QdiAeYqu/XPQLUI/b 2KMQ== X-Gm-Message-State: AOJu0Yxlb6Aky3WZdeeFvTq7a5VSj9fISYbKeqyhkPHyGYmC6712nJiJ WyK+GAoGBI9W1p2LwyHJLRpSnDYKQkI= X-Google-Smtp-Source: AGHT+IHoRuULoCxFyJvk7IdIYN8biMJPFNyh9DXKJtbAhYbXpricpeHnAjfCoVpy1lED5dOJKiymYw== X-Received: by 2002:a50:8e58:0:b0:543:3df8:cc95 with SMTP id 24-20020a508e58000000b005433df8cc95mr6761445edx.9.1698856712765; Wed, 01 Nov 2023 09:38:32 -0700 (PDT) Received: from debian_development.DebianHome (dynamic-095-116-163-023.95.116.pool.telefonica.de. [95.116.163.23]) by smtp.gmail.com with ESMTPSA id j8-20020a50ed08000000b0053eb9af1e15sm1245939eds.77.2023.11.01.09.38.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 09:38:32 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 1/3] libsepol: validate default type of transition is not an attribute Date: Wed, 1 Nov 2023 17:38:28 +0100 Message-ID: <20231101163830.177769-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org The default type of a type transition must be a regular type, not an attribute. Signed-off-by: Christian Göttsche --- libsepol/src/policydb_validate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c index 892a0ffd..d214bf09 100644 --- a/libsepol/src/policydb_validate.c +++ b/libsepol/src/policydb_validate.c @@ -1105,7 +1105,7 @@ static int validate_filename_trans(hashtab_key_t k, hashtab_datum_t d, void *arg for (; ftd; ftd = ftd->next) { if (validate_ebitmap(&ftd->stypes, &flavors[SYM_TYPES])) goto bad; - if (validate_value(ftd->otype, &flavors[SYM_TYPES])) + if (validate_simpletype(ftd->otype, &flavors[SYM_TYPES])) goto bad; } From patchwork Wed Nov 1 16:38:29 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: 13442916 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 655EBC4167D for ; Wed, 1 Nov 2023 16:38:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344130AbjKAQim (ORCPT ); Wed, 1 Nov 2023 12:38:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344200AbjKAQik (ORCPT ); Wed, 1 Nov 2023 12:38:40 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 542BC119 for ; Wed, 1 Nov 2023 09:38:35 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5094727fa67so27694e87.3 for ; Wed, 01 Nov 2023 09:38:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1698856713; x=1699461513; darn=vger.kernel.org; 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=MvB5GTFv9yaEX00MVskrhNJZC9Z66fAa3nJW1huXJU0=; b=YhowgKhTk+gQ/erVld7BOSTyaFwcBhn8pWCJy2tGFhWbqm+R9rm9kJbjQOa3FOjjwU ARkWosFROdvVnReASItYWRuSFa03YjsnTEn6MWiacUcGr+Vclq/+Tv54j5RQ2F27cbzr pwr1mMOfLfFBAePh0JCEITsUKVjm2e2xwtfk4xk4nTxw5ZP4CzSxyhy91v3a/ATBKCbA +q08GwSkzSRXtPOnNCZiBcYqA4adUjhXefM7jGiWjjjksx8q0DihhedPJKu/3ARCycIY zcKZH6cMcIUQBTkW04fcbsYmClix7urgEUawyRiiRGi2ucG9pOBuZ6eL4Q5t9i6Ck4qY 5r/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698856713; x=1699461513; 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=MvB5GTFv9yaEX00MVskrhNJZC9Z66fAa3nJW1huXJU0=; b=r8m9Xfm5WEUDlA/ocijM8lg4A9vtTreI6q72gFOhhWznMcISHUUfDe6lOiCo+N0cXZ ytod3LfGmjw/BfZ28s/ZcSo6xESImCoBMmADA/KkAkAlrSEH3k1/jk5Yhtx/57vMvkDo l+HvV+sZ5FMxEMyBQNAMQkbFciTrpQCEVET6yRAhVOeYS0cgzuvZCZmy3tTW1hPlGli0 F5hpx3xaUw49PkFHo/nF84GLUnKwKEUtomn3WTdeYwjHHQ1n5m+Kc8nkcyaMb5AJHQJk 11aM7iKDYpcmwFOmJwqFAHPvHHc1aRg1S6tXdyvygHrJbUz4GenhJJk6f5HLaUasI3Yl /Lqw== X-Gm-Message-State: AOJu0Yx8Clpi9miN3ZcdEGIqXpC+dz+PBzO+7G+85YhLYf3hd/xAPr+5 hNef9dcTN5cL0/g9fuT/lStOyikjuus= X-Google-Smtp-Source: AGHT+IHLpQYZhFPAryVjD7vq8KtcW437ebqmhmzDW6zUsp1dB6C+IWHyGsJb5BGBeTqYkSAsofyzrQ== X-Received: by 2002:a19:6d1b:0:b0:507:95ea:1e72 with SMTP id i27-20020a196d1b000000b0050795ea1e72mr10600937lfc.22.1698856713279; Wed, 01 Nov 2023 09:38:33 -0700 (PDT) Received: from debian_development.DebianHome (dynamic-095-116-163-023.95.116.pool.telefonica.de. [95.116.163.23]) by smtp.gmail.com with ESMTPSA id j8-20020a50ed08000000b0053eb9af1e15sm1245939eds.77.2023.11.01.09.38.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 09:38:33 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 2/3] libsepol: validate constraint depth Date: Wed, 1 Nov 2023 17:38:29 +0100 Message-ID: <20231101163830.177769-2-cgzones@googlemail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231101163830.177769-1-cgzones@googlemail.com> References: <20231101163830.177769-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Ensure constraint expressions are complete and do not exceed the supported depth limit. Signed-off-by: Christian Göttsche Acked-by: James Carter --- libsepol/src/policydb_validate.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c index d214bf09..c6a66fb3 100644 --- a/libsepol/src/policydb_validate.c +++ b/libsepol/src/policydb_validate.c @@ -228,6 +228,7 @@ bad: static int validate_constraint_nodes(sepol_handle_t *handle, unsigned int nperms, const constraint_node_t *cons, validate_t flavors[]) { const constraint_expr_t *cexp; + int depth; for (; cons; cons = cons->next) { if (nperms == 0 && cons->permissions != 0) @@ -240,8 +241,14 @@ static int validate_constraint_nodes(sepol_handle_t *handle, unsigned int nperms if (!cons->expr) goto bad; + depth = -1; + for (cexp = cons->expr; cexp; cexp = cexp->next) { if (cexp->expr_type == CEXPR_NAMES) { + if (depth >= (CEXPR_MAXDEPTH - 1)) + goto bad; + depth++; + if (cexp->attr & CEXPR_XTARGET && nperms != 0) goto bad; if (!(cexp->attr & CEXPR_TYPE)) { @@ -282,6 +289,10 @@ static int validate_constraint_nodes(sepol_handle_t *handle, unsigned int nperms goto bad; } } else if (cexp->expr_type == CEXPR_ATTR) { + if (depth >= (CEXPR_MAXDEPTH - 1)) + goto bad; + depth++; + if (!ebitmap_is_empty(&cexp->names)) goto bad; if (validate_empty_type_set(cexp->type_names)) @@ -318,8 +329,14 @@ static int validate_constraint_nodes(sepol_handle_t *handle, unsigned int nperms } else { switch (cexp->expr_type) { case CEXPR_NOT: + if (depth < 0) + goto bad; + break; case CEXPR_AND: case CEXPR_OR: + if (depth < 1) + goto bad; + depth--; break; default: goto bad; @@ -335,6 +352,9 @@ static int validate_constraint_nodes(sepol_handle_t *handle, unsigned int nperms goto bad; } } + + if (depth != 0) + goto bad; } return 0; From patchwork Wed Nov 1 16:38:30 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: 13442914 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 F3901C4167B for ; Wed, 1 Nov 2023 16:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344209AbjKAQil (ORCPT ); Wed, 1 Nov 2023 12:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344158AbjKAQik (ORCPT ); Wed, 1 Nov 2023 12:38:40 -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 8B46B11B for ; Wed, 1 Nov 2023 09:38:35 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-543456dbd7bso2124388a12.1 for ; Wed, 01 Nov 2023 09:38:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1698856714; x=1699461514; darn=vger.kernel.org; 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=b2ZBmBt3OVeECFdp5EaVDChMvH4meeSVzpOCcU+vBac=; b=Xnt5PKt0Xmu3WeqlZPmxj/hpLx8/+sLpZmpmcqlnNmi6cOGCkChNp3t3JkhiE694Yy EhBZtiNbnLEJFddUZfb8ufb8RCbK+R8XCdDOVHPSzN1ms2imqkcLeYn0HPEVXUjmKwYY REXwnns8Dn1qs2d41qdnpind6WMX3OzvN6w8hdd/BmtfKX820pXuVqXfkVk6hXjTrbUr mVG0rVJiT7IVsSwj5tXihUAYR6vYG4kmQk4Uuqn4jQjj2I92GBy5tTdNmXuLZB/d0Se2 6gEYCfKTsit1wg6DpATGzIzMo+ZowEprFpf41aAyFKV8U/4MT0mKbuzwm8Sf0cGDoVyh EBXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698856714; x=1699461514; 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=b2ZBmBt3OVeECFdp5EaVDChMvH4meeSVzpOCcU+vBac=; b=V7Cv5MYtAq5p1RypYOH80WvTSq1xe4Yp1owgMtHWuktGCMIijmhvsZgYZCvEj3JAkm ro2EQhxwTqEPXrdmu6hW7pK+h5I8DzM0JlVj82BbLbaIqpqbA5NaYRA4vQaqKAV5CBNW w29Lzohi+++dYzcm7gtoQYSKyU7K5VyXyc43/fd/I+3gDhz8wEKHXrqr3GGfBL1v89/T cJYhdeRheyfk74lNPE39qr+ocBQjWhRI7rzOVuj5/yOMUbJOxcKPN17fxnahCdnulq3f 1dh7qS0gFZqUxGQrv4hKK63IweY7e1Pqb2MsylcMWfX2YZ1hUEC22mLRwvavwXAaRumv uWbw== X-Gm-Message-State: AOJu0YzJKUNFqOko6zgLcQHVrwNJmeLxyfh4o0fFXUpRVHUzlQWvPL1J jRNowsjeV16fbRcm9Khz0h7YR5HcWA4= X-Google-Smtp-Source: AGHT+IGE63R1EhqgugVjBsR46netgBzGW37Ux0zhI+FCbHDOmBm3Hsx+CJUnrxGgx/wmJXbvw+pO+A== X-Received: by 2002:aa7:c711:0:b0:540:16be:6562 with SMTP id i17-20020aa7c711000000b0054016be6562mr2977127edq.15.1698856713900; Wed, 01 Nov 2023 09:38:33 -0700 (PDT) Received: from debian_development.DebianHome (dynamic-095-116-163-023.95.116.pool.telefonica.de. [95.116.163.23]) by smtp.gmail.com with ESMTPSA id j8-20020a50ed08000000b0053eb9af1e15sm1245939eds.77.2023.11.01.09.38.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 09:38:33 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Subject: [PATCH 3/3] libsepol: more strict validation Date: Wed, 1 Nov 2023 17:38:30 +0100 Message-ID: <20231101163830.177769-3-cgzones@googlemail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231101163830.177769-1-cgzones@googlemail.com> References: <20231101163830.177769-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Ensure the ibendport port is not 0 (similar to the kernel). More general depth test for boolean expressions. Ensure the boolean id is not set for logic operators. Signed-off-by: Christian Göttsche Acked-by: James Carter --- libsepol/src/policydb_validate.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c index c6a66fb3..0e4805ef 100644 --- a/libsepol/src/policydb_validate.c +++ b/libsepol/src/policydb_validate.c @@ -1002,13 +1002,15 @@ static int validate_cond_expr(sepol_handle_t *handle, const struct cond_expr *ex case COND_BOOL: if (validate_value(expr->boolean, boolean)) goto bad; - if (depth == (COND_EXPR_MAXDEPTH - 1)) + if (depth >= (COND_EXPR_MAXDEPTH - 1)) goto bad; depth++; break; case COND_NOT: if (depth < 0) goto bad; + if (expr->boolean != 0) + goto bad; break; case COND_OR: case COND_AND: @@ -1017,6 +1019,8 @@ static int validate_cond_expr(sepol_handle_t *handle, const struct cond_expr *ex case COND_NEQ: if (depth < 1) goto bad; + if (expr->boolean != 0) + goto bad; depth--; break; default: @@ -1199,6 +1203,8 @@ static int validate_ocontexts(sepol_handle_t *handle, const policydb_t *p, valid goto bad; break; case OCON_IBENDPORT: + if (octx->u.ibendport.port == 0) + goto bad; if (!octx->u.ibendport.dev_name) goto bad; break;