View Issue Details

IDProjectCategoryView StatusLast Update
0000059bareos-corefile daemonpublic2014-05-16 17:43
ReporterdanielAssigned To 
PrioritylowSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformLinuxOSUbuntuOS Version12.04
Fixed in Version14.2.0 
Summary0000059: bareos failed to start when linked with hardening linker flags LDFLAGS
DescriptionThe bareos-fd doesnt start on Ubuntu 12.0.4, he crashes direct after starting the service using the service call or direct call (/etc/init.d/bareos-fd start).
The reason is a missing working directory, as you can see in the additional information.
Additional Information-------------- create bareos-fd.config ------------
[SSH] exit-status: 0
executing script:

echo "--------- starting services ---------- "
service bareos-fd start

--------- starting services ----------
Starting Bareos File Daemon: 08-Feb 09:53 ubuntu12fresh: ERROR TERMINATION at util.c:863
Working directory not defined. Cannot continue.
bareos-fd
TagsNo tags attached.

Relationships

child of 0000202 closed Config engine redesign 

Activities

mvwieringen

mvwieringen

2013-02-08 11:56

developer   ~0000083

Could you try setting the working explicitly in the bareos-fd.conf ?

The error message is printed when no working directory is set which
is strange as there is a default compiled into the code so it should
always be set.

Its also strange we only see this on this platform is on other platforms
the working directory still in the configs ?
daniel

daniel

2013-02-08 13:03

reporter   ~0000084

Last edited: 2013-02-08 14:06

Adding the working directory in the conifg, doesnt work right. Only the error output disappears. And ther are no trace files in the working/pid directory and no running fd.

No there is no working directory in the configs anymore. Yeah this problem only exists on ubuntu.

root@ubuntu12fresh:/var/lib# bareos-fd -c /etc/bareos/bareos-fd.conf -d200
bareos-fd: filed_conf.c:472-0 Inserting director res: dir-ci-mon
ubuntu12fresh: message.c:343-0 Copy message resource f67c48 to f8b178
root@ubuntu12fresh:/var/lib# 08-Feb 13:25 ubuntu12fresh: ERROR TERMINATION at bsys.c:549
Could not open pid file. <NULL>/bareos-fd.9102.pid ERR=Datei oder Verzeichnis nicht gefunden

mvwieringen

mvwieringen

2013-02-12 18:26

developer   ~0000093

Compiled the code on Ubuntu 12.04 LTS in Virtual box cannot reproduce it there
just works. Did find some problems as I didn't have zlib there so this at least
gave some fixes.

Only way to determine what goes wrong here is to have debugging package and put
a debugger on the binary and see what is happening.

We also found some problems in the Ubuntu autoconf stuff so that may also
help to fix it, but it could be still be broken on this specific platform.
joergs

joergs

2013-02-15 18:42

developer   ~0000113

It seems, that problem is only triggered, when Bareos is compiled in OBS.

Things already tested:
  - remove optimization (-O2), compile with -O0: same problems as before
  - compiler version are identical on local testsystem (working) and OBS chroot environment:
    # dpkg -l | grep gcc
ii gcc 4:4.6.3-1ubuntu5 GNU C compiler
ii gcc-4.6 4.6.3-1ubuntu5 GNU C compiler
ii gcc-4.6-base 4.6.3-1ubuntu5 GCC, the GNU Compiler Collection (base package)
joergs

joergs

2013-02-15 18:46

developer  

config.out (2,615 bytes)
joergs

joergs

2013-02-15 18:47

developer   ~0000114

I added the config.out from obs, optimization disabled, still not working.
joergs

joergs

2013-02-15 18:50

developer  

.build.log (325,679 bytes)
joergs

joergs

2013-02-15 18:50

developer   ~0000115

and also the full build log.
mvwieringen

mvwieringen

2013-02-16 17:45

developer   ~0000118

using gdb debugging I have figured out the problem no idea why it happens
but the config engine uses function pointers that handle certain conversions
e.g. to store a bool, string etc. Those function pointers are stored in the
config array and both the default initialization in init_resource but also
some other places compare the function pointer in the config table with the
actual address of the function to determine what type is being processed.

The problem on Ubuntu seems to be that the stored function pointer in the
config table smells like a 32 bits pointer but when you ask for the address
of the actual function you get a 64 bit pointer so the compare logic woes
and as such the default is never set. This also explains why explicitly setting
the value doesn't work as there is similar pointer comparison going on there.

This smells very much like the new x32 ABI on x86_64. The bacula code because
that is where this whole code originates from seems to have problems when
pointers have random sizes which seems to be the case. What I can find is that
this is enable by the -mx32 option so maybe compiling with explicitly -m64 will
solve this problem or we need some more stuff to handle the x32 ABI and when
comparing the function pointers we need some macro that truncates the pointer
or convert it in the same manner as the ABI does to 32 bit.

An other possible solution is adding a type field to the config tables and
no longer compare function pointers but that may only solve this particular
problem.
mvwieringen

mvwieringen

2013-02-17 22:33

developer   ~0000123

Ok small misinterpretation on my side as what gdb prints when printing a
function pointer and what is printed by gdb when you resolve a functionname.
It seems the print of a structure with a function pointer always prints the
short representation of the function pointer and the printing of the function
pointer directly looks differently but that is normal. What is a problem is
that the version build by OBS has a problem where comparing a function pointer
doesn't work (watched it with gdb and it just never matches any function pointer,
when doing it on a hand compiled version of ubuntu I cannot reproduce this and
it just matches the function pointer and jumps into the function as initializes
the default value (for all data, the misfiring version fails for all default
data not only for the working dir.) It also seems the whole trick used by the
config engine by calculating the data offset into the structure doesn't
work and that explains why also explicitly setting a value doesn't set the
value in the structure.) It must have something to do with the exact compiling
options.

I first thought it could be related to the special linker flags passed on

-Wl,-Bsymbolic-functions -Wl,-z,relro

but adding these to the working hand compiled version doesn't result in
a non working version. This turns into some kind of needle/haystack search.

Its something that you can show in the debugger but there is no clue as
to why it happens and why something that has worked for ages now all of
sudden does not.
mvwieringen

mvwieringen

2013-02-17 22:39

developer   ~0000124

Ok wrong test set.

The LDFLAGS are the problem !!!!

So we should remove the -Wl,-Bsymbolic-functions -Wl,-z,relro
mvwieringen

mvwieringen

2013-02-18 12:37

developer   ~0000126

Tried disabling the hardening in the debian/rules file but it seems
Ubuntu has its own idea on these items and ignores the documented
hints.
joergs

joergs

2013-02-19 18:42

developer   ~0000129

I've compiled Ubuntu now with disabled hardening.
Configure outputs:
Compiler flags: -g -O2 -Wall -fno-strict-aliasing -fno-exceptions
Linker flags: -Wl,-Bsymbolic-functions
Libraries: -lpthread -ldl -ldl

However the behavior is the same as before.
joergs

joergs

2013-02-19 18:43

developer  

0002-disable-hardening.patch (840 bytes)   
From 14a168d83b9a1358524a46ddc5be55a524cbdf7b Mon Sep 17 00:00:00 2001
From: Joerg Steffens <joerg.steffens@bareos.com>
Date: Tue, 19 Feb 2013 17:14:55 +0100
Subject: [PATCH 2/2] disable hardening

---
 debian/rules |    7 ++++++-
 1 Datei geändert, 6 Zeilen hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/debian/rules b/debian/rules
index 7e68870..b04cafd 100755
--- a/debian/rules
+++ b/debian/rules
@@ -17,7 +17,12 @@ DH_VERBOSE = 1
 DH_OPTIONS = -v
 
 # This disables the hardening flags which lead to LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro which breaks the config engine.
-DEB_BUILD_HARDENING = 0
+#DEB_BUILD_HARDENING = 0
+#DEB_LDFLAGS_SET =
+export DEB_BUILD_MAINT_OPTIONS = hardening=-all
+DPKG_EXPORT_BUILDFLAGS = 1
+-include /usr/share/dpkg/buildflags.mk
+
 
 DAEMON_USER = bareos
 DAEMON_GROUP = bareos
-- 
1.7.10.4

joergs

joergs

2013-02-19 18:47

developer   ~0000130

Patch to disable hardening is attached.
There is still the -Wl,-Bsymbolic-functions flags.
I'm trying to disable them also.
joergs

joergs

2013-02-19 19:04

developer   ~0000131

Same problems with:
Compiler flags: -g -O2 -Wall -fno-strict-aliasing -fno-exceptions
Linker flags:
Libraries: -lpthread -ldl -ldl

@Marco: do you see anything still wrong with these flags?
How can I verify, that a compiled and linked binary is really made with this flags?
mvwieringen

mvwieringen

2013-02-19 19:41

developer   ~0000132

No flags look ok. After doing some more tests myself I can at will
make this appear and disappear by linking the libbareoscfg-13.1.0.so
shared library with and without the -Wl,-Bsymbolic-functions

So I can for sure say that its related to -Wl,-Bsymbolic-functions

Its even so simple that if you change the LDFLAGS in the Makefile
and do a rm libbareoscfg.la and then a make it will generate a new shared
lib without recompiling any sources and that leads to a working shared lib
when you remove the above entry from it.

The problem is however you cannot really see any difference in the two
generated libraries already tried the obvious nm -p for symbols which
look almost the same (small memory offset differences but nothing
more) and also objdump -T or objdump -h don't show anything obvious.

What you could do is use the attached libbareoscfg-13.1.0.so file
which is the correctly compiled version.

This version works for me for letting bareos-fd start with

bareos-fd -f -d 200 -c ./bareos-fd.conf in the src/filed dir.
mvwieringen

mvwieringen

2013-02-19 19:41

developer  

libbareoscfg-13.1.0.so (208,697 bytes)
mvwieringen

mvwieringen

2013-02-19 19:51

developer   ~0000133

Installed current OBS 13.1.0 deb packages e.g. only comon (e.g. libs) and
filed and that fails. Replacing the libbareoscfg-13.1.0.so file and the same
binary works.
pstorz

pstorz

2013-02-19 23:32

administrator   ~0000134

by setting the LDFLAGS directly before the configure run, we can disable the LDFLAGS. This seems to be the only option that works.

That way, we have the jenkins regressions run without problems, only the mysql tests have a problem with access control, but that should be a minor problem.
joergs

joergs

2013-02-20 08:00

developer  

0002-disable-hardening-by-settings-LDFLAGS.patch (904 bytes)   
From 0b985a5a327e67d394b35e7d2ce4d9bf2ebcee2d Mon Sep 17 00:00:00 2001
From: Joerg Steffens <joerg.steffens@bareos.com>
Date: Tue, 19 Feb 2013 17:14:55 +0100
Subject: [PATCH 2/2] disable hardening by settings LDFLAGS

---
 debian/rules |    8 +++++++-
 1 Datei geändert, 7 Zeilen hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/debian/rules b/debian/rules
index 7e68870..b1b4130 100755
--- a/debian/rules
+++ b/debian/rules
@@ -17,7 +17,13 @@ DH_VERBOSE = 1
 DH_OPTIONS = -v
 
 # This disables the hardening flags which lead to LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro which breaks the config engine.
-DEB_BUILD_HARDENING = 0
+#DEB_BUILD_HARDENING = 0
+#DEB_LDFLAGS_SET =
+export DEB_BUILD_MAINT_OPTIONS = hardening=-all
+export DEB_LDFLAGS_SET := -Wl,--as-needed
+DPKG_EXPORT_BUILDFLAGS = 1
+-include /usr/share/dpkg/buildflags.mk
+
 
 DAEMON_USER = bareos
 DAEMON_GROUP = bareos
-- 
1.7.10.4

joergs

joergs

2013-02-20 08:07

developer   ~0000138

with Patch https://bugs.bareos.org/mantis/file_download.php?file_id=7&type=bug it also seems to work.
Difference is, that LDFLAGS is now set to a value, instead setting it to blank.

What OBS (dpkg-buildpackage) is doing is first call dpkg-buildflags to get the system compiler and linker flags and set them as environment variables.

Our debian/rules makefile is executed after this.

Setting LDFLAGS to "" looked as it has helped, but the result have been the same.
By setting LDFLAGS to some, hopefully safe value, it seems to work.

However, I'll take a closer look to it tomorrow, when I'll be in the office again.
joergs

joergs

2013-02-27 13:58

developer   ~0000196

currently, we have a workaround.
Looking for a better solution has a lower priority.
joergs

joergs

2013-03-18 16:08

developer   ~0000280

make summary more descriptive.
mvwieringen

mvwieringen

2013-09-30 19:36

developer   ~0000679

Fix committed to bareos master branch with changesetid 1164.

Related Changesets

bareos: master 12a0fdd0

2013-09-27 18:00

pstorz


Committer: mvwieringen

Ported: N/A

Details Diff
Config engine redesign Phase 1

This whole wad is the first phase of a bigger full overhaul of the config
engine. The following is in here:

1)
Instead of using function pointers for storing the config parser function
to call use integer types which are translated at runtime to the correct
function to call. This should work around hardening being performed on
shared libraries on some Linux platforms. On those platforms the actual
comparing of the function pointers fail, using integers for the different
data types makes it also possible to use an elegant switch to jump to the
correct parsing function instead of using an endless set of ifs needed when
comparing memory addresses of functions.

An extra side effect of not using function pointers is that the store functions
don't need to be global so the parse_conf.c in the shared library only exports
10 instead of 32 symbols and also the daemon specific store function can be
local only functions. The only thing needed is a callback to a dispatch function
in the daemon when it uses non standard config items which are not of a generic
type (e.g. not bool, integer etc but things like protocol etc.) which leads to a
very small extra payload which is probably not even measurable.

2)
Bring config engine to 2013 and don't polute namespace.

Implement a TODO from June 2008 and get ride of a slack of global
variables used by the config engine. The code seems to be have been
refactored in 2008 to access most configfile parsing via the CONFIG
class and it already has most of the needed structures which also were
kept as global variables. From now on the config engine is accessed via
the CONFIG class and only res_all is left as global variable. As a side
effect the config CLASS is now available as my_config and is a global
variable.

Global variable introduced:

- CLASS CONFIG *my_config (Global configuration)

Global variables removed:

- res_all_size
- r_first
- r_last
- resources
- res_head

It should be possible also to get ride of res_all but that needs some
more testing. And is currently not very high on our urgency map.

3)
Fix long standing TODO to remove the MAXSTRING definition.
Use POOLMEM and POOL_MEM to replace the fixed sized buffers.

4)
First basic part of printing config information out from the internal
tables. We will enhance this in the second phase to be more generic
and to allow it to write out the config maybe in different formats.
(JSON/XML comes to mind).

Fixes 0000059: bareos failed to start when linked with hardening linker flags LDFLAGS
Fixes 0000164: Remove MAXSTRING variable
Fixes 0000202: Config engine redesign
Affected Issues
0000059, 0000164, 0000202
mod - autoconf/configure.in Diff File
mod - src/console/console.c Diff File
mod - src/console/console_conf.c Diff File
mod - src/console/console_conf.h Diff File
mod - src/dird/authenticate.c Diff File
mod - src/dird/bsr.c Diff File
mod - src/dird/dbcheck.c Diff File
mod - src/dird/dird.c Diff File
mod - src/dird/dird.h Diff File
mod - src/dird/dird_conf.c Diff File
mod - src/dird/dird_conf.h Diff File
mod - src/dird/expand.c Diff File
mod - src/dird/fd_cmds.c Diff File
mod - src/dird/inc_conf.c Diff File
add - src/dird/inc_conf.h Diff File
mod - src/dird/job.c Diff File
mod - src/dird/migrate.c Diff File
mod - src/dird/ndmp_dma.c Diff File
mod - src/dird/newvol.c Diff File
mod - src/dird/run_conf.c Diff File
mod - src/dird/scheduler.c Diff File
mod - src/dird/testfind.c Diff File
mod - src/dird/ua_cmds.c Diff File
mod - src/dird/ua_dotcmds.c Diff File
mod - src/dird/ua_label.c Diff File
mod - src/dird/ua_output.c Diff File
mod - src/dird/ua_prune.c Diff File
mod - src/dird/ua_restore.c Diff File
mod - src/dird/ua_run.c Diff File
mod - src/dird/ua_select.c Diff File
mod - src/dird/ua_server.c Diff File
mod - src/dird/ua_status.c Diff File
mod - src/dird/verify.c Diff File
mod - src/filed/authenticate.c Diff File
mod - src/filed/backup.c Diff File
mod - src/filed/filed.c Diff File
mod - src/filed/filed.h Diff File
mod - src/filed/filed_conf.c Diff File
mod - src/filed/filed_conf.h Diff File
mod - src/filed/restore.c Diff File
mod - src/filed/verify.c Diff File
mod - src/filed/verify_vol.c Diff File
mod - src/findlib/xattr.c Diff File
mod - src/include/baconfig.h Diff File
mod - src/lib/address_conf.c Diff File
mod - src/lib/address_conf.h Diff File
mod - src/lib/cram-md5.c Diff File
mod - src/lib/edit.c Diff File
add - src/lib/generic_res.h Diff File
mod - src/lib/ini.c Diff File
mod - src/lib/ini.h Diff File
mod - src/lib/lex.c Diff File
mod - src/lib/lex.h Diff File
mod - src/lib/message.c Diff File
mod - src/lib/parse_bsr.c Diff File
mod - src/lib/parse_conf.c Diff File
mod - src/lib/parse_conf.h Diff File
mod - src/lib/protos.h Diff File
mod - src/lib/res.c Diff File
mod - src/lib/runscript.c Diff File
mod - src/lib/util.c Diff File
mod - src/plugins/filed/test-plugin-fd.c Diff File
mod - src/qt-console/bat.h Diff File
mod - src/qt-console/bat_conf.cpp Diff File
mod - src/qt-console/bat_conf.h Diff File
mod - src/qt-console/bcomm/dircomm.cpp Diff File
mod - src/qt-console/main.cpp Diff File
mod - src/qt-console/mainwin.cpp Diff File
mod - src/qt-tray-monitor/authenticate.cpp Diff File
mod - src/qt-tray-monitor/monitoritemthread.cpp Diff File
mod - src/qt-tray-monitor/tray-monitor.cpp Diff File
mod - src/qt-tray-monitor/tray_conf.cpp Diff File
mod - src/qt-tray-monitor/tray_conf.h Diff File
mod - src/stored/acquire.c Diff File
mod - src/stored/authenticate.c Diff File
mod - src/stored/autochanger.c Diff File
mod - src/stored/bcopy.c Diff File
mod - src/stored/bextract.c Diff File
mod - src/stored/bls.c Diff File
mod - src/stored/bscan.c Diff File
mod - src/stored/btape.c Diff File
mod - src/stored/butil.c Diff File
mod - src/stored/dir_cmd.c Diff File
mod - src/stored/ndmp_tape.c Diff File
mod - src/stored/reserve.c Diff File
mod - src/stored/status.c Diff File
mod - src/stored/stored.c Diff File
mod - src/stored/stored.h Diff File
mod - src/stored/stored_conf.c Diff File
mod - src/stored/stored_conf.h Diff File

Issue History

Date Modified Username Field Change
2013-02-08 11:22 daniel New Issue
2013-02-08 11:54 mvwieringen Assigned To => mvwieringen
2013-02-08 11:54 mvwieringen Status new => assigned
2013-02-08 11:56 mvwieringen Note Added: 0000083
2013-02-08 11:56 mvwieringen Status assigned => feedback
2013-02-08 13:03 daniel Note Added: 0000084
2013-02-08 13:03 daniel Status feedback => assigned
2013-02-08 13:58 daniel Note Edited: 0000084
2013-02-08 14:06 daniel Note Edited: 0000084
2013-02-12 18:26 mvwieringen Note Added: 0000093
2013-02-15 18:42 joergs Note Added: 0000113
2013-02-15 18:46 joergs File Added: config.out
2013-02-15 18:47 joergs Note Added: 0000114
2013-02-15 18:50 joergs File Added: .build.log
2013-02-15 18:50 joergs Note Added: 0000115
2013-02-16 17:45 mvwieringen Note Added: 0000118
2013-02-16 17:45 mvwieringen Status assigned => acknowledged
2013-02-17 22:33 mvwieringen Note Added: 0000123
2013-02-17 22:39 mvwieringen Note Added: 0000124
2013-02-18 11:01 mvwieringen Assigned To mvwieringen => joergs
2013-02-18 11:01 mvwieringen Status acknowledged => assigned
2013-02-18 12:37 mvwieringen Note Added: 0000126
2013-02-19 18:42 joergs Note Added: 0000129
2013-02-19 18:43 joergs File Added: 0002-disable-hardening.patch
2013-02-19 18:43 joergs Assigned To joergs => mvwieringen
2013-02-19 18:47 joergs Note Added: 0000130
2013-02-19 18:47 joergs Assigned To mvwieringen => joergs
2013-02-19 19:03 joergs Assigned To joergs => mvwieringen
2013-02-19 19:04 joergs Note Added: 0000131
2013-02-19 19:41 mvwieringen Note Added: 0000132
2013-02-19 19:41 mvwieringen File Added: libbareoscfg-13.1.0.so
2013-02-19 19:42 mvwieringen Assigned To mvwieringen => joergs
2013-02-19 19:51 mvwieringen Note Added: 0000133
2013-02-19 23:32 pstorz Note Added: 0000134
2013-02-20 08:00 joergs File Added: 0002-disable-hardening-by-settings-LDFLAGS.patch
2013-02-20 08:07 joergs Note Added: 0000138
2013-02-27 13:58 joergs Target Version => 12.4.0
2013-02-27 13:58 joergs Fixed in Version => 12.4.0
2013-02-27 13:58 joergs Note Added: 0000196
2013-02-27 13:58 joergs Priority high => low
2013-03-01 10:51 joergs Relationship added child of 0000109
2013-03-01 10:51 joergs Relationship deleted child of 0000109
2013-03-18 16:08 joergs Note Added: 0000280
2013-03-18 16:08 joergs OS Version 12.0.4 => 12.04
2013-03-18 16:08 joergs Summary Bareos-fd doesnt start in cause of missing working directory => bareos failed to start when linked with hardening linker flags LDFLAGS
2013-06-21 16:54 joergs Assigned To joergs => mvwieringen
2013-07-05 16:51 maik Relationship added related to 0000202
2013-07-05 16:52 maik Relationship deleted related to 0000202
2013-07-05 16:52 maik Relationship added child of 0000202
2013-09-30 19:36 mvwieringen Changeset attached => bareos master 12a0fdd0
2013-09-30 19:36 mvwieringen Note Added: 0000679
2013-09-30 19:36 mvwieringen Status assigned => resolved
2013-09-30 19:36 mvwieringen Resolution open => fixed
2014-05-16 17:43 mvwieringen adm Assigned To mvwieringen =>
2014-05-16 17:43 mvwieringen adm Status resolved => closed
2014-05-16 17:43 mvwieringen adm Fixed in Version => 14.2.0