From: Xi Ruoyao <xry111@xry111.site>
To: binutils@sourceware.org
Cc: liuzhensong <liuzhensong@loongson.cn>,
Lulu Cheng <chenglulu@loongson.cn>, Wang Xuerui <i@xen0n.name>,
Chenghua Xu <xuchenghua@loongson.cn>,
Xi Ruoyao <xry111@xry111.site>
Subject: [PATCH v2 1/2] LoongArch: Don't write into GOT for local ifunc
Date: Tue, 20 Sep 2022 14:09:29 +0800 [thread overview]
Message-ID: <20220920060930.33357-2-xry111@xry111.site> (raw)
In-Reply-To: <20220920060930.33357-1-xry111@xry111.site>
Local ifuncs are always resolved at runtime via R_LARCH_IRELATIVE, so
there is no need to write anything into GOT. And when we write the GOT
we actually trigger a heap-buffer-overflow: If a and b are different
sections, we cannot access something in b with "a->contents + (offset
from a)" because "a->contents" and "b->contents" are heap buffers
allocated separately, not slices of a large buffer.
So stop writing into GOT for local ifunc now.
---
bfd/elfnn-loongarch.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index ed42b8b6770..af18a8a0168 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -3179,6 +3179,8 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
htab->elf.srelgot, &rela);
}
h->got.offset |= 1;
+ bfd_put_NN (output_bfd, relocation,
+ got->contents + got_off);
}
}
else
@@ -3200,10 +3202,9 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
}
local_got_offsets[r_symndx] |= 1;
}
+ bfd_put_NN (output_bfd, relocation, got->contents + got_off);
}
- bfd_put_NN (output_bfd, relocation, got->contents + got_off);
-
relocation = got_off + sec_addr (got);
}
--
2.37.0
next prev parent reply other threads:[~2022-09-20 6:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 6:09 [PATCH v2 0/2] Fix two bugs breaking IFUNC in static PIE Xi Ruoyao
2022-09-20 6:09 ` Xi Ruoyao [this message]
2022-09-20 6:09 ` [PATCH v2 2/2] LoongArch: Fix R_LARCH_IRELATIVE insertion after elf_link_sort_relocs Xi Ruoyao
2022-09-20 9:29 ` [PATCH v2 0/2] Fix two bugs breaking IFUNC in static PIE liuzhensong
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=20220920060930.33357-2-xry111@xry111.site \
--to=xry111@xry111.site \
--cc=binutils@sourceware.org \
--cc=chenglulu@loongson.cn \
--cc=i@xen0n.name \
--cc=liuzhensong@loongson.cn \
--cc=xuchenghua@loongson.cn \
/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).