From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by sourceware.org (Postfix) with ESMTPS id 79D97384243E for ; Fri, 8 Jan 2021 17:59:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 79D97384243E Received: by mail-qt1-x82a.google.com with SMTP id 7so7149823qtp.1 for ; Fri, 08 Jan 2021 09:59:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:autocrypt:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Lv+xL2FsMxUxPAGpVqPP4nVENK5ozakEibvhxXgL8Vo=; b=mPL6WQLNoLWNdNoIp4C7uIv8wxheZ/aZVI4eAhl/HYhoCvijQGTDXeveUKmAIUONJM ew5xaGFxhFDCypeC+AW5AxDIxQgZFqlZl2sD5mOqSk0AIzz5rOqBZdRvQXW8kIqLwp9T 8BM7UTYJ6tiBm/nimL67IDjeqHKeZ3C56zT/BZxe82yvTzEfpGBXCKzuGKVrwA1jO/s5 MMd9CA7O8yQ2KLTTnKER2CCRhUOL3uupI8DJeL3V8AEwzg9bG16CzEH9p8zTuLQ2efNJ CSdV0PWEe46IJ1jCREnSpqg7j+tfdWfX+5cJxeHG9lCYaxLNOe5kgpv4vlMKMbVQrw9r pJrw== X-Gm-Message-State: AOAM533uRgfOo8E60UrTkEX6YvbNyMT/Cmn2WkAS52kJE1mwUzvI9jcK x9I9fX6uTgKiOGGt/tfJGHwv+/upuNQD4w== X-Google-Smtp-Source: ABdhPJynXh7wGyaOtWVoMjxTM2DWoYpwnxKkvHmEy5u8CKG7bxh+syGNhC+d/cDfgpsvenLUMfG+EQ== X-Received: by 2002:aed:23d6:: with SMTP id k22mr4666460qtc.226.1610128792488; Fri, 08 Jan 2021 09:59:52 -0800 (PST) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id g128sm5008505qkd.91.2021.01.08.09.59.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Jan 2021 09:59:51 -0800 (PST) Subject: Re: [PATCH v2 3/4] elf: Avoid RELATIVE relocs in __tunables_init To: Szabolcs Nagy , libc-alpha@sourceware.org References: <69ef59c70daa586fdda61fd818506c1f9fab06d0.1610121077.git.szabolcs.nagy@arm.com> From: Adhemerval Zanella Autocrypt: addr=adhemerval.zanella@linaro.org; prefer-encrypt=mutual; keydata= mQINBFcVGkoBEADiQU2x/cBBmAVf5C2d1xgz6zCnlCefbqaflUBw4hB/bEME40QsrVzWZ5Nq 8kxkEczZzAOKkkvv4pRVLlLn/zDtFXhlcvQRJ3yFMGqzBjofucOrmdYkOGo0uCaoJKPT186L NWp53SACXguFJpnw4ODI64ziInzXQs/rUJqrFoVIlrPDmNv/LUv1OVPKz20ETjgfpg8MNwG6 iMizMefCl+RbtXbIEZ3TE/IaDT/jcOirjv96lBKrc/pAL0h/O71Kwbbp43fimW80GhjiaN2y WGByepnkAVP7FyNarhdDpJhoDmUk9yfwNuIuESaCQtfd3vgKKuo6grcKZ8bHy7IXX1XJj2X/ BgRVhVgMHAnDPFIkXtP+SiarkUaLjGzCz7XkUn4XAGDskBNfbizFqYUQCaL2FdbW3DeZqNIa nSzKAZK7Dm9+0VVSRZXP89w71Y7JUV56xL/PlOE+YKKFdEw+gQjQi0e+DZILAtFjJLoCrkEX w4LluMhYX/X8XP6/C3xW0yOZhvHYyn72sV4yJ1uyc/qz3OY32CRy+bwPzAMAkhdwcORA3JPb kPTlimhQqVgvca8m+MQ/JFZ6D+K7QPyvEv7bQ7M+IzFmTkOCwCJ3xqOD6GjX3aphk8Sr0dq3 4Awlf5xFDAG8dn8Uuutb7naGBd/fEv6t8dfkNyzj6yvc4jpVxwARAQABtElBZGhlbWVydmFs IFphbmVsbGEgTmV0dG8gKExpbmFybyBWUE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QTteqkvA+gNqSaK1NM9tY0eQ4iJpo+aoX8HAcn4sZzt2pfUB9vQMTBJ2d4+m/qO6+ cFTAceXmIoFsN8+gFN3i8Is3u12u8xGudcBPvpoy4OoG Message-ID: <20c562ab-c04f-5620-9a5e-53c987315067@linaro.org> Date: Fri, 8 Jan 2021 14:59:49 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <69ef59c70daa586fdda61fd818506c1f9fab06d0.1610121077.git.szabolcs.nagy@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jan 2021 17:59:56 -0000 On 08/01/2021 13:20, Szabolcs Nagy via Libc-alpha wrote: > With static pie linking pointers in the tunables list need > RELATIVE relocs since the absolute address is not known at link > time. We want to avoid relocations so the static pie self > relocation can be done after tunables are initialized. > > This is a quick fix that increases the tunable list size a bit. > --- > elf/dl-tunables.c | 2 +- > elf/dl-tunables.h | 4 ++-- > scripts/gen-tunables.awk | 2 +- > 3 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c > index 9b4d737fb8..3845b2c04e 100644 > --- a/elf/dl-tunables.c > +++ b/elf/dl-tunables.c > @@ -350,7 +350,7 @@ __tunables_init (char **envp) > > /* Skip over tunables that have either been set already or should be > skipped. */ > - if (cur->initialized || cur->env_alias == NULL) > + if (cur->initialized || cur->env_alias[0] == '\0') > continue; > > const char *name = cur->env_alias; > diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h > index 518342a300..05997d028a 100644 > --- a/elf/dl-tunables.h > +++ b/elf/dl-tunables.h > @@ -38,7 +38,7 @@ __tunables_init (char **unused __attribute__ ((unused))) > /* A tunable. */ > struct _tunable > { > - const char *name; /* Internal name of the tunable. */ > + const char name[64]; /* Internal name of the tunable. */ > tunable_type_t type; /* Data type of the tunable. */ > tunable_val_t val; /* The value. */ > bool initialized; /* Flag to indicate that the tunable is > @@ -54,7 +54,7 @@ struct _tunable > target module if the value is > considered unsafe. */ > /* Compatibility elements. */ > - const char *env_alias; /* The compatibility environment > + const char env_alias[24]; /* The compatibility environment > variable name. */ > }; > > diff --git a/scripts/gen-tunables.awk b/scripts/gen-tunables.awk > index 622199061a..9e7bd24e13 100644 > --- a/scripts/gen-tunables.awk > +++ b/scripts/gen-tunables.awk > @@ -57,7 +57,7 @@ $1 == "}" { > maxvals[top_ns,ns,tunable] = max_of[types[top_ns,ns,tunable]] > } > if (!env_alias[top_ns,ns,tunable]) { > - env_alias[top_ns,ns,tunable] = "NULL" > + env_alias[top_ns,ns,tunable] = "{0}" > } > if (!security_level[top_ns,ns,tunable]) { > security_level[top_ns,ns,tunable] = "SXID_ERASE" > The change is ok, although I think we can at least not make the maximum r equired size being automatically generated at build time: diff --git a/Makeconfig b/Makeconfig index 0a4811b5e5..a291f90719 100644 --- a/Makeconfig +++ b/Makeconfig @@ -1160,8 +1160,10 @@ endif # Build the tunables list header early since it could be used by any module in # glibc. ifneq (no,$(have-tunables)) -before-compile += $(common-objpfx)dl-tunable-list.h -common-generated += dl-tunable-list.h dl-tunable-list.stmp +before-compile += $(common-objpfx)dl-tunable-list.h \ + $(common-objpfx)dl-tunable-list-max.h +common-generated += dl-tunable-list.h dl-tunable-list.stmp \ + dl-tunable-list-max.h dl-tunable-list-max.stmp \ $(common-objpfx)dl-tunable-list.h: $(common-objpfx)dl-tunable-list.stmp; @: $(common-objpfx)dl-tunable-list.stmp: \ @@ -1169,7 +1171,17 @@ $(common-objpfx)dl-tunable-list.stmp: \ $(..)elf/dl-tunables.list \ $(wildcard $(subdirs:%=$(..)%/dl-tunables.list)) \ $(wildcard $(sysdirs:%=%/dl-tunables.list)) - $(AWK) -f $^ > ${@:stmp=T} + $(AWK) -v mode=tunables -f $^ > ${@:stmp=T} + $(move-if-change) ${@:stmp=T} ${@:stmp=h} + touch $@ + +$(common-objpfx)dl-tunable-list-max.h: $(common-objpfx)dl-tunable-list-max.stmp; @: +$(common-objpfx)dl-tunable-list-max.stmp: \ + $(..)scripts/gen-tunables.awk \ + $(..)elf/dl-tunables.list \ + $(wildcard $(subdirs:%=$(..)%/dl-tunables.list)) \ + $(wildcard $(sysdirs:%=%/dl-tunables.list)) + $(AWK) -v mode=max -f $^ > ${@:stmp=T} $(move-if-change) ${@:stmp=T} ${@:stmp=h} touch $@ endif diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h index 518342a300..daeb6cf115 100644 --- a/elf/dl-tunables.h +++ b/elf/dl-tunables.h @@ -34,11 +34,12 @@ __tunables_init (char **unused __attribute__ ((unused))) # include # include "dl-tunable-types.h" +# include "dl-tunable-list-max.h" /* A tunable. */ struct _tunable { - const char *name; /* Internal name of the tunable. */ + const char name[TUNABLES_NAME_MAX]; /* Internal name of the tunable. */ tunable_type_t type; /* Data type of the tunable. */ tunable_val_t val; /* The value. */ bool initialized; /* Flag to indicate that the tunable is @@ -54,7 +55,7 @@ struct _tunable target module if the value is considered unsafe. */ /* Compatibility elements. */ - const char *env_alias; /* The compatibility environment + const char env_alias[TUNABLES_ALIAS_MAX];/* The compatibility environment variable name. */ }; diff --git a/scripts/gen-tunables.awk b/scripts/gen-tunables.awk index 622199061a..a4174b61f5 100644 --- a/scripts/gen-tunables.awk +++ b/scripts/gen-tunables.awk @@ -12,6 +12,8 @@ BEGIN { tunable="" ns="" top_ns="" + max_name_len=0 + max_alias_len=0 } # Skip over blank lines and comments. @@ -46,6 +48,14 @@ $2 == "{" { # End of either a top namespace, tunable namespace or a tunable. $1 == "}" { if (tunable != "") { + name_len = length(top_ns"."ns"."tunable) + if (name_len > max_name_len) + max_name_len = name_len + + alias_len = length(env_alias[top_ns,ns,tunable]) + if (alias_len > max_alias_len) + max_alias_len = alias_len + # Tunables definition ended, now fill in default attributes. if (!types[top_ns,ns,tunable]) { types[top_ns,ns,tunable] = "STRING" @@ -57,7 +67,7 @@ $1 == "}" { maxvals[top_ns,ns,tunable] = max_of[types[top_ns,ns,tunable]] } if (!env_alias[top_ns,ns,tunable]) { - env_alias[top_ns,ns,tunable] = "NULL" + env_alias[top_ns,ns,tunable] = "{0}" } if (!security_level[top_ns,ns,tunable]) { security_level[top_ns,ns,tunable] = "SXID_ERASE" @@ -131,7 +141,7 @@ $1 == "}" { } } -END { +function print_tunables() { if (ns != "") { print "Unterminated namespace. Is a closing brace missing?" exit 1 @@ -172,3 +182,20 @@ END { print "};" print "#endif" } + +function print_name_max() { + print "/* AUTOGENERATED by gen-tunables.awk. */" + print "#ifndef _TUNABLES_H_" + print "# error \"Do not include this file directly.\"" + print "# error \"Include tunables.h instead.\"" + print "#endif" + printf ("#define TUNABLES_NAME_MAX %d\n", max_name_len) + printf ("#define TUNABLES_ALIAS_MAX %d\n", max_alias_len) +} + +END { + if (mode == "tunables") + print_tunables() + else (mode == "max") + print_name_max() +}