Commit Graph

13599 Commits

Author SHA1 Message Date
Panu Matilainen 6e7c6d1a18 Revised fix for CVE-2013-6435
In case of hardlinked files, we first create a zero-length file
to which all the links are created, the content comes in the last
link. When the links have been created with no permissions at all
(as per commit 7e26e2bd72), reopening
the final file for writing the actual content fails for non-root users.
Which breaks installation of hardlinked files for regular users,
including our testsuite.

Creating the files with write-only permissions solves the issue - we
*are* writing to these files afterall so it only makes sense.
This doesn't stop root from reading the file but neither does zero
permissions so no change there. But if somebody reads a file with
write-only permissions and gets garbage, at least we get to tell
them "told you so".
2016-10-11 09:58:15 +03:00
Panu Matilainen 94bb6283be Revert "Always set file attribute for hard linked files"
This reverts commit a42a8cc175.
On closer examination this makes hardlinked files vulnerable to
CVE-2013-6435 again, so it's not a very good fix for breakage
caused by fixing CVE-2013-6435.
2016-10-11 09:39:20 +03:00
Mark Wielaard 3f9b7bc64e Fix mini-symtab in find-debuginfo.sh for arches with function descriptors.
add_minidebug uses nm to select the function symbols to include in the
mini-symtab table. But on arches that use function descriptors (like ppc64)
nm --format-posix doesn't make it clear which symbols are real functions
The symbols point to the (stripped away) function descriptor table).

Use --format=sysv style to match the ELF symbol type directly instead of
using the somewhat ambiguous symbol type char used in --format=posix style
in binutils nm.

https://bugzilla.redhat.com/show_bug.cgi?id=1052415

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-10-10 15:13:18 +03:00
Mark Wielaard bd7611151b find-debuginfo.sh: Don't copy extra sections into .gnu_debugdata.
When creating the compressed mini-symtab section in find-debuginfo
add_minidebug we explicitly remove .gdb_index and .comment. But there
can be other non-empty sections in the debuginfo that shouldn't be
copied. For example rust binaries might have a .rustc section.

Explicitly remove any non-allocated PROGBITS or NOTE sections.

https://bugzilla.redhat.com/show_bug.cgi?id=1382394

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-10-10 15:13:18 +03:00
Stefan Berger 9d8c7b6dbd ima-plugin: Move the IMA plugin to the fsm_file_prepare hook
Since newly installed files may be invoked by post install scriptlets,
we need to have them signed before the scriptlets are executed.
Therefore, we now move the IMA plugin to the fsm_file_prepare hook.
This way we can also correctly handle skipped files without silencing
away any errors from lsetxattr().

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-10-10 15:09:52 +03:00
Stefan Berger 7d89f49c4d ima-plugin: Have executable configuration files signed
Some configuration files are executables and so they require the
signature in the extended attribute. If they are not executable,
they can be skipped.

Examples for configuration files that are also executables are
the grub files in /etc/grub.d.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-10-10 14:54:42 +03:00
Florian Festi a6e662f6bd rpm2archive: return 0 on success instead of stop iteration
Solves: https://github.com/rpm-software-management/rpm/pull/94/files
Thanks to Neal Gompa (ニール・ゴンパ)<ngompa13@gmail.com> for spotting this
and proposing a solution!
2016-10-10 11:57:14 +02:00
Florian Festi a42a8cc175 Always set file attribute for hard linked files
Fixes test cases broken by previous commit
2016-10-07 17:39:23 +02:00
Florian Festi 7e26e2bd72 Create files with with 000 permissions to avoid leaking yet unchecked data
As we are calculating the check sum while writing we only know the file
content is correct after it being written comletely. CVE-2013-6435
2016-10-07 17:32:55 +02:00
Panu Matilainen 73a8f43b2b Bump version to appear newer than latest stable branch 2016-10-03 14:47:58 +03:00
Panu Matilainen b1e7ce8153 Remove leftover include of <selinux/flask.h>
Besides unused, this has started spitting warnings in recent selinux versions:
In file included from selinux.c:5:0:
/usr/include/selinux/flask.h:5:2: warning: #warning "Please remove any #include's of this header in your source code." [-Wcpp]
 #warning "Please remove any #include's of this header in your source code."
  ^~~~~~~
2016-10-03 13:57:56 +03:00
Panu Matilainen 2ea72daabe Fix behavior when %_build_id_links is undefined
Commit bbfe1f86b2 tries to behave sanely
and use compat setting when %_build_id_links is undefined, but
rpmExpand() never returns NULL so the original check is incorrect.
Check for empty string instead.
2016-10-03 12:36:46 +03:00
Panu Matilainen 689d9a53dd Preserve timestamps by default in %make_install (RhBug:959872) 2016-10-03 10:38:47 +03:00
Gleb Fotengauer-Malinovskiy e5d3b9f682 rpmdb.c: (rpmdbCheckTerminate) return non-zero on subsequent runs
This function is not necessarily called first by rpmdbCheckSignals, as
long as it is a part of API.  Thus, it is important to return the same
value on subsequent runs.

Signed-off-by: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
2016-09-21 10:26:39 +02:00
Gleb Fotengauer-Malinovskiy 4c6e51e2c0 rpmdb.c: avoid double free in rpmdbClose, rpmdbMatchIterator, ...
... and rpmdbIndexIterator.
This makes functions assume that the object has been freed if it is not
on the list.

Signed-off-by: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
2016-09-21 10:26:39 +02:00
Mark Wielaard e41550e375 Fix misleading-indentation in rpmplugins.c
GCC6 will warn about:

lib/rpmplugins.c: In function ‘rpmpluginsCallInit’:
lib/rpmplugins.c:217:5: warning: this ‘if’ clause does not guard...
     if (hookFunc)
     ^~
lib/rpmplugins.c:219:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
         if (rc != RPMRC_OK && rc != RPMRC_NOTFOUND)
         ^~

GCC is right, this is misleading and causes the if statement to be executed
even when it isn't necessary. It doesn't actually cause wrong results
because rc is initialized to RPMRC_OK earlier and can only change when
hookFunc != NULL.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-09-21 10:10:09 +02:00
Michal Marek 1b338aa84d find-debuginfo.sh: Process files in parallel
Add a -j <n> option, which, when used, will spawn <n> processes to do the
debuginfo extraction in parallel. A pipe is used to dispatch the files among
the processes.

Signed-off-by: Michal Marek <mmarek@suse.com>
2016-09-15 17:05:01 +02:00
Michal Marek 038bfe0179 find-debuginfo.sh: Split directory traversal and debuginfo extraction
This siplifies the handling of hardlinks a bit and allows a later patch
to parallelize the debuginfo extraction.

Signed-off-by: Michal Marek <mmarek@suse.com>
2016-09-15 17:05:01 +02:00
Pavel Raiskup 0d76d6114d build: better warning for non-unique %files section
Background story is in rhbz#1374138, having the warning better
spelled before would simplify macro debugging a lot in that case.
2016-09-15 12:43:34 +02:00
Thomas Petazzoni b5f1895aae configure.ac: use link instead of compile for gcc flags test
The logic that tests whether gcc supports or not certain flags uses
AC_COMPILE_IFELSE(). However, when checking for stack smashing
protection support, an AC_LINK_IFELSE() test is needed, since the
build might work but not the link stage if certain libraries are
missing for proper stack smashing protection support.

Therefore, this commit switches to use AC_LINK_IFELSE().

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: James Knight <james.d.knight@live.com>
2016-09-12 23:33:02 -04:00
Alexey Gladkov 19dbaff8dd rpm2cpio.sh: refactoring to reduce extra dependencies
rpm2cpio.sh was refactored to minimize the use of external tools.

* after refactoring the utility requires to work: dd, printf, and unarchivers;
* add check that file passed as argument is a rpm-file;
* fix signatures of compressed data.

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2016-09-12 15:04:08 +02:00
Igor Gnatenko 58a9cc704f Makefile.maint: use git-rev-list
No need to query all commits and count lines of output, we can just ask git to provide information directly.
2016-09-12 14:59:30 +02:00
Per Øyvind Karlsen a60f36a55c prevent exceeding 32 bit memory limitations with multithreaded xz compression
As 32 bit build suffers under the limitation of 32 bit address space,
regardless of it's environment would be ie. 64 bit and not have this
constration, rpm must make sure not to exceed this memory limitation.
When using multithreaded xz compression, the number of threads used will
increase the memory usage, making it necessary to check the memory
required with the number of threads to be used.

Number of compression threads will therefore be kept reduced untill
amount of memory required won't exceed this limitation.

For 32 bit binaries running under 64 bit host environment, where less
available memory will be reserved for kernel, easing memory constraints,
determination of this will be done by a combination of checking host
arch as well as whether 32 bit personality flag is set, thereby still
allow a sligthly greater memory usage for such cases to avoid
imposing unnecessatry limitations under such environments.
2016-09-09 02:12:01 +02:00
Jakub Filak 932f14fdf8 macros: make rpmsig's gpg command alterable
The current version of gpg2 asks for password using a curses dialogue
or a GTK dialogue. Both methods breaks automation of package signing.

If we want to be asked the old way on terminal, we must run gpg2 with
additional arguments '--pinentry-mode loopback' (and gpg-agent must be
allow looping back (--allow-loopback) - allowed by default since 2.1.13).

Currently there is no other way how to tweak gpg command line than
creating a wrapper script and redefining %__gpg macro.

The wrapper script method can lead to use of wrong version of gpg
binary, hence, this patch adds possibility to specify additional command
lines argument passed on gpg's command line.

Signed-off-by: Jakub Filak <jfilak@redhat.com>
2016-09-08 17:42:40 +02:00
Igor Gnatenko 1f553f9cdc macros: check if GNU Make supports -O
Otherwise on old platforms which have GNU Make < 4.0 it will fail with:
/usr/bin/make: invalid option -- 'O'

We could check version of GNU Make, but we want to rely on feature, and
not on the version. Features can be backported.

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Acked-by: Alexey Gladkov <agladkov@redhat.com>
2016-09-06 16:58:03 +02:00
Florian Weimer f255c6bdb2 Fix overflow in cpio filename by limiting the allowed length to 4kB
This could lead to a stack-based overflow, while parsing a crafted CPIO header in the payload section of an RPM file.

Fixes: rhbz#1168715, CVE-2014-8118
2016-09-05 10:12:29 +02:00
Florian Festi 394cbfb668 tests: Do not pass real pathnames to fakechroot commands
for the remaining tests.
Also add a Provides: /bin/sh to one of the specs as the test does no longer
works without for some unknown reason.
2016-08-29 18:12:42 +02:00
Michal Marek 5b8b2bdd32 tests: Do not pass real pathnames to fakechroot commands
Fakechroot returns -ENOENT for such paths:

$ FAKECHROOT_BASE=$PWD/tests/testing fakechroot ls /not_an.rpm
/not_an.rpm
$ FAKECHROOT_BASE=$PWD/tests/testing fakechroot ls $PWD/not_an.rpm
ls: cannot access /home/mmarek/GIT/rpm/not_an.rpm: No such file or directory

Signed-off-by: Michal Marek <mmarek@suse.com>
2016-08-29 16:21:15 +02:00
Neal Gompa (ニール・ゴンパ) 89394bfcc8 pythondistdeps.py: Add --majorver-only dependency switch
Tomas Orsava from the Fedora Python SIG requested that
the dependency generator support only using pythonXdist(M)
format for both Provides and Requires, so now this capability
exists.
2016-08-29 08:36:52 -04:00
Stefan Berger 3171982612 rpmsign: Use default hash algo if RPMTAG_FILEDIGESTALGO missing
Use the default hash algorithm md5 on RPMs that do not contain the
RPMTAG_FILEDIGESTALGO. This may be the case if the default hash
algorithm used on files is md5 and thus no RPMTAG_FILEDIGESTALGO is
being written (see build/files.c:genCpioListAndHeader()).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-08-24 18:22:49 +02:00
Mark Wielaard 10633641ec Fix libdw configure check.
commit a82119 "configure.ac: use LIBDW always conditionally" contained
a typo that caused WITH_LIBDW_LIB never to be set when you were using
libelf. Fixed by reverting the "!=" to "=" again.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-08-24 18:22:49 +02:00
Igor Gnatenko 30d472c8af pythondistdeps.py: add forgotten import
Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
2016-08-24 15:37:16 +02:00
Igor Gnatenko a82119bf35 configure.ac: use LIBDW always conditionally
References: https://bugzilla.redhat.com/show_bug.cgi?id=1365278
Reported-and-tested-by: Neal Gompa <ngompa13@gmail.com>
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2016-08-24 14:07:22 +02:00
Richard W.M. Jones 3910b1d1cf build: fgetc returns int, not char.
Returning the value into a char is a mistake on all platforms, but is
particularly bad on RISC-V.  On that platform (like ARM) char is
unsigned.  Therefore EOF (-1) is returned as 255, and the subsequent
test 'c == EOF' ('255 == -1') fails causing an infinite loop.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
2016-08-24 13:56:17 +02:00
Richard W.M. Jones cf5679397f rpmrc: Convert uname.machine == "riscv" to "riscv32"/"riscv64"/"riscv128".
On RISC-V, the kernel can return uname.machine == "riscv" (for all bit
sizes).  I say "can" return, because that is the default, but it is
also possible to compile the kernel specially so it returns "riscv64"
etc.

GNU is using "riscv64".

This commit converts the kernel uname machine type "riscv" to a more
suitable value.

This conversion is supposed to be done by the arch_canon table.
However the arch_canon table is not populated until after the
defaultMachine function is called for the first time, making it a bit
useless.  In any case, arch_canon cannot take into account the bit
size of the architecture, but the C code here can.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
2016-08-22 21:16:48 +01:00
Richard W.M. Jones d9d47e0114 RISCV 64-bit (riscv64) support.
Based on Mark Salter's aarch64 support patch (commit 8e1ca16c58).

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
2016-08-22 21:16:48 +01:00
Igor Gnatenko 83e4d44b80 pythondistdeps.py: skip .egg-link files
From setuptools's documentation:
These files are not eggs, strictly speaking. They simply provide a way
to reference an egg that is not physically installed in the desired
location. They exist primarily as a cross-platform alternative to
symbolic links, to support "installing" code that is being developed in
a different location than the desired installation location.

If we read .egg-link using pkg_resources.Distribution it will
never have version as it is just list of directories which should be
taken into account.

We could change into that directories and add eggs from those locations
for parsing, but RPM's dependency generator already passing all files
from built RPM so it just does not make any sense to traverse those
directories.

After all written above, let's just ignore .egg-link files.

Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
2016-08-22 15:19:08 +02:00
Igor Gnatenko 2f51022e15 pythondistdeps.py: show warning if version is not found in metadata
In 49197c930b we introduced skipping
metadata which has no version, but it's better to show some warning.

Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
2016-08-22 15:04:42 +02:00
Neal Gompa (ニール・ゴンパ) 49197c930b pythondistdeps.py: skip distribution metadata if there is no version
For example, reading .egg-link using pkg_resources.Distribution returns
actual metadata, but it does not contain version. It returns traceback like:

File "/usr/lib/rpm/pythondistdeps.py", line 113, in <module>
    pyver_major = dist.py_version.split('.')[0]
AttributeError: 'NoneType' object has no attribute 'split'
Traceback (most recent call last):
  File "/usr/lib/rpm/pythondistdeps.py", line 113, in <module>
    pyver_major = dist.py_version.split('.')[0]
AttributeError: 'NoneType' object has no attribute 'split'

Let's just skip such errors as we can't do much about that.

Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1368673
Reported-and-tested-by: Igor Gnatenko <ignatenko@redhat.com>
2016-08-22 15:02:54 +02:00
Igor Gnatenko 9571218345 let debuginfo packages provide the build-id
This patch lets debuginfo packages provide build-id like follows:

 debuginfo(build-id) = c63cb23876c5fa85f36beaff58f8557e1bf22517

Originally this patch was written by Jan Blunck <jblunck@suse.de>.

Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
2016-08-03 12:10:40 +02:00
Mark Wielaard 45bfecbf7d Add option to have unique debug file names across version/release/arch.
Introduce a new macro _unique_debug_names that when set will pass
--unique-debug-arch "%{_arch}" to find-debuginfo.sh to create debuginfo
files which end in "-<ver>-<rel>.<arch>.debug" instead of simply ".debug".

Adds testcases for dwz and buildid with and without unique debug file names.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:29:10 +02:00
Mark Wielaard 67d3df3388 Make adding GDB index sections configurable.
Introduces _include_gdb_index macro and -i flag to find-debuginfo.sh to
enable or disable adding a .gdb_index section to debug files. Adds tests
to make sure the .gdb_index is really added (or not) when requested.
Checks that gdb-add-index is actually installed instead of silently
failing if not. Similar for dwz.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:28:53 +02:00
Mark Wielaard 5ef1166ad9 Make it possible to have unique build-ids across build versions/releases.
Introduce a new macro _unique_build_ids that when set will pass the
version and release to find-debuginfo.sh and debugedit to recalculate
the build-id of ELF files.

Includes two new testcases to make sure the new setting works as expected
both when set and unset.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:28:53 +02:00
Mark Wielaard bbfe1f86b2 Add build-id links to rpm for all ELF files.
This patch moves the main ELF file build-id symlinks from the
debuginfo package into the main package. And uses different
base directories for the main ELF file build-id symlink.
For the main build-id use /usr/lib/.build-id and for the debug
build-id use /usr/lib/debug/.build-id.

There are two reasons for doing this. The main package and the
debuginfo package might get out of sync, or the debuginfo package
might not be installed at all. In which case finding the main ELF
file through the build-id symlink becomes impossible. Secondly by
moving the main ELF build-id symlink in its own directory the
/usr/lib/debug directory gets populated with only debuginfo files
which is convenient if the user might want to have that directory
populated through a network mountpoint.

To support the new logic the symlink code has been moved from
find-debuginfo.sh to build/files.c.

This also includes support for a new config %_build_id_links that
defaults to compat. The other settings are none, alldebug (the old
style) and separate. compat is like separate, but adds a compatibility
link under /usr/lib/debug/.build-id for the main build-id symlink.

There are several new testcases added to test the various settings
using the new keyword "buildid".

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:28:53 +02:00
Mark Wielaard 4ec7c396fb Add sepdebugcrcfix to fixup old style gnu_debuglink CRC checksum.
Some old tools might still use the .gnu_debuglink section to find
separate debuginfo files instead of build-id style lookups. When
dwz has compresses the .debug files the original CRC in the main
ELF file will no longer match. Make sure to run sepdebugcrcfix
after dwz to recalculate the CRC.

The original fix was created by Jan Kratochvil based on code
from GNU binutils BFD. https://bugzilla.redhat.com/show_bug.cgi?id=971119
I added a testcase to make sure the CRCs were all correctly
updated after dwz has run to compress a debuginfo package.
And a change (plus testcase) to make sure implicit suid binaries
didn't accidentially got their suid flag bit.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:28:53 +02:00
Mark Wielaard 41c4dcf507 Don't use hardcoded paths to tools/scripts in find-debuginfo.sh.
This prevents installation and testing in any other location than
/usr/lib/rpm.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:28:53 +02:00
Mark Wielaard 6b3b435fa6 Add dwz debuginfo compression support.
Support for dwz compression has been in Fedora since a couple of years.
https://fedoraproject.org/wiki/Features/DwarfCompressor

The original find-debuginfo.sh patch was written by Jakub Jelinek.
https://bugzilla.redhat.com/show_bug.cgi?id=833311
The new testcase using the macros.debug was added by me.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:28:53 +02:00
Mark Wielaard b33a41da36 Add find-debuginfo.sh -m minisymtab support.
Support for minisymtab (a minimal function symbol table in a compressed
section in the main binary) has been in gdb and elfutils based tools
since some years. Fedora has had this as rpm-4.10.0-minidebuginfo.patch
since 2012.

The patch adjusts macros to pass -m to find-debuginfo.sh when
_include_minidebuginfo has been set. find-debuginfo.sh now takes -m
as argument to generate the .gnu_debugdata ELF section to be added
to the main executable.

To support the testcases a new macros.debug is added that is used to
generate debuginfo packages in the rpmbuild.at testsuite.

The original support was added to Fedora rpm by Alexander Larsson.
Lubos Kardos fixed a bug in it when strip -g was used. I added some
configuration macros and two testcases to check the basic support works
and for the strip -g bug.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:28:53 +02:00
Ville Skyttä 0e51d17004 Remove some unnecessary assignments flagged by cppcheck 2016-07-29 17:41:36 +02:00
Frederic Bonnard 1ac507f15f Fix preun scriptlet failure not aborting rpm erase
Since commit f4a49c3d44 ( Unceremoniously
eliminate rpmpsmNext() ), when a preun scriptlet is failing, rpm continues to
be erased. Handling return code of runInstScript.
2016-07-29 17:36:41 +02:00