This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 1/1] dl-load: add memory barrier before updating the next.
- From: Maninder Singh <maninder1 dot s at samsung dot com>
- To: libc-alpha at sourceware dot org
- Cc: pankaj dot m at samsung dot com, hakbong5 dot lee at samsung dot com, a dot sahrawat at samsung dot com, ajeet dot y at samsung dot com, Maninder Singh <maninder1 dot s at samsung dot com>, Vaneet Narang <v dot narang at samsung dot com>
- Date: Thu, 16 Mar 2017 10:42:02 +0530
- Subject: [PATCH 1/1] dl-load: add memory barrier before updating the next.
- Authentication-results: sourceware.org; auth=none
- Cms-type: 105P
- Dlp-filter: Pass
- References: <CGME20170316051208epcas5p2d15680536ba99a6f05ecd6906750cd98@epcas5p2.samsung.com>
This patch adds memory barrier before updating the liblist next.
Issue Fix: race condition between add_name_to_object & _dl_name_match_p.
One threads calling dlopen which further calls add_name_to_object &
other thread trying to resolve RTLD_LAZY symbols through _dl_runtime_resolve
which further calls.
_dl_name_match_p checks if libname->next is valid, then it assumes
libname->next->name to be valid. Also add_name_to_object initialized name
first and then sets valid next pointer.
This patch avoids any reorder of instruction when next is set before name
to avoid any race.
Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
Signed-off-by: Vaneet Narang <v.narang@samsung.com>
---
elf/dl-load.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 016a99c..c1e69b8 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -429,6 +429,7 @@ add_name_to_object (struct link_map *l, const char *name)
newname->name = memcpy (newname + 1, name, name_len);
newname->next = NULL;
newname->dont_free = 0;
+ atomic_write_barrier ();
lastp->next = newname;
}
--
1.9.1