Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3421462pxb; Mon, 4 Apr 2022 16:28:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqE7EYgSZrt0LdOcLjlU4rIFixHXcc3tocw8BbYn14wUUTIZEx6MmiEs4OT1PN4fc7of4f X-Received: by 2002:a17:90b:17c4:b0:1c6:e74b:31d9 with SMTP id me4-20020a17090b17c400b001c6e74b31d9mr778074pjb.242.1649114935045; Mon, 04 Apr 2022 16:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649114935; cv=none; d=google.com; s=arc-20160816; b=ximUaCdFERBYhTRGLqUTGRB7HBjZZZjAVYy2WL+poHvjChKbTUAdkGbY+CGS8eSdsh m6SQaurtsUACqXIMsPq/I9nQaco3ogbvXAnzsfcDgamGfR8bRw7O3MLbFpC//e/k+rRI 7bobohQwJbIbTvETuMHVk3tvnubemyJJeWF48FlD/saE7NZTWpDif017hhtXxMdc+uPc glG6zwVdDu97aowekpTHfrKUlKxOiC1Jo6EJvl0i9oEGcVU8Diwg+os9o/5qBoT95Wtx uJlL6Kz4nyD0st7HnAgIocYE9qp3MKALfFXhjhm3fdKKaoiXKj74OkyHFbHP5ntUxj7y LwWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=CrpYt5lVlKuy2k+kKWnZgQywx0bCmkEjtjH6HYRoOhQ=; b=w5J7FfJfF8VQMRoXiE+y62XtwKRirhweTLI5kpqKyznlKZph9VrdDdQCWnLLXpJX+y s84qQ9xBbkOJdLDMqvDsKxDINJhseZLByQcF3ZEMw8PHSAkkbq3l6R1uxIU7NrEBURhK rwoCCr/Xr3aX1dsFAPxd/147+SUU+LxrzfOERPySPcEZxFlSSaQ3ypqf86AGjR1GUC90 nkC5Nfc0VAnqv44F+Cjob3LEa8LWxe6gE9RZNNMbNr8vX2O8vZh0Hwga+JCFIv1Fwvg1 t9i7QXwCix+LmFxyqusXWKURNaGmYmv3oxwSDTDd+3rRG2KPRtb06F5ty7gJeRvl1os3 QoIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=QWtilS35; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c2-20020a170902d48200b00153b2d16453si12091151plg.91.2022.04.04.16.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 16:28:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=QWtilS35; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6C8F82B1BD; Mon, 4 Apr 2022 16:27:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381722AbiDDVXy (ORCPT + 99 others); Mon, 4 Apr 2022 17:23:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380413AbiDDUFb (ORCPT ); Mon, 4 Apr 2022 16:05:31 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F162CC36 for ; Mon, 4 Apr 2022 13:03:33 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id i27so15174579ejd.9 for ; Mon, 04 Apr 2022 13:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=CrpYt5lVlKuy2k+kKWnZgQywx0bCmkEjtjH6HYRoOhQ=; b=QWtilS35liU4Gd847ayqzl1+Xu3q5LYVHMfUzUizuln6K7VajF0VthS1a5ivhzNuZs Vb0AbMMPTtLaqQ4fs96PTRsH5w8FZuGJQgk7wadg4Zc3h1TT5TsDl2lEcelg9XECB2ef q6pR6ZpG0WiArgQVkKPp2zQvs80GH3EFdkk8IBI8n7UhuS1QqVotwHz2FlEBLP/5/tB2 CJ6tkq0oJXB2dZ1K3zGKK1n8+9u3/7xygKNh015o9+LY81o7hMI+cCH66leOlKSBgFnw BXGjLKXGVsCcw0zfsHm7B1VvznCY4DVSqevmzZrA6DknE0HLN8njsh9vZ7s6qDiGhw+Y jS3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CrpYt5lVlKuy2k+kKWnZgQywx0bCmkEjtjH6HYRoOhQ=; b=nKLLxKs8lcsSIy+OgDxEIEmgsOuXhOCGWPkwNfyP8N7y8c41PgqBkQ54YzMEKv+SqA nBYArzCsKQLV1/uvGBMNqcQs83zPJvE/Jk16YxZRAFhH0LIuTgQiSliW1a9xBZu35OLU rKgJVJaCYClw3M+IOA4tENGARa+ebyP+cFeyxMaGR4x8Vv0IZV5DjXph+S6aajBYlCKv mpa5mljyjobak5gkJ4MeR9tzg4BGS2/GJELTWjuoDt4E8MyNNy5CBQaBQcIUkbb7DoT9 Tjg7UxnZtoCJrY882PBuDeKyryqiKtbcF65iQ71c4P6VcAo3JZcpOEH3c+vtYGiLaIN1 iI8Q== X-Gm-Message-State: AOAM531nnxztb8/jXcyKt46zjCeh+Veu+qXYknJEpHcHf/j7u7QvpYZR /YupNByx3Oo6QFt5okXBqlI420J7FhfABM2lQwpf X-Received: by 2002:a17:906:4443:b0:6cf:6a7d:5f9b with SMTP id i3-20020a170906444300b006cf6a7d5f9bmr1776503ejp.12.1649102612452; Mon, 04 Apr 2022 13:03:32 -0700 (PDT) MIME-Version: 1.0 References: <20220217142133.72205-3-cgzones@googlemail.com> <20220308165527.45456-1-cgzones@googlemail.com> In-Reply-To: <20220308165527.45456-1-cgzones@googlemail.com> From: Paul Moore Date: Mon, 4 Apr 2022 16:03:21 -0400 Message-ID: Subject: Re: [PATCH v2 4/5] selinux: declare data arrays const To: =?UTF-8?Q?Christian_G=C3=B6ttsche?= Cc: selinux@vger.kernel.org, Stephen Smalley , Eric Paris , Ondrej Mosnacek , "David S. Miller" , Jeremy Kerr , Richard Haines , Lakshmi Ramasubramanian , Austin Kim , Yang Li , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 8, 2022 at 11:55 AM Christian G=C3=B6ttsche wrote: > > 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. > > Do not override the classmap and the initial sid list in the build time > script genheaders, by using a static buffer in the conversion function > stoupperx(). In cases we need to compare or print more than one > identifier allocate a temporary copy. > > Signed-off-by: Christian G=C3=B6ttsche > --- > v2: > Drop const exemption for genheaders script by rewriting stoupperx(). > --- > scripts/selinux/genheaders/genheaders.c | 76 ++++++++++--------- > scripts/selinux/mdp/mdp.c | 4 +- > security/selinux/avc.c | 2 +- > security/selinux/include/avc_ss.h | 2 +- > security/selinux/include/classmap.h | 2 +- > .../selinux/include/initial_sid_to_string.h | 3 +- > security/selinux/include/policycap.h | 2 +- > security/selinux/include/policycap_names.h | 2 +- > security/selinux/ss/services.c | 4 +- > 9 files changed, 51 insertions(+), 46 deletions(-) > > diff --git a/scripts/selinux/genheaders/genheaders.c b/scripts/selinux/ge= nheaders/genheaders.c > index f355b3e0e968..a2caff3c997f 100644 > --- a/scripts/selinux/genheaders/genheaders.c > +++ b/scripts/selinux/genheaders/genheaders.c > @@ -26,19 +26,23 @@ static void usage(void) > exit(1); > } > > -static char *stoupperx(const char *s) > +static const char *stoupperx(const char *s) > { > - char *s2 =3D strdup(s); > - char *p; > + static char buffer[256]; > + unsigned int i; > + char *p =3D buffer; > > - if (!s2) { > - fprintf(stderr, "%s: out of memory\n", progname); > + for (i =3D 0; i < (sizeof(buffer) - 1) && *s; i++) > + *p++ =3D toupper(*s++); > + > + if (*s) { > + fprintf(stderr, "%s: buffer too small\n", progname); > exit(3); > } > > - for (p =3D s2; *p; p++) > - *p =3D toupper(*p); > - return s2; > + *p =3D '\0'; > + > + return buffer; > } Hmmm. I recognize this is just build time code so it's not as critical, but I still don't like the idea of passing back a static buffer to the caller; it just seems like we are asking for future trouble. I'm also curious as to why you made this choice in this revision when the existing code should have worked (passed a const, returned a non-const). I'm sure I'm missing something obvious, but can you help me understand why this is necessary? --=20 paul-moore.com