On Sat, May 30, 2026 at 3:12 PM Richard Henderson <
[email protected]> wrote:

> Since dropping 32-bit host support, a guest address cannot
> overflow a host pointer.  This means guest_hiaddr is unused
> for relocatable images, so don't pass guest_hiaddr as size.
>
> Signed-off-by: Richard Henderson <[email protected]>
> ---
>  linux-user/elfload.c  | 26 +++++++-------------------
>  linux-user/flatload.c |  3 +--
>  2 files changed, 8 insertions(+), 21 deletions(-)
>

Reviewed-by: Warner Losh <[email protected]>

I though there'd be a bsd-user change like this but I couldn't find it,
though I did find some code in bsd-user/main.c I may need to cleanup now
that 64-on-32 isn't a thing.

Warner


> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index fb774adf25..33565ad7be 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -1092,20 +1092,11 @@ void probe_guest_base(const char *image_name,
> abi_ulong guest_loaddr,
>      uintptr_t align = MAX(SHMLBA, TARGET_PAGE_SIZE);
>
>      /* Sanity check the guest binary. */
> -    if (reserved_va) {
> -        if (guest_hiaddr > reserved_va) {
> -            error_report("%s: requires more than reserved virtual "
> -                         "address space (0x%" PRIx64 " > 0x%lx)",
> -                         image_name, (uint64_t)guest_hiaddr, reserved_va);
> -            exit(EXIT_FAILURE);
> -        }
> -    } else {
> -        if (guest_hiaddr != (uintptr_t)guest_hiaddr) {
> -            error_report("%s: requires more virtual address space "
> -                         "than the host can provide (0x%" PRIx64 ")",
> -                         image_name, (uint64_t)guest_hiaddr + 1);
> -            exit(EXIT_FAILURE);
> -        }
> +    if (reserved_va && guest_hiaddr > reserved_va) {
> +        error_report("%s: requires more than reserved virtual "
> +                     "address space (0x%" PRIx64 " > 0x%lx)",
> +                     image_name, (uint64_t)guest_hiaddr, reserved_va);
> +        exit(EXIT_FAILURE);
>      }
>
>      if (have_guest_base) {
> @@ -1373,11 +1364,8 @@ static void load_elf_image(const char *image_name,
> const ImageSource *src,
>               */
>              probe_guest_base(image_name, range.lo, range.hi);
>          } else {
> -            /*
> -             * The binary is dynamic, but we still need to
> -             * select guest_base.  In this case we pass a size.
> -             */
> -            probe_guest_base(image_name, 0, range.hi - range.lo);
> +            /* The binary is dynamic; we still need to select guest_base.
> */
> +            probe_guest_base(image_name, 0, 0);
>
>              /*
>               * Avoid collision with the loader by providing a different
> diff --git a/linux-user/flatload.c b/linux-user/flatload.c
> index 4beb3ed1b9..8abdd2aef2 100644
> --- a/linux-user/flatload.c
> +++ b/linux-user/flatload.c
> @@ -261,8 +261,7 @@ static int load_flat_file(struct linux_binprm * bprm,
>      /*
>       * Allocate the address space.
>       */
> -    probe_guest_base(bprm->filename, 0,
> -                     text_len + data_len + extra + indx_len - 1);
> +    probe_guest_base(bprm->filename, 0, 0);
>
>      /*
>       * there are a couple of cases here,  the separate code/data
> --
> 2.43.0
>
>

Reply via email to