public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark <hack-computer@wildebeest.org>
To: "Dmitry V. Levin" <ldv@altlinux.org>, elfutils-devel@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>,
	Panu Matilainen	 <pmatilai@laiskiainen.org>
Subject: Re: [PATCH] elfclassify tool
Date: Fri, 19 Jul 2019 14:21:00 -0000	[thread overview]
Message-ID: <84da918d32c57e6f16fbcf1c854b375111dbdcb5.camel@wildebeest.org> (raw)
In-Reply-To: <20190719134341.GA26346@altlinux.org>

On Fri, 2019-07-19 at 16:43 +0300, Dmitry V. Levin wrote:
> On Fri, Jul 19, 2019 at 02:47:09PM +0200, Mark Wielaard wrote:
> [...]
> > +static bool
> > +is_shared (void)
> > +{
> > +  if (!is_loadable ())
> > +    return false;
> > +
> > +  /* The ELF type is very clear: this is an executable.  */
> > +  if (elf_type == ET_EXEC)
> > +    return false;
> > +
> > +  /* If the object is marked as PIE, it is definitely an
> > executable,
> > +     and not a loadlable shared object.  */
> > +  if (has_pie_flag)
> > +    return false;
> > +
> > +  /* Treat a DT_SONAME tag as a strong indicator that this is a
> > shared
> > +     object.  */
> > +  if (has_soname)
> > +    return true;
> 
> I'm not sure DT_SONAME is a reliable indicator.
> 
> I've seen many cases of DT_SONAME being erroneously applied to 
> non-libraries, e.g. lib.so was used as soname in openjdk executables.

I didn't know. Is this really common?
I did find one java binary on my system that indeed has this problem.
$ eu-readelf -d /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-
0.el7_6.x86_64/jre/bin/policytool

Dynamic segment contains 39 entries:
 Addr: 0x0000000000600d88  Offset: 0x000d88  Link to section: [ 7]
'.dynstr'
  Type              Value
  NEEDED            Shared library: [libpthread.so.0]
  NEEDED            Shared library: [libz.so.1]
  NEEDED            Shared library: [libX11.so.6]
  NEEDED            Shared library: [libjli.so]
  NEEDED            Shared library: [libdl.so.2]
  NEEDED            Shared library: [libc.so.6]
  SONAME            Library soname: [lib.so]
  RPATH             Library rpath:
[$ORIGIN/../lib/amd64/jli:$ORIGIN/../lib/amd64]
[...]

But even so eu-elfclassify still doesn't treat it as a shared library,
because:
$ eu-elfclassify -v --shared policytool; echo $?
info: policytool: ELF kind: ELF_K_ELF (0x3)
info: policytool: ELF type: ET_EXEC (0x2)
info: policytool: PT_LOAD found
info: policytool: allocated PROGBITS section found
info: policytool: program interpreter found
info: policytool: dynamic segment found
info: policytool: soname found
info: policytool: DT_DEBUG found
1

So other characteristics like it being ET_EXEC mark it as an
executable. And I assume if it was PIE (ET_DYN) the PIE DT_FLAGS would
have caught it.

So, I don't think the code is wrong. We might want to tweak the comment
a bit though, to make it less definitive?

Cheers,

Mark

  reply	other threads:[~2019-07-19 14:21 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-12 15:38 Florian Weimer
2019-04-15 15:39 ` Mark Wielaard
2019-04-16 11:38   ` Florian Weimer
2019-04-18 11:17     ` Florian Weimer
2019-07-19 12:47       ` Mark Wielaard
2019-07-19 13:43         ` Dmitry V. Levin
2019-07-19 14:21           ` Mark [this message]
2019-07-19 18:35             ` Dmitry V. Levin
2019-07-19 21:00               ` Florian Weimer
2019-07-19 21:23                 ` Dmitry V. Levin
2019-07-19 21:36                   ` Mark Wielaard
2019-07-19 22:57                     ` Dmitry V. Levin
2019-07-20 21:51                       ` Mark Wielaard
2019-07-25 22:39                         ` [PATCH] elfclassify: Add --library classification Mark Wielaard
2019-07-26 22:53                           ` Dmitry V. Levin
2019-07-26 23:04                         ` [PATCH] elfclassify tool Dmitry V. Levin
2019-07-27 11:54                           ` Mark Wielaard
2019-07-20 21:40         ` Mark Wielaard
2019-07-22 15:55         ` Florian Weimer
2019-07-26 22:11           ` Mark Wielaard
2019-07-29  8:44             ` Florian Weimer
2019-07-29 14:24               ` Mark Wielaard
2019-08-11 23:38                 ` Mark Wielaard
2019-08-12  8:14                   ` Florian Weimer
2019-08-12 15:18                     ` Mark Wielaard
2019-07-29  9:16             ` Florian Weimer
2019-07-29 14:34               ` Mark Wielaard
2019-07-29 14:38                 ` Florian Weimer
2019-08-13  9:44                   ` Mark Wielaard
2019-08-13 11:42                     ` Mark Wielaard
2019-08-14 20:46                       ` [PATCH] config/elfutils.spec.in: package eu-elfclassify Dmitry V. Levin
2019-08-15  7:33                         ` Mark Wielaard
2019-07-29  9:22             ` [PATCH] elfclassify tool Florian Weimer
2019-07-29 14:40               ` Mark Wielaard
2019-07-29 14:42                 ` Florian Weimer
2019-07-19 13:24     ` Mark Wielaard

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=84da918d32c57e6f16fbcf1c854b375111dbdcb5.camel@wildebeest.org \
    --to=hack-computer@wildebeest.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=fweimer@redhat.com \
    --cc=ldv@altlinux.org \
    --cc=pmatilai@laiskiainen.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).