mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [RESEND PATCH] ldso: don't reclaim zero-memory-sized segments
@ 2024-11-18  3:44 Yao Zi
  2025-02-08  5:51 ` Yao Zi
  0 siblings, 1 reply; 3+ messages in thread
From: Yao Zi @ 2024-11-18  3:44 UTC (permalink / raw)
  To: musl; +Cc: Yao Zi

Some weird linkers may emit PT_LOAD segments with memsz = 0. ELF
specification does not forbid this, but such a segment with non-zero
p_vaddr will result in reclaiming of invalid memory address.

This patch skips such segments during reclaiming for better
compatibility.

Signed-off-by: Yao Zi <ziyao@disroot.org>
---
 ldso/dynlink.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 3b57c07f..715948f4 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -616,6 +616,7 @@ static void reclaim_gaps(struct dso *dso)
 	for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) {
 		if (ph->p_type!=PT_LOAD) continue;
 		if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue;
+		if (ph->p_memsz == 0) continue;
 		reclaim(dso, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr);
 		reclaim(dso, ph->p_vaddr+ph->p_memsz,
 			ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE);
-- 
2.46.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] [RESEND PATCH] ldso: don't reclaim zero-memory-sized segments
  2024-11-18  3:44 [musl] [RESEND PATCH] ldso: don't reclaim zero-memory-sized segments Yao Zi
@ 2025-02-08  5:51 ` Yao Zi
  2025-02-09 14:04   ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Yao Zi @ 2025-02-08  5:51 UTC (permalink / raw)
  To: musl

On Mon, Nov 18, 2024 at 03:44:47AM +0000, Yao Zi wrote:
> Some weird linkers may emit PT_LOAD segments with memsz = 0. ELF
> specification does not forbid this, but such a segment with non-zero
> p_vaddr will result in reclaiming of invalid memory address.
> 
> This patch skips such segments during reclaiming for better
> compatibility.

Ping on this patch, someone has been hitting this[1].

Thanks for your time and review!

> Signed-off-by: Yao Zi <ziyao@disroot.org>
> ---
>  ldso/dynlink.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/ldso/dynlink.c b/ldso/dynlink.c
> index 3b57c07f..715948f4 100644
> --- a/ldso/dynlink.c
> +++ b/ldso/dynlink.c
> @@ -616,6 +616,7 @@ static void reclaim_gaps(struct dso *dso)
>  	for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) {
>  		if (ph->p_type!=PT_LOAD) continue;
>  		if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue;
> +		if (ph->p_memsz == 0) continue;
>  		reclaim(dso, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr);
>  		reclaim(dso, ph->p_vaddr+ph->p_memsz,
>  			ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE);
> -- 
> 2.46.0
> 

[1]: https://lists.nongnu.org/archive/html/tinycc-devel/2024-10/msg00012.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] [RESEND PATCH] ldso: don't reclaim zero-memory-sized segments
  2025-02-08  5:51 ` Yao Zi
@ 2025-02-09 14:04   ` Rich Felker
  0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2025-02-09 14:04 UTC (permalink / raw)
  To: Yao Zi; +Cc: musl

On Sat, Feb 08, 2025 at 05:51:01AM +0000, Yao Zi wrote:
> On Mon, Nov 18, 2024 at 03:44:47AM +0000, Yao Zi wrote:
> > Some weird linkers may emit PT_LOAD segments with memsz = 0. ELF
> > specification does not forbid this, but such a segment with non-zero
> > p_vaddr will result in reclaiming of invalid memory address.
> > 
> > This patch skips such segments during reclaiming for better
> > compatibility.
> 
> Ping on this patch, someone has been hitting this[1].
> 
> Thanks for your time and review!
> 
> > Signed-off-by: Yao Zi <ziyao@disroot.org>
> > ---
> >  ldso/dynlink.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/ldso/dynlink.c b/ldso/dynlink.c
> > index 3b57c07f..715948f4 100644
> > --- a/ldso/dynlink.c
> > +++ b/ldso/dynlink.c
> > @@ -616,6 +616,7 @@ static void reclaim_gaps(struct dso *dso)
> >  	for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) {
> >  		if (ph->p_type!=PT_LOAD) continue;
> >  		if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue;
> > +		if (ph->p_memsz == 0) continue;
> >  		reclaim(dso, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr);
> >  		reclaim(dso, ph->p_vaddr+ph->p_memsz,
> >  			ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE);
> > -- 
> > 2.46.0
> > 
> 
> [1]: https://lists.nongnu.org/archive/html/tinycc-devel/2024-10/msg00012.html

Thanks for the ping. Applying.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-09 14:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-18  3:44 [musl] [RESEND PATCH] ldso: don't reclaim zero-memory-sized segments Yao Zi
2025-02-08  5:51 ` Yao Zi
2025-02-09 14:04   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).