From patchwork Thu Feb 17 14:21:29 2022 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: 12750259 X-Patchwork-Delegate: paul@paul-moore.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 71486C433EF for ; Thu, 17 Feb 2022 14:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234301AbiBQOW0 (ORCPT ); Thu, 17 Feb 2022 09:22:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:37694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241869AbiBQOWV (ORCPT ); Thu, 17 Feb 2022 09:22:21 -0500 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 1BE6D2B04B0; Thu, 17 Feb 2022 06:22:06 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id a23so7695568eju.3; Thu, 17 Feb 2022 06:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TKbGn4VnF077K/SNeC7jeA3ji+PgaLkDsV1uHuyFEfY=; b=fMCq3oJKasAOWtpeLVeqCXkK0BfuPeMwW6ID7eddz+BiIEjdIGBx+QMb2Rwiy7u6zC FF9EHKhjOBvuJb0HNkSoagqHn7e1Wd4wMYcVlXcLEDrRpAq5s4AtlccEhFsHmavLbQji lQicA5GQ4gceDNgEzhk1k7qBVcv0+8SFhko4adSuKdcmgcqvQfuHOG+yTwySBgHgidI5 ehDDLTsdvSESJ4pSX+eNrveJaPF2kpwWXUiZXsClRvUy8Q9L56qxIboJQpsAHovYCmoF BT8V7UegXGkcEOhKqexxf42jeeDprq2CRYAleWdRN9iUjGtrzAClxuwhwph9oD3Ht5/I nOeA== 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=TKbGn4VnF077K/SNeC7jeA3ji+PgaLkDsV1uHuyFEfY=; b=BUmxak+CtOnWE8VOho330DJ33tccwuQ0j3k6n747Vh1n1FCltNlXXAdsgIHQznm5nv p4OlqPeFDVG5fHfIPTbQVSVec9174b0E99xnqVgym7YAdrG94Jgg0AVyMQABJNi/XBb3 5Fp9ft5ji+o6XqvrHs8s27NSpJ0lZPvGoV+KVIBYPw2Q3bReWQw4VooHAFk3wdl4AQgh 3CuHbGzXVq2wAxoJp8i7EG0bfvFKc3pAzZ+gCC1t4Fi1JWBqoynqel47FBHoYhyOsZFg Iw0Gp57ilL5tBhCV9rwGFWqphbqdsFfkL2NASbfOB4q+BOGc9oz55gklcOlc1O7baaIJ +1PQ== X-Gm-Message-State: AOAM532k+zqbz6+0T+u30doxNqggoE1S4QprVhKR+U2Tx5ID8czR1yh6 N6hHIWF4iXPiCtzxfG9dVVFP33iZhnrFeQ== X-Google-Smtp-Source: ABdhPJzHeZ1hq4tKV6RQC0asfUmX6vcSGs/AyrEZloRCSL1Vm0if9C3k5Ms1jH8RgaG5n8S6RYs+WA== X-Received: by 2002:a17:906:c282:b0:6ce:369d:3d5 with SMTP id r2-20020a170906c28200b006ce369d03d5mr2584779ejz.425.1645107724616; Thu, 17 Feb 2022 06:22:04 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-001-066-240.77.1.pool.telefonica.de. [77.1.66.240]) by smtp.gmail.com with ESMTPSA id a13sm578436edn.25.2022.02.17.06.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 06:22:04 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , Nathan Chancellor , Nick Desaulniers , Ondrej Mosnacek , Serge Hallyn , Yang Li , Austin Kim , Lakshmi Ramasubramanian , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 1/5] selinux: drop return statement at end of void functions Date: Thu, 17 Feb 2022 15:21:29 +0100 Message-Id: <20220217142133.72205-5-cgzones@googlemail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220217142133.72205-1-cgzones@googlemail.com> References: <20220217142133.72205-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Those return statements at the end of a void function are redundant. Reported by clang-tidy [readability-redundant-control-flow] Signed-off-by: Christian Göttsche --- security/selinux/hooks.c | 2 -- security/selinux/ss/conditional.c | 2 -- security/selinux/ss/ebitmap.c | 1 - security/selinux/ss/mls.c | 1 - security/selinux/ss/services.c | 2 -- 5 files changed, 8 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index dafabb4dcc64..1e69f88eb326 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3284,8 +3284,6 @@ static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name, isec->sid = newsid; isec->initialized = LABEL_INITIALIZED; spin_unlock(&isec->lock); - - return; } static int selinux_inode_getxattr(struct dentry *dentry, const char *name) diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index 2ec6e5cd25d9..c46c419af512 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -566,8 +566,6 @@ void cond_compute_xperms(struct avtab *ctab, struct avtab_key *key, if (node->key.specified & AVTAB_ENABLED) services_compute_xperms_decision(xpermd, node); } - return; - } /* Determine whether additional permissions are granted by the conditional * av table, and if so, add them to the result diff --git a/security/selinux/ss/ebitmap.c b/security/selinux/ss/ebitmap.c index 61fcbb8d0f88..abde349c8321 100644 --- a/security/selinux/ss/ebitmap.c +++ b/security/selinux/ss/ebitmap.c @@ -359,7 +359,6 @@ void ebitmap_destroy(struct ebitmap *e) e->highbit = 0; e->node = NULL; - return; } int ebitmap_read(struct ebitmap *e, void *fp) diff --git a/security/selinux/ss/mls.c b/security/selinux/ss/mls.c index 3f5fd124342c..99571b19d4a9 100644 --- a/security/selinux/ss/mls.c +++ b/security/selinux/ss/mls.c @@ -156,7 +156,6 @@ void mls_sid_to_context(struct policydb *p, } *scontext = scontextp; - return; } int mls_level_isvalid(struct policydb *p, struct mls_level *l) diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 2f8db93e53b2..6901dc07680d 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -529,8 +529,6 @@ static void security_dump_masked_av(struct policydb *policydb, /* release scontext/tcontext */ kfree(tcontext_name); kfree(scontext_name); - - return; } /* From patchwork Thu Feb 17 14:21:25 2022 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: 12750255 X-Patchwork-Delegate: paul@paul-moore.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 BC969C433EF for ; Thu, 17 Feb 2022 14:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231313AbiBQOWA (ORCPT ); Thu, 17 Feb 2022 09:22:00 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:36348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241848AbiBQOV7 (ORCPT ); Thu, 17 Feb 2022 09:21:59 -0500 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 3EEC3294133; Thu, 17 Feb 2022 06:21:43 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id a23so7692764eju.3; Thu, 17 Feb 2022 06:21:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pszNuayq3uAwPjpzq/uwyInszVpNCtaI4non2ruEen8=; b=EzWUOMPttCGG5Yg3G3nXzK6cU6fkvWMUdfJ1CNKVYIofnQ8MBABhzHGcjpeaFGveKU 1OJ87QrSEX1uuPUc7BJfeIXXIytBzZXFv4LINWFVY4q0nOBh21i+Dm+TNrqGBcP6ILHL RYij2xEsD4K9kfiKIPn1kgvc5FXRqQJe3rsjuiXcLRwTgOEY8S7C5EP47XiYxycZvsQX tsBHRGZih1VxQ8SDY14SgZdLKxYb6uPxBy9oA9ytoZh6iBNdvdycVP8Shj7JdvFwV3aL UaZfCHoIRd/1OXv2XTyFj0JQvyUlRQ2nvRshbjkDNpVEAMTxb0OOkGByWao2Bj/kbnqT ErnQ== 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=pszNuayq3uAwPjpzq/uwyInszVpNCtaI4non2ruEen8=; b=XUiOc69KuUXk3MjYuVhhMfvuWVD60tEvQtHYYfXJE0ofvcHgn0CCBW8t9lxj25pyLh qULHLOofS/il9LXwSKi2Yqk03+w4Y7KI/cE+w7kNeY8Msh27ZR8dv3GDZPaq9Eaq9xyU GZGFzh9/BNRFes9mdCCM3dlOhOA0AqVoL3Q/r2vhwKiu4rXqTbINM005wX/YHe25Qehd 6hhXTBChGPa23IQOVKDQVf7Q0G1+2cExGkZCMaMmjIJDQTL1ujP0nI4NXVtK8hrp6LGr wTMMFIGWCKJ5gPiVxTTTBsLUZ3kznnQ9mDKagZDYxfTFbLauUMxEB2h9/Dyl7e0nt1Xr bVzw== X-Gm-Message-State: AOAM531BeaiNgW4PiYv9LXW4WQLtxVMOe15lPmSYCc2IOkRi4P5phJ/C mgPKU+5P2GNxODcIQBxXG9DXO06ZUL8GkA== X-Google-Smtp-Source: ABdhPJwa0W7mI8nYQ7LIYGYeZKKRoW7ww/i5hwmuOBPRPmWmW0gWn5Vc8PxZZvea3wi00KlNvupvhQ== X-Received: by 2002:a17:906:c08a:b0:6ce:36f8:bfe8 with SMTP id f10-20020a170906c08a00b006ce36f8bfe8mr2553503ejz.52.1645107701726; Thu, 17 Feb 2022 06:21:41 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-001-066-240.77.1.pool.telefonica.de. [77.1.66.240]) by smtp.gmail.com with ESMTPSA id a13sm578436edn.25.2022.02.17.06.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 06:21:41 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , Nathan Chancellor , Nick Desaulniers , Ondrej Mosnacek , Austin Kim , Kees Cook , Yang Li , Casey Schaufler , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 2/5] selinux: use correct type for context length Date: Thu, 17 Feb 2022 15:21:25 +0100 Message-Id: <20220217142133.72205-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org security_sid_to_context() expects a pointer to an u32 as the address where to store the length of the computed context. Reported by sparse: security/selinux/xfrm.c:359:39: warning: incorrect type in argument 4 (different signedness) security/selinux/xfrm.c:359:39: expected unsigned int [usertype] *scontext_len security/selinux/xfrm.c:359:39: got int * Signed-off-by: Christian Göttsche --- security/selinux/xfrm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/selinux/xfrm.c b/security/selinux/xfrm.c index 90697317895f..c576832febc6 100644 --- a/security/selinux/xfrm.c +++ b/security/selinux/xfrm.c @@ -347,7 +347,7 @@ int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x, int rc; struct xfrm_sec_ctx *ctx; char *ctx_str = NULL; - int str_len; + u32 str_len; if (!polsec) return 0; From patchwork Thu Feb 17 14:21:26 2022 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: 12750256 X-Patchwork-Delegate: paul@paul-moore.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 8D9F9C433EF for ; Thu, 17 Feb 2022 14:21:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241422AbiBQOWG (ORCPT ); Thu, 17 Feb 2022 09:22:06 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:36504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241834AbiBQOWD (ORCPT ); Thu, 17 Feb 2022 09:22:03 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39C2D294133; Thu, 17 Feb 2022 06:21:48 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id vz16so7807550ejb.0; Thu, 17 Feb 2022 06:21:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EuHmUQyH6qnHd858RqknP0s0QcJF0aPYhchgl7zVC2A=; b=a/cRpJjYorSNEhv8rgzuuwu8DtqJBBjyo6H/urhBzQeA8gCrmajvBkEHM7if60gNmo 2UhRRWooKMiMJ9joFoQRdXTMAQZCrFUroZuBnUTi0oYCGwMI792kPeYppaccmY0thftX LXMC0uCUt4Xyw5YvGFTzgxlZ/kWlk7UGIiXXLxekUjCJq3XUFmBiDj3yW+zTLDPQ4N5R gp6aGQvov4zzK47ZsNnCDl+9ZRn7LURFYAk8JqeVI5jY3tdS5ZZraNv8t3BISmCWvAax 49qJ5LTGcp9GKqPzdNnrQiJaiwl2Slcuh+0Md+vvG3fCAs/1SFNYVZF5za0LSllI7RjJ FYXg== 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=EuHmUQyH6qnHd858RqknP0s0QcJF0aPYhchgl7zVC2A=; b=mniax30NFeTvOdghrrIq6BeNJQVq7wmzggd3PHnwyxvw4n5w5rRkUzDD9pt1ERU42U PcFS0mMblOy7bkRnWXWIR7Kg167lj45b3HScKWNi555XGCkTwy5Bb5BKjg9lUbV6TC8E I/Y89GozK5RRAkiLz/FOyXpTCOHicr3KxKJEDuytBhRJ5wGUS9VpxRpiUHw/vz9idBZp qs1rF8q9+iUsrkTkp1OS6l+clEv90AwtGECw12jNHyc9J8EDIGSdZWFj20RS7ncWKRPQ 6CXOmrx61wFb+10E1KavkRyO5LWJxV3bBVW5YuiMnqBGEu5byJ6yw4y3EgcSH8pb0hzV coDQ== X-Gm-Message-State: AOAM531QMBoht7wD4sNeydCJq1xM4phWWiTNFyl+XUvJoloO1M2Z++Hy VsWaiCwnGv534xul43dbKDFuH+ow9LVY4A== X-Google-Smtp-Source: ABdhPJxTYJvXI6TOu7Yyy7Lxd7Q0QAwjxFNf0pSk+WK3sVTcBhx4oOQ5Q+ZQQ7967AqOazORGuxVew== X-Received: by 2002:a17:907:9956:b0:6b9:a6d9:a535 with SMTP id kl22-20020a170907995600b006b9a6d9a535mr2533960ejc.64.1645107706743; Thu, 17 Feb 2022 06:21:46 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-001-066-240.77.1.pool.telefonica.de. [77.1.66.240]) by smtp.gmail.com with ESMTPSA id a13sm578436edn.25.2022.02.17.06.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 06:21:46 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , Nathan Chancellor , Nick Desaulniers , Ondrej Mosnacek , James Morris , Austin Kim , Casey Schaufler , Jiapeng Chong , Yang Li , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 3/5] selinux: use consistent pointer types for boolean arrays Date: Thu, 17 Feb 2022 15:21:26 +0100 Message-Id: <20220217142133.72205-2-cgzones@googlemail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220217142133.72205-1-cgzones@googlemail.com> References: <20220217142133.72205-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Use a consistent type of unsigned int* for boolean arrays, instead of using implicit casts to and from int*. Reported by sparse: security/selinux/selinuxfs.c:1481:30: warning: incorrect type in assignment (different signedness) security/selinux/selinuxfs.c:1481:30: expected unsigned int * security/selinux/selinuxfs.c:1481:30: got int *[addressable] values security/selinux/selinuxfs.c:1398:48: warning: incorrect type in argument 3 (different signedness) security/selinux/selinuxfs.c:1398:48: expected int *values security/selinux/selinuxfs.c:1398:48: got unsigned int *bool_pending_values Signed-off-by: Christian Göttsche --- A more invasive change would be to change all boolean arrays to bool*. --- security/selinux/include/conditional.h | 4 ++-- security/selinux/selinuxfs.c | 2 +- security/selinux/ss/services.c | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/security/selinux/include/conditional.h b/security/selinux/include/conditional.h index b09343346e3f..9e65aa409318 100644 --- a/security/selinux/include/conditional.h +++ b/security/selinux/include/conditional.h @@ -14,9 +14,9 @@ #include "security.h" int security_get_bools(struct selinux_policy *policy, - u32 *len, char ***names, int **values); + u32 *len, char ***names, unsigned int **values); -int security_set_bools(struct selinux_state *state, u32 len, int *values); +int security_set_bools(struct selinux_state *state, u32 len, unsigned int *values); int security_get_bool_value(struct selinux_state *state, u32 index); diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index f2f6203e0fff..5216a321bbb0 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -1428,7 +1428,7 @@ static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_ struct inode_security_struct *isec; char **names = NULL, *page; u32 i, num; - int *values = NULL; + unsigned int *values = NULL; u32 sid; ret = -ENOMEM; diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 6901dc07680d..7865926962ab 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -3023,7 +3023,7 @@ int security_fs_use(struct selinux_state *state, struct super_block *sb) } int security_get_bools(struct selinux_policy *policy, - u32 *len, char ***names, int **values) + u32 *len, char ***names, unsigned int **values) { struct policydb *policydb; u32 i; @@ -3045,7 +3045,7 @@ int security_get_bools(struct selinux_policy *policy, goto err; rc = -ENOMEM; - *values = kcalloc(*len, sizeof(int), GFP_ATOMIC); + *values = kcalloc(*len, sizeof(unsigned int), GFP_ATOMIC); if (!*values) goto err; @@ -3075,7 +3075,7 @@ int security_get_bools(struct selinux_policy *policy, } -int security_set_bools(struct selinux_state *state, u32 len, int *values) +int security_set_bools(struct selinux_state *state, u32 len, unsigned int *values) { struct selinux_policy *newpolicy, *oldpolicy; int rc; @@ -3175,7 +3175,8 @@ int security_get_bool_value(struct selinux_state *state, static int security_preserve_bools(struct selinux_policy *oldpolicy, struct selinux_policy *newpolicy) { - int rc, *bvalues = NULL; + int rc; + unsigned int *bvalues = NULL; char **bnames = NULL; struct cond_bool_datum *booldatum; u32 i, nbools = 0; From patchwork Thu Feb 17 14:21:27 2022 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: 12750257 X-Patchwork-Delegate: paul@paul-moore.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 D54C3C433FE for ; Thu, 17 Feb 2022 14:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238946AbiBQOWO (ORCPT ); Thu, 17 Feb 2022 09:22:14 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:37236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241834AbiBQOWN (ORCPT ); Thu, 17 Feb 2022 09:22:13 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9D562B1663; Thu, 17 Feb 2022 06:21:57 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id lw4so7619919ejb.12; Thu, 17 Feb 2022 06:21:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uzAjuvuRezKyO/SVp83DwWN6oZxDOTQaXqLmt6YXjzE=; b=LHvSh8IaM6IhY+1/xnC7+iup0QTMkQxAnANF1Cg2sZM4XoogiBvEJSzrFxgaqKLHOe lRreAZvNDUMFfAo5Pu/7jLYCUV8jlEFa4+eCGqtU+NIOuX/kUExBEd+f4Z+LZGSKe0cN pU2P3cyppD2X6JkObg6kl52ZfZ/Ob5zHJnZlJ2z3yY+BJ5NiRcRRs2c2LUJyPmDiJjBv C8z0NQqMgsPagkxrAJjMtmCRhmqPHAEYkYKj0FCSRYkxydFwyJNXAOqnP+U7N2hN7cSX Vz5btmgnKObw7jMlGvxzRgfjp8kNsBfILB1B51ywokK1KSwWNq2644WzOh+zws/HptwS 2xaw== 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=uzAjuvuRezKyO/SVp83DwWN6oZxDOTQaXqLmt6YXjzE=; b=GEYKwM3apSSlIieKICZfZXKQppjf948EkZ+sqARKNfU78Pts6rb4o5Bz69IDuFeoNz 1T+sPaGVfWooDa9auQJqpur44tux4GVhQQAkkSjLraImRAgKZMbS7bWTEfWPeCPIe6TD 5MgpYNWeFlE6U5eTR/VATsRsWQNVZhettBWRFVZ942na7vsQLTpZ2nUupMB91vjySjom l6Tyyr7HHH4ft6lpsx/6yfrPe85I6kSxd1y6nn9LS8/77WXKhkVSjgrlp4Ok/Q+hgZ6b 6/BDCac6m/hOTPg690GWSb5IrwM0FyTYhHsJuRRYaWJT5TfGc/bBOM/afBf31X3F3qhj /LQg== X-Gm-Message-State: AOAM531SP2CnG5GJzvwqL/q9Ag3h1QtMREeoc8cNqZJh1+YeSEL/h/We DeCXZ9S2ZWVkJ59Z+MVnypFayfBycm97wA== X-Google-Smtp-Source: ABdhPJxG9vIvZ6Wb0ffgnDvshkhUw4k6RsPKnE9YL7PdUc/nsZqTnNlQBPe5tektEvwu/gC1POUfPA== X-Received: by 2002:a17:906:7711:b0:6ce:51b:a5a1 with SMTP id q17-20020a170906771100b006ce051ba5a1mr2464110ejm.610.1645107716221; Thu, 17 Feb 2022 06:21:56 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-001-066-240.77.1.pool.telefonica.de. [77.1.66.240]) by smtp.gmail.com with ESMTPSA id a13sm578436edn.25.2022.02.17.06.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 06:21:55 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , Nathan Chancellor , Nick Desaulniers , Ondrej Mosnacek , Jeremy Kerr , "David S. Miller" , Lakshmi Ramasubramanian , Yang Li , Austin Kim , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 4/5] selinux: declare data arrays const Date: Thu, 17 Feb 2022 15:21:27 +0100 Message-Id: <20220217142133.72205-3-cgzones@googlemail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220217142133.72205-1-cgzones@googlemail.com> References: <20220217142133.72205-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org The arrays for the policy capability names, the initial sid identifiers and the class and permission names are not changed at runtime. Declare them const to avoid accidental modification. The build time script genheaders needs to be exempted, since it converts the entries to uppercase. Signed-off-by: Christian Göttsche --- scripts/selinux/genheaders/genheaders.c | 2 ++ scripts/selinux/mdp/mdp.c | 4 ++-- security/selinux/avc.c | 2 +- security/selinux/include/avc_ss.h | 2 +- security/selinux/include/classmap.h | 8 +++++++- security/selinux/include/initial_sid_to_string.h | 9 ++++++++- security/selinux/include/policycap.h | 2 +- security/selinux/include/policycap_names.h | 2 +- security/selinux/ss/services.c | 4 ++-- 9 files changed, 25 insertions(+), 10 deletions(-) diff --git a/scripts/selinux/genheaders/genheaders.c b/scripts/selinux/genheaders/genheaders.c index f355b3e0e968..5f7c0b7d9260 100644 --- a/scripts/selinux/genheaders/genheaders.c +++ b/scripts/selinux/genheaders/genheaders.c @@ -15,6 +15,8 @@ struct security_class_mapping { const char *perms[sizeof(unsigned) * 8 + 1]; }; +/* Allow to convert entries in mappings to uppercase */ +#define __SELINUX_GENHEADERS__ #include "classmap.h" #include "initial_sid_to_string.h" diff --git a/scripts/selinux/mdp/mdp.c b/scripts/selinux/mdp/mdp.c index 105c1c31a316..1415604c3d24 100644 --- a/scripts/selinux/mdp/mdp.c +++ b/scripts/selinux/mdp/mdp.c @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) /* print out the class permissions */ for (i = 0; secclass_map[i].name; i++) { - struct security_class_mapping *map = &secclass_map[i]; + const struct security_class_mapping *map = &secclass_map[i]; fprintf(fout, "class %s\n", map->name); fprintf(fout, "{\n"); for (j = 0; map->perms[j]; j++) @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) #define SYSTEMLOW "s0" #define SYSTEMHIGH "s1:c0.c1" for (i = 0; secclass_map[i].name; i++) { - struct security_class_mapping *map = &secclass_map[i]; + const struct security_class_mapping *map = &secclass_map[i]; fprintf(fout, "mlsconstrain %s {\n", map->name); for (j = 0; map->perms[j]; j++) diff --git a/security/selinux/avc.c b/security/selinux/avc.c index abcd9740d10f..020985a53d8f 100644 --- a/security/selinux/avc.c +++ b/security/selinux/avc.c @@ -668,7 +668,7 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a) struct common_audit_data *ad = a; struct selinux_audit_data *sad = ad->selinux_audit_data; u32 av = sad->audited; - const char **perms; + const char *const *perms; int i, perm; audit_log_format(ab, "avc: %s ", sad->denied ? "denied" : "granted"); diff --git a/security/selinux/include/avc_ss.h b/security/selinux/include/avc_ss.h index 88c384c5c09e..b38974e22d81 100644 --- a/security/selinux/include/avc_ss.h +++ b/security/selinux/include/avc_ss.h @@ -18,7 +18,7 @@ struct security_class_mapping { const char *perms[sizeof(u32) * 8 + 1]; }; -extern struct security_class_mapping secclass_map[]; +extern const struct security_class_mapping secclass_map[]; #endif /* _SELINUX_AVC_SS_H_ */ diff --git a/security/selinux/include/classmap.h b/security/selinux/include/classmap.h index 35aac62a662e..07ade4af85ff 100644 --- a/security/selinux/include/classmap.h +++ b/security/selinux/include/classmap.h @@ -2,6 +2,12 @@ #include #include +#ifdef __SELINUX_GENHEADERS__ +# define const_qual +#else +# define const_qual const +#endif + #define COMMON_FILE_SOCK_PERMS "ioctl", "read", "write", "create", \ "getattr", "setattr", "lock", "relabelfrom", "relabelto", "append", "map" @@ -38,7 +44,7 @@ * Note: The name for any socket class should be suffixed by "socket", * and doesn't contain more than one substr of "socket". */ -struct security_class_mapping secclass_map[] = { +const_qual struct security_class_mapping secclass_map[] = { { "security", { "compute_av", "compute_create", "compute_member", "check_context", "load_policy", "compute_relabel", diff --git a/security/selinux/include/initial_sid_to_string.h b/security/selinux/include/initial_sid_to_string.h index 5d332aeb8b6c..915283cd89bd 100644 --- a/security/selinux/include/initial_sid_to_string.h +++ b/security/selinux/include/initial_sid_to_string.h @@ -1,5 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0 */ -static const char *initial_sid_to_string[] = + +#ifdef __SELINUX_GENHEADERS__ +# define const_qual +#else +# define const_qual const +#endif + +static const char *const_qual initial_sid_to_string[] = { NULL, "kernel", diff --git a/security/selinux/include/policycap.h b/security/selinux/include/policycap.h index 2ec038efbb03..3207a4e8c899 100644 --- a/security/selinux/include/policycap.h +++ b/security/selinux/include/policycap.h @@ -15,6 +15,6 @@ enum { }; #define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1) -extern const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX]; +extern const char *const selinux_policycap_names[__POLICYDB_CAPABILITY_MAX]; #endif /* _SELINUX_POLICYCAP_H_ */ diff --git a/security/selinux/include/policycap_names.h b/security/selinux/include/policycap_names.h index b89289f092c9..51da36e37d21 100644 --- a/security/selinux/include/policycap_names.h +++ b/security/selinux/include/policycap_names.h @@ -5,7 +5,7 @@ #include "policycap.h" /* Policy capability names */ -const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX] = { +const char *const selinux_policycap_names[__POLICYDB_CAPABILITY_MAX] = { "network_peer_controls", "open_perms", "extended_socket_class", diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 7865926962ab..25c287324059 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -99,7 +99,7 @@ static void context_struct_compute_av(struct policydb *policydb, struct extended_perms *xperms); static int selinux_set_mapping(struct policydb *pol, - struct security_class_mapping *map, + const struct security_class_mapping *map, struct selinux_map *out_map) { u16 i, j; @@ -121,7 +121,7 @@ static int selinux_set_mapping(struct policydb *pol, /* Store the raw class and permission values */ j = 0; while (map[j].name) { - struct security_class_mapping *p_in = map + (j++); + const struct security_class_mapping *p_in = map + (j++); struct selinux_mapping *p_out = out_map->mapping + j; /* An empty class string skips ahead */ From patchwork Thu Feb 17 14:21:28 2022 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: 12750258 X-Patchwork-Delegate: paul@paul-moore.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 EE6F2C433FE for ; Thu, 17 Feb 2022 14:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241860AbiBQOWR (ORCPT ); Thu, 17 Feb 2022 09:22:17 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:37404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241855AbiBQOWQ (ORCPT ); Thu, 17 Feb 2022 09:22:16 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2F7B294132; Thu, 17 Feb 2022 06:22:01 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id m17so9839871edc.13; Thu, 17 Feb 2022 06:22:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8lKeT6/UwWXU+14STiDc02KgAuvLL0ArwI0Frgd9EJw=; b=FlvAtUwO9YvUfW2tiTjSUFjqP6r5Zvow5Jf60Yn1lt0jY6ng0M96E1qBVauRtVuYeQ /G63Z/9GUdt5oPZ7aDya7mYs97HHt7vcsg/2ypUnTof0zuocG5es4bPh43yeNObQztOR XaIMtzSw6kqgbKxLvSWLsM9rzl5GaWJUwzBH0cn04sbluPY+w4WGlGvDR3Qv5E/Hl/RE 1L9M5mrIsgRbQas2XI0lF0Xu8aAsPp32O3HvTsRmT0SyuSFhQZ9pHQ4V52ttJSgKz45D oZJVHYa2nsxdtXMk+xhF4EZkok2vqBEdC24bmZje5mcfRnYHsS28rd4k/Iw8XTaNC8yE WREw== 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=8lKeT6/UwWXU+14STiDc02KgAuvLL0ArwI0Frgd9EJw=; b=aXq1opdrXKuM5RnlZZHUv6u1hRYIh8huQb9jtCQNwvh4W53sDof3x9cBtN7qWLJp7U BuzZXLsUuLKB9Bw9+U4Ailu1bo502J/7KWYJqodQaQbMLaat0ptfCVNdgk+UaQ60nzCb zWCTsEWypkckorf5RFBlS2Azk4nJ/6C0vOQsMttoPqY5yHEahEZ76ueu3+FYfWB1RnRL 88Qrsj92nSW0XHnC55qo3p7qWSKBNdnDeXNTmYb0yKOjwpupemxzlUhLoesqhvcHN24X CqS1HzvWeEEGc4JGPv3227idaW9k+OgWH9kCPmkom8QuWvdK8c/E21Mvy1X+avSt6SFo iCug== X-Gm-Message-State: AOAM530pYbzdneU1rKOBS03dGzTCA41CkrC1ryvJNFpZY/X5BajSWSD3 doCkaiMSPnablcJxdNjvKuFPPiYPbUqFzA== X-Google-Smtp-Source: ABdhPJzQF8YqRKaRzhqpB/+RKXKTS92zdI9LaCldl/gjxDCST/Q7SYVtCA0jA3ko98w0KRBRVpcFjA== X-Received: by 2002:aa7:d594:0:b0:410:ef84:f706 with SMTP id r20-20020aa7d594000000b00410ef84f706mr2767662edq.347.1645107720447; Thu, 17 Feb 2022 06:22:00 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-001-066-240.77.1.pool.telefonica.de. [77.1.66.240]) by smtp.gmail.com with ESMTPSA id a13sm578436edn.25.2022.02.17.06.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 06:22:00 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , Nathan Chancellor , Nick Desaulniers , Ondrej Mosnacek , Serge Hallyn , Austin Kim , Jiapeng Chong , Casey Schaufler , Yang Li , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 5/5] selinux: drop unnecessary NULL check Date: Thu, 17 Feb 2022 15:21:28 +0100 Message-Id: <20220217142133.72205-4-cgzones@googlemail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220217142133.72205-1-cgzones@googlemail.com> References: <20220217142133.72205-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Commit e3489f8974e1 ("selinux: kill selinux_sb_get_mnt_opts()") introduced a NULL check on the context after a successful call to security_sid_to_context(). This is on the one hand redundant after checking for success and on the other hand insufficient on an actual NULL pointer, since the context is passed to seq_escape() leading to a call of strlen() on it. Reported by Clang analyzer: In file included from security/selinux/hooks.c:28: In file included from ./include/linux/tracehook.h:50: In file included from ./include/linux/memcontrol.h:13: In file included from ./include/linux/cgroup.h:18: ./include/linux/seq_file.h:136:25: warning: Null pointer passed as 1st argument to string length function [unix.cstring.NullArg] seq_escape_mem(m, src, strlen(src), flags, esc); ^~~~~~~~~~~ Signed-off-by: Christian Göttsche --- security/selinux/hooks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 1e69f88eb326..ac802b99d36c 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -1020,7 +1020,7 @@ static int show_sid(struct seq_file *m, u32 sid) rc = security_sid_to_context(&selinux_state, sid, &context, &len); if (!rc) { - bool has_comma = context && strchr(context, ','); + bool has_comma = strchr(context, ','); seq_putc(m, '='); if (has_comma)