[PATCH v2 1/2] elf: strdup() l_name if no realname [BZ #30100]
Florian Weimer
fw@deneb.enyo.de
Sun Feb 12 13:44:01 GMT 2023
* Stas Sergeev via Libc-alpha:
> _dl_close_worker() has this code:
> /* This name always is allocated. */
> free (imap->l_name);
>
> But in that particular case, while indeed being allocated, l_name
> doesn't point to the start of an allocation:
> new = (struct link_map *) calloc (sizeof (*new) + audit_space
> + sizeof (struct link_map *)
> + sizeof (*newname) + libname_len, 1);
> ...
> new->l_symbolic_searchlist.r_list = (struct link_map **) ((char *) (new + 1)
> + audit_space);
>
> new->l_libname = newname
> = (struct libname_list *) (new->l_symbolic_searchlist.r_list + 1);
> newname->name = (char *) memcpy (newname + 1, libname, libname_len);
> ...
> new->l_name = (char *) newname->name + libname_len - 1;
>
> It therefore cannot be freed separately.
> Use strdup() as a simple fix.
The problematic adjustment should only happen for objects which cannot
be closed. I think you see this in your dlmem case because it
introduces unnamed shared objects that can be closed. It may be
better to change the dlmem interface to explicitly name the shared
objects because that assumption is likely widespread throughout the
system (even outside glibc, in debuggers, for example).
More information about the Libc-alpha
mailing list