Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Oct 2023 10:56:52 -0700
From:      Benjamin Kaduk <bjkfbsd@gmail.com>
To:        "Stephen J. Kiernan" <stevek@freebsd.org>
Cc:        src-committers@freebsd.org, dev-commits-src-all@freebsd.org,  dev-commits-src-main@freebsd.org
Subject:   Re: git: 95335dd3c19e - main - rtld: introduce STATIC_TLS_EXTRA
Message-ID:  <CAJ5_RoCx1zbpU4U1ZE2N%2BQCM6oVA4wwrM=dyP9%2Bqe2FqvHpv4w@mail.gmail.com>
In-Reply-To: <202310301742.39UHgSPp011580@gitrepo.freebsd.org>
References:  <202310301742.39UHgSPp011580@gitrepo.freebsd.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Mon, Oct 30, 2023 at 10:42 AM Stephen J. Kiernan <stevek@freebsd.org>
wrote:

> The branch main has been updated by stevek:
>
> URL:
> https://cgit.FreeBSD.org/src/commit/?id=95335dd3c19e0ade161bb4dc8462fc3d045ce4f8
>
> commit 95335dd3c19e0ade161bb4dc8462fc3d045ce4f8
> Author:     Stephen J. Kiernan <stevek@FreeBSD.org>
> AuthorDate: 2023-10-29 21:13:10 +0000
> Commit:     Stephen J. Kiernan <stevek@FreeBSD.org>
> CommitDate: 2023-10-30 17:42:05 +0000
>
>     rtld: introduce STATIC_TLS_EXTRA
>
>     The new STATIC_TLS_EXTRA variable provides a means for applications
>     to increases the size of the extra static TLS space allocated by
>     rtld beyond the default of '128'. This extra static TLS space is used
>     for objects loaded with dlopen.
>
>     The value specified in the variable must be no less than the default
>     value and no greater than the maximum allowed value for size_t type.
>
>

I think that we want to have a maximum allowed value that is smaller than
SIZE_T_MAX, both to prevent chance of this being used in attacks and to
prevent integer overflow.

Perhaps something large but not incredibly large, like 1M?


>     If an invalid value is specified, rtld will ignore it and just use
>     the default value.
>
>     The rtld(1) man page is updated to document this new option.
>
>     Obtained from:  Juniper Networks, Inc.
>     Differential Revision:  https://reviews.freebsd.org/D42025
> ---
>  libexec/rtld-elf/aarch64/reloc.c   |  2 +-
>  libexec/rtld-elf/amd64/reloc.c     |  2 +-
>  libexec/rtld-elf/arm/reloc.c       |  3 ++-
>  libexec/rtld-elf/i386/reloc.c      |  2 +-
>  libexec/rtld-elf/powerpc/reloc.c   |  3 ++-
>  libexec/rtld-elf/powerpc64/reloc.c |  3 ++-
>  libexec/rtld-elf/riscv/reloc.c     |  2 +-
>  libexec/rtld-elf/rtld.1            |  8 +++++++-
>  libexec/rtld-elf/rtld.c            | 21 +++++++++++++++++----
>  libexec/rtld-elf/rtld.h            |  1 +
>  10 files changed, 35 insertions(+), 12 deletions(-)
>
> diff --git a/libexec/rtld-elf/aarch64/reloc.c
> b/libexec/rtld-elf/aarch64/reloc.c
> index c8f09d797215..907377f2619a 100644
> --- a/libexec/rtld-elf/aarch64/reloc.c
> +++ b/libexec/rtld-elf/aarch64/reloc.c
> @@ -521,7 +521,7 @@ allocate_initial_tls(Obj_Entry *objs)
>         * use.
>         */
>         tls_static_space = tls_last_offset + tls_last_size +
> -           RTLD_STATIC_TLS_EXTRA;
> +           ld_static_tls_extra;
>
>         _tcb_set(allocate_tls(objs, NULL, TLS_TCB_SIZE, TLS_TCB_ALIGN));
>  }
> diff --git a/libexec/rtld-elf/amd64/reloc.c
> b/libexec/rtld-elf/amd64/reloc.c
> index ce74c54cc5c3..9c5887def356 100644
> --- a/libexec/rtld-elf/amd64/reloc.c
> +++ b/libexec/rtld-elf/amd64/reloc.c
> @@ -527,7 +527,7 @@ allocate_initial_tls(Obj_Entry *objs)
>          * offset allocated so far and adding a bit for dynamic
>          * modules to use.
>          */
> -       tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
> +       tls_static_space = tls_last_offset + ld_static_tls_extra;
>
>
This calculation could overflow, as I see it (likewise for the other archs).

-Ben

[-- Attachment #2 --]
<div dir="ltr"><div dir="ltr">On Mon, Oct 30, 2023 at 10:42 AM Stephen J. Kiernan &lt;<a href="mailto:stevek@freebsd.org">stevek@freebsd.org</a>&gt; wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The branch main has been updated by stevek:<br>
<br>
URL: <a href="https://cgit.FreeBSD.org/src/commit/?id=95335dd3c19e0ade161bb4dc8462fc3d045ce4f8" rel="noreferrer" target="_blank">https://cgit.FreeBSD.org/src/commit/?id=95335dd3c19e0ade161bb4dc8462fc3d045ce4f8</a><br>;
<br>
commit 95335dd3c19e0ade161bb4dc8462fc3d045ce4f8<br>
Author:     Stephen J. Kiernan &lt;stevek@FreeBSD.org&gt;<br>
AuthorDate: 2023-10-29 21:13:10 +0000<br>
Commit:     Stephen J. Kiernan &lt;stevek@FreeBSD.org&gt;<br>
CommitDate: 2023-10-30 17:42:05 +0000<br>
<br>
    rtld: introduce STATIC_TLS_EXTRA<br>
<br>
    The new STATIC_TLS_EXTRA variable provides a means for applications<br>
    to increases the size of the extra static TLS space allocated by<br>
    rtld beyond the default of &#39;128&#39;. This extra static TLS space is used<br>
    for objects loaded with dlopen.<br>
<br>
    The value specified in the variable must be no less than the default<br>
    value and no greater than the maximum allowed value for size_t type.<br>
<br></blockquote><div><br></div><div><br></div><div>I think that we want to have a maximum allowed value that is smaller than SIZE_T_MAX, both to prevent chance of this being used in attacks and to prevent integer overflow.</div><div><br></div><div>Perhaps something large but not incredibly large, like 1M?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
    If an invalid value is specified, rtld will ignore it and just use<br>
    the default value.<br>
<br>
    The rtld(1) man page is updated to document this new option.<br>
<br>
    Obtained from:  Juniper Networks, Inc.<br>
    Differential Revision:  <a href="https://reviews.freebsd.org/D42025" rel="noreferrer" target="_blank">https://reviews.freebsd.org/D42025</a><br>;
---<br>
 libexec/rtld-elf/aarch64/reloc.c   |  2 +-<br>
 libexec/rtld-elf/amd64/reloc.c     |  2 +-<br>
 libexec/rtld-elf/arm/reloc.c       |  3 ++-<br>
 libexec/rtld-elf/i386/reloc.c      |  2 +-<br>
 libexec/rtld-elf/powerpc/reloc.c   |  3 ++-<br>
 libexec/rtld-elf/powerpc64/reloc.c |  3 ++-<br>
 libexec/rtld-elf/riscv/reloc.c     |  2 +-<br>
 libexec/rtld-elf/rtld.1            |  8 +++++++-<br>
 libexec/rtld-elf/rtld.c            | 21 +++++++++++++++++----<br>
 libexec/rtld-elf/rtld.h            |  1 +<br>
 10 files changed, 35 insertions(+), 12 deletions(-)<br>
<br>
diff --git a/libexec/rtld-elf/aarch64/reloc.c b/libexec/rtld-elf/aarch64/reloc.c<br>
index c8f09d797215..907377f2619a 100644<br>
--- a/libexec/rtld-elf/aarch64/reloc.c<br>
+++ b/libexec/rtld-elf/aarch64/reloc.c<br>
@@ -521,7 +521,7 @@ allocate_initial_tls(Obj_Entry *objs)<br>
        * use.<br>
        */<br>
        tls_static_space = tls_last_offset + tls_last_size +<br>
-           RTLD_STATIC_TLS_EXTRA;<br>
+           ld_static_tls_extra;<br>
<br>
        _tcb_set(allocate_tls(objs, NULL, TLS_TCB_SIZE, TLS_TCB_ALIGN));<br>
 }<br>
diff --git a/libexec/rtld-elf/amd64/reloc.c b/libexec/rtld-elf/amd64/reloc.c<br>
index ce74c54cc5c3..9c5887def356 100644<br>
--- a/libexec/rtld-elf/amd64/reloc.c<br>
+++ b/libexec/rtld-elf/amd64/reloc.c<br>
@@ -527,7 +527,7 @@ allocate_initial_tls(Obj_Entry *objs)<br>
         * offset allocated so far and adding a bit for dynamic<br>
         * modules to use.<br>
         */<br>
-       tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;<br>
+       tls_static_space = tls_last_offset + ld_static_tls_extra;<br>
<br></blockquote><div><br></div><div>This calculation could overflow, as I see it (likewise for the other archs).</div><div><br></div><div>-Ben</div><div><br></div><div> </div></div></div>
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ5_RoCx1zbpU4U1ZE2N%2BQCM6oVA4wwrM=dyP9%2Bqe2FqvHpv4w>