Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix symbol resolution issues #48

Merged
merged 5 commits into from
Oct 25, 2022
Merged

Fix symbol resolution issues #48

merged 5 commits into from
Oct 25, 2022

Conversation

mwilck
Copy link
Contributor

@mwilck mwilck commented Oct 25, 2022

Hi @cvaroqui, hi @bmarzins,

This set fixes #47. The problem analysis can be seen in #47, and in the description of
6e8aec6. In short, if we use duplicate symbols in different shared objects, we need to keep
the versions of these symbols in sync, otherwise symbol lookup won't work as intended.

I've sent this via GitHub and not via dm-devel because it's really purely technical stuff that
matters only little for the ML, and because people who upgrade multipath-tools because of
CVE-2022-41973 and CVE-2022-41974 will be looking here.

The solution for the problem is 3-fold:

  • the symbols udev and libmpverbosity aren't duplicated any more, but defined only in libmultipath and libmpathutil, respectively.
  • This leaves get_multipath_config and put_multipath_config as duplicate symbols. For these, we use a new ABI "version" LIBMPATHCOMMON_1.0.0, with comments that make it clear that the version of these symbols must be changed synchronously in the two libraries.

Martin Wilck (5):
libmpathutil: move devt2devname() to libmultipath
libmpathutil: remove udev symbol
libmultipath: remove duplicate export of libmp_verbosity
libmpathutil: remove __attribute__((weak))
libmultipath/libmpathutil: use common ABI version for duplicate symbols

@xosevp for information.

devt2devname is under the default license and can be moved to
libmultipath.

Signed-off-by: Martin Wilck <[email protected]>
in libmpathutil, udev was only used by devt2devname. Remove it.

Signed-off-by: Martin Wilck <[email protected]>
This symbol should live in libmpathutil only.

Signed-off-by: Martin Wilck <[email protected]>
Using of __attribute__((weak)) here has no effect for dynamic
linking.

Quoting from ld.so(8): "Standard practice is that the distinction
between weak and strong symbols should have effect only at static
link time." See also the ELF specification, p. 1-18 "Symbol Table".

We would only need this if we supported static linking for
multipath-tools, which we haven't done for a long time.
Some symbols like get_multipath_config are exported by both libmpathutil and
libmultipath. The symbols exported by `libmpathutil` are dummies, intended to
be overridden by `libmultipath` using "breadth-first" symbol lookup
search specified by ELF [1]. The dummy symbols are only used by programs
not linking to libmultipath, i.e. multipathc.

Because we're using ABI versioning, code in libmpathutil actually exports *and
references* `get_multipath_config@LIBMULTIPATH_16.0.0`. That worked until
0.9.1, because both libraries were using the same ABI version, and
`get_multipath_config@LIBMULTIPATH_16.0.0` from libmultipath overrides
the symbol from libmpathutil. But in 0.9.2, we bumped the ABI version of
libmultipath to 17.0.0. libmultipath now exports (only)
`get_multipath_config@LIBMULTIPATH_17.0.0`, which does *not* override
`get_multipath_config@LIBMULTIPATH_16.0.0` from libmpathutil.

The effect is that references to these duplicate symbols from libmpathutil are
resolved to its own dummy symbols, which is wrong and causes a coredump
e.g. with "multipath -t", where the return value of get_multipath_config() is
accessed in the call chain snprint_keyword()->snprint_defaults().

This happens only with multipath, because multipathd itself overrides
get_multipath_config().

 [1]: Executable and Linkable Format (ELF)
(https://www.cs.cmu.edu/afs/cs/academic/class/15213-f00/docs/elf.pdf), p. 2-15 ("Shared Object Dependencies")

Signed-off-by: Martin Wilck <[email protected]>
@mwilck mwilck requested a review from bmarzins October 25, 2022 14:57
@mwilck
Copy link
Contributor Author

mwilck commented Oct 25, 2022

Compare to the example in #47 (comment):

[LIBMPATHCOMMON_1.0.0]
 # LD_DEBUG=bindings ./sbin/multipath -t 2>&1 | egrep '`get_multipath_config'
     15486:     binding file /tmp/mp/lib64/libmpathutil.so.0 [0] to /tmp/mp/lib64/libmultipath.so.0 [0]: normal symbol `get_multipath_config' [LIBMPATHCOMMON_1.0.0]
     15486:     binding file /tmp/mp/lib64/libmultipath.so.0 [0] to /tmp/mp/lib64/libmultipath.so.0 [0]: normal symbol `get_multipath_config' [LIBMPATHCOMMON_1.0.0]
     15486:     binding file ./sbin/multipath [0] to /tmp/mp/lib64/libmultipath.so.0 [0]: normal symbol `get_multipath_config' [LIBMPATHCOMMON_1.0.0]

get_multipath_config is now correctly resolved to the symbol from libmultipath for all referrers, in particular for libmpathutil.

@eworm-de
Copy link
Contributor

I can confirm this does no longer crash for me. Thanks a lot!

@cvaroqui cvaroqui merged commit 7da868c into opensvc:master Oct 25, 2022
Copy link
Contributor

@bmarzins bmarzins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It all looks good to me.

@eworm-de
Copy link
Contributor

Will we see a new release with this?

@mwilck
Copy link
Contributor Author

mwilck commented Oct 26, 2022

We haven't done that in the past. We usually accumulate some commits before we bump the version.
But maybe we should this time.

@cvaroqui, would you bump to 0.9.3?

@cvaroqui
Copy link
Member

Ok. Can you prepare the pr ? I will merge and tag asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

segmentation fault
4 participants