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

Missing libraries in Rescue ISO causing executables to fail #1975

Closed
rmetrich opened this issue Nov 20, 2018 · 7 comments
Closed

Missing libraries in Rescue ISO causing executables to fail #1975

rmetrich opened this issue Nov 20, 2018 · 7 comments
Assignees
Labels
bug The code does not do what it is meant to do fixed / solved / done
Milestone

Comments

@rmetrich
Copy link
Contributor

  • ReaR version ("/usr/sbin/rear -V"): 2.4 master

  • OS version ("cat /etc/rear/os.conf" or "lsb_release -a" or "cat /etc/os-release"): RHEL7

  • ReaR configuration files ("cat /etc/rear/site.conf" and/or "cat /etc/rear/local.conf"):

COPY_AS_IS+=( /non-standard-dir/lib64/* )
#PROGS+=( /lib/udev/rename_device )
  • Description of the issue (ideally so that others can reproduce it):

When adding programs into the Rescue ISO using COPY_AS_IS (typically done when using NetBackup in real life) and the directories specified contain files with same names as standard libraries (but likely at different version), the corresponding standard libraries are not included, causing some binaries that are added anyway to not be usable.
The related code is /usr/share/rear/build/GNU/Linux/100_copy_as_is.sh.
However, if a program is specified using PROG, then the required system libraries will be included anyway, because there is additional code running in /usr/share/rear/build/GNU/Linux/390_copy_binaries_libraries.sh.

Reproducer

Create a non standard path and copy "libglib" into it:

# mkdir -p /non-standard-dir/lib64
# cp /lib64/libglib-2.0.so.0 /non-standard-dir/lib64/

# rear -dD mkrescue
...
There are binaries or libraries in the ReaR recovery system that need additional libraries
/usr/lib/udev/rename_device requires additional libraries
	libglib-2.0.so.0 => not found
/usr/lib/udev/udev-kvm-check requires additional libraries
	libglib-2.0.so.0 => not found
...

# find /tmp/rear.* -name "libglib*"
/tmp/rear.gg4yN2RSDWWhD1M/rootfs/non-standard-dir/lib64/libglib-2.0.so.0

We can see from there that libglib-2.0.so.0 was not included, even though it's a must for /usr/lib/udev/rename_device.

I'm currently investigating this.

rmetrich added a commit to rmetrich/rear that referenced this issue Nov 21, 2018
… to fail

When including files in the ISO using COPY_AS_IS functionality and some of these are libraries with same name as standard system libraries, the standard system libraries are not included if an executable included through COPY_AS_IS requires a library.
This does not happen for executables specified through PROG.

Example: copy /lib64/libglib-2.0.so.0 into /non-standard-dir/lib64/ and include /non-standard-dir/lib64 in the ISO (COPY_AS_IS+=( /non-standard-dir/lib64 ))

- /usr/lib/udev/rename_device which is also included as COPY_AS_IS (in /usr/share/rear/rescue/GNU/Linux/250_udev.sh) requires /lib64/libglib-2.0.so.0 but /lib64/libglib-2.0.so.0 is not included, only /non-standard-dir/lib64/libglib-2.0.so.0 will be
- /usr/lib/udev/rename_device will not be usable in rescue due to missing library

If we now add /usr/lib/udev/rename_device to PROG (PROG+=( /usr/lib/udev/rename_device )), the library /lib64/libglib-2.0.so.0 will be included because of code in /usr/share/rear/build/GNU/Linux/390_copy_binaries_libraries.sh, so there will be no issue in that case.

The root cause of the issue is due to the grep line being used:

  grep -q "$required_library" $copy_as_is_filelist_file && continue

Because $required_library is "/lib64/libglib-2.0.so.0" and file $copy_as_is_filelist_file contains "/non-standard-dir/lib64/libglib-2.0.so.0", this will be a match, whereas it should not.

The fix consists in modifying the grep line to match a full line instead (file $copy_as_is_filelist_file contains 1 file name per line).

Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
rmetrich added a commit to rmetrich/rear that referenced this issue Nov 21, 2018
… to fail

When including files in the ISO using COPY_AS_IS functionality and some of these are libraries with same name as standard system libraries, the standard system libraries are not included if an executable included through COPY_AS_IS requires a library.
This does not happen for executables specified through PROG.

Example: copy /lib64/libglib-2.0.so.0 into /non-standard-dir/lib64/ and include /non-standard-dir/lib64 in the ISO (COPY_AS_IS+=( /non-standard-dir/lib64 ))

- /usr/lib/udev/rename_device which is also included as COPY_AS_IS (in /usr/share/rear/rescue/GNU/Linux/250_udev.sh) requires /lib64/libglib-2.0.so.0 but /lib64/libglib-2.0.so.0 is not included, only /non-standard-dir/lib64/libglib-2.0.so.0 will be
- /usr/lib/udev/rename_device will not be usable in rescue due to missing library

If we now add /usr/lib/udev/rename_device to PROG (PROG+=( /usr/lib/udev/rename_device )), the library /lib64/libglib-2.0.so.0 will be included because of code in /usr/share/rear/build/GNU/Linux/390_copy_binaries_libraries.sh, so there will be no issue in that case.

The root cause of the issue is due to the grep line being used:

  grep -q "$required_library" $copy_as_is_filelist_file && continue

Because $required_library is "/lib64/libglib-2.0.so.0" and file $copy_as_is_filelist_file contains "/non-standard-dir/lib64/libglib-2.0.so.0", this will be a match, whereas it should not.

The fix consists in modifying the grep line to match a full line instead (file $copy_as_is_filelist_file contains 1 file name per line).

Signed-off-by: Renaud Métrich <rmetrich@redhat.com>

M
@jsmeix jsmeix self-assigned this Nov 21, 2018
@jsmeix jsmeix added the bug The code does not do what it is meant to do label Nov 21, 2018
@jsmeix jsmeix added this to the ReaR v2.5 milestone Nov 21, 2018
@jsmeix
Copy link
Member

jsmeix commented Nov 21, 2018

@rmetrich
again many thanks for your continuous and careful testing
that reveals such hidden bugs that only happen in special cases!

@jsmeix
Copy link
Member

jsmeix commented Nov 21, 2018

@rmetrich
I wonder about your reproducer:
I think one cannot "just change" the actual libraries files
without also adapting the dynamic linker configuration
i.e. adapt dynamic linker config files like /etc/ld.so.conf
and finally run ldconfig - or do I misunderstand it?

@rmetrich
Copy link
Contributor Author

That's just an example. In real life, this happens when doing relaxed COPY_AS_IS such as the one done for ... NetBackup ... : /usr/openv/lib which contains unrelated libraries and probably unneeded ones.

rmetrich added a commit to rmetrich/rear that referenced this issue Nov 21, 2018
… to fail

When including files in the ISO using COPY_AS_IS functionality and some of these are libraries with same name as standard system libraries, the standard system libraries are not included if an executable included through COPY_AS_IS requires a library.
This does not happen for executables specified through PROG.

Example: copy /lib64/libglib-2.0.so.0 into /non-standard-dir/lib64/ and include /non-standard-dir/lib64 in the ISO (COPY_AS_IS+=( /non-standard-dir/lib64 ))

- /usr/lib/udev/rename_device which is also included as COPY_AS_IS (in /usr/share/rear/rescue/GNU/Linux/250_udev.sh) requires /lib64/libglib-2.0.so.0 but /lib64/libglib-2.0.so.0 is not included, only /non-standard-dir/lib64/libglib-2.0.so.0 will be
- /usr/lib/udev/rename_device will not be usable in rescue due to missing library

If we now add /usr/lib/udev/rename_device to PROG (PROG+=( /usr/lib/udev/rename_device )), the library /lib64/libglib-2.0.so.0 will be included because of code in /usr/share/rear/build/GNU/Linux/390_copy_binaries_libraries.sh, so there will be no issue in that case.

The root cause of the issue is due to the grep line being used:

  grep -q "$required_library" $copy_as_is_filelist_file && continue

Because $required_library is "/lib64/libglib-2.0.so.0" and file $copy_as_is_filelist_file contains "/non-standard-dir/lib64/libglib-2.0.so.0", this will be a match, whereas it should not.

The fix consists in modifying the grep line to match a full line instead (file $copy_as_is_filelist_file contains 1 file name per line).

Signed-off-by: Renaud Métrich <rmetrich@redhat.com>

M
@jsmeix
Copy link
Member

jsmeix commented Nov 21, 2018

@rmetrich
your #1976 explains it all.
It is a generic bug in ReaR.

jsmeix added a commit that referenced this issue Nov 21, 2018
Missing libraries in recovery system caused executables to fail,
see #1975
because in build/GNU/Linux/100_copy_as_is.sh
libraries were skipped from copying when their library path
was a substring of another already copied library, for example
/path/to/lib was skipped when /other/path/to/lib was already copied.
@jsmeix
Copy link
Member

jsmeix commented Nov 21, 2018

With #1976 merged
this issue should be fixed.

@rmetrich
many thanks for your analysis what the root cause was and your fix!

@jsmeix jsmeix closed this as completed Nov 21, 2018
@jsmeix
Copy link
Member

jsmeix commented Nov 21, 2018

I found a simple reproducer that emphasizes
this generic bug (before the fix here) even more.

I only added to my etc/rear/local.conf

COPY_AS_IS=( "${COPY_AS_IS[@]}" /usr/sbin/postfix /doesnotexist/usr/lib/postfix/libpostfix-global.so )

and "rear -D mkrescue" failed with

Testing that the recovery system in /tmp/rear.8eGP5wvyks7HAf1/rootfs contains a usable system
There are binaries or libraries in the ReaR recovery system that need additional libraries
/bin/postfix requires additional libraries (fatal error)
        libpostfix-global.so => not found
ReaR recovery system in '/tmp/rear.8eGP5wvyks7HAf1/rootfs' needs additional libraries, check /root/rear.github.master/var/log/rear/rear-g243.log for details
ERROR: ReaR recovery system in '/tmp/rear.8eGP5wvyks7HAf1/rootfs' not usable (required libraries are missing)

For me ldd /usr/sbin/postfix shows in particular

libpostfix-global.so => /usr/lib/postfix/libpostfix-global.so

but copying /usr/lib/postfix/libpostfix-global.so is skipped
in build/GNU/Linux/100_copy_as_is.sh because
the copy_as_is_filelist_file contains

tar: /doesnotexist/usr/lib/postfix/libpostfix-global.so: Cannot stat: No such file or directory

cf. the comment in build/GNU/Linux/100_copy_as_is.sh about
"make it work fail-safe even in case of non-existent files in the COPY_AS_IS array"

I.e. even files that failed to copy may have matched before this fix here.

@rmetrich
Copy link
Contributor Author

Good point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The code does not do what it is meant to do fixed / solved / done
Projects
None yet
Development

No branches or pull requests

2 participants