public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: John David Anglin <dave.anglin@bell.net>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	libc-alpha@sourceware.org,
	John David Anglin <danglin@gcc.gnu.org>
Subject: Re: [PATCH v2] hppa: Fix bind-now audit (BZ #28857)
Date: Mon, 7 Feb 2022 10:14:40 -0500	[thread overview]
Message-ID: <7a8af6dc-7e06-ddef-22e9-4b36f9fe7a38@bell.net> (raw)
In-Reply-To: <20220207124934.653139-1-adhemerval.zanella@linaro.org>

On 2022-02-07 7:49 a.m., Adhemerval Zanella wrote:
> diff --git a/sysdeps/hppa/dl-lookupcfg.h b/sysdeps/hppa/dl-lookupcfg.h
> index 8da2412fea..3929fc84ae 100644
> --- a/sysdeps/hppa/dl-lookupcfg.h
> +++ b/sysdeps/hppa/dl-lookupcfg.h
> @@ -30,6 +30,7 @@ rtld_hidden_proto (_dl_symbol_address)
>   #define DL_SYMBOL_ADDRESS(map, ref) _dl_symbol_address(map, ref)
>   
>   Elf32_Addr _dl_lookup_address (const void *address);
> +rtld_hidden_proto (_dl_lookup_address)
>   
>   #define DL_LOOKUP_ADDRESS(addr) _dl_lookup_address ((const void *) addr)
>   
> @@ -81,5 +82,8 @@ void attribute_hidden _dl_unmap (struct link_map *map);
>   #define DL_FIXUP_VALUE_ADDR(value) ((uintptr_t) &(value))
>   #define DL_FIXUP_ADDR_VALUE(addr) (*(struct fdesc *) (addr))
>   #define DL_FIXUP_BINDNOW_ADDR_VALUE(addr) (addr)
> -#define DL_FIXUP_BINDNOW_RELOC(value, new_value, st_value) \
> -  (*value) = *(struct fdesc *) (st_value)
> +#define DL_FIXUP_BINDNOW_RELOC(value, new_value, st_value)	\
> +  ({								\
> +     value->ip = _dl_lookup_address ((void *) new_value);	\
> +     value->gp = ((struct fdesc *) (new_value))->gp;		\
> +  })
This still isn't correct.  The PLABEL bit is set in new_value in the cases I looked at.  It needs
to be cleared to access the ip and gp values in the function descriptor.  Otherwise, a misaligned
access will occur for the gp value and the wrong value will be loaded.

Based on my testing, it is unnecessary to call _dl_lookup_address().  It does not seem
necessary to bind the descriptor pointed to by new_value.  All the audit24 and audit25
tests pass without calling _dl_lookup_address().  It seems we just need to clear the
PLABEL bit and copy new_value to value.  Note that _dl_lookup_address() only returns
the ip address in the descriptor when it finds a valid descriptor. Otherwise, it returns
the original pointer value.

Can the PLABEL bit be set in the addr value in DL_FIXUP_ADDR_VALUE? In any case,
it doesn't hurt to clear it as function descriptors are always at least 4-byte aligned.  Currently,
they are 8-byte aligned so the ip and gp values can be updated atomically with a floating
point store.

If the PLABEL bit is not set in a function pointer, a descriptor is not used and the pointer
points directly at function or stub.  gp does not change.  This is only supported within objects.
I don't think this case occurs in the audit code.

-- 
John David Anglin  dave.anglin@bell.net


      reply	other threads:[~2022-02-07 15:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-07 12:49 Adhemerval Zanella
2022-02-07 15:14 ` John David Anglin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a8af6dc-7e06-ddef-22e9-4b36f9fe7a38@bell.net \
    --to=dave.anglin@bell.net \
    --cc=adhemerval.zanella@linaro.org \
    --cc=danglin@gcc.gnu.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).