date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,551,884,463,000
I'm writing a script to execute after a new installation of Minimal Ubuntu(mini.iso) to install all the software I need and sync the dotfiles I backed up previously. What's the best way to avoid errors? Install the software and after do the sync of the dotfiles within my /home folder or the contrary? Thanks!
I have been doing the opposite, I install the OS then install packages using APT / snapd then copy dotfiles. Try it first on a VM to check what might break when installing a newer OS (or newer package versions) and re-using your existing dotfiles. Sometimes the conf file syntax may have changed, but then I would look for ways to avoid this hassle in the future. usually there is some folder.d/ directory where users may place override settings that will not be overwritten and easy to see what's changed from the default. I know you didn't explicitly ask about it, but in case you don't know git is a great way to manage dotfiles. I use yadm myself - it's just like normal git commands.
Should I install softwares first or sync the dotfiles on new Ubuntu install? [closed]
1,551,884,463,000
I'm debating whether I should switch from Windows to Linux and I've decided that if I do, I'll be using Arch Linux (most likely manjaro specifically). Mainly because I don't want to have to deal with: "5 years of free security and maintenance updates" (correct me if I'm wrong) The problem is that the "rice" that I want to use contains dotfiles that were created on Ubuntu and I don't know if they'll work on Arch. If they aren't compatible, would you mind explaining how one would go about making them compatible (if possible). Or, since I am new to Linux, if you think I should just go with Ubuntu then explain why I should choose it instead of Arch. Thanks!
From the wikipedia: In Unix-like operating systems, any file or folder that starts with a dot character (for example, /home/user/.config), commonly called a dot file or dotfile, is to be treated as hidden – that is, the ls command does not display them unless the -a flag (ls -a) is used. In most command-line shells, wildcards will not match files whose names start with . unless the wildcard itself starts with an explicit . . A convention arose of using dotfiles in the user's home directory to store per-user configuration or informational text. Early uses of this were the well-known dotfiles .profile, .login, and .cshrc, which are configuration files for the Bourne shell and C shell and shells compatible with them, and .plan and .project, both used by the finger and name commands. There's nothing special about a file that starts with a dot, you won't have problems to use them across Unix/GNU+Linux systems. And I say this because you can have issues handling the encoding and end of lines of the files if they are created from windows. But that's not really something you should worry about much. Or, since I am new to Linux, if you think I should just go with Ubuntu then explain why I should choose it instead of Arch. That's just matter of debate and opinions. I would ask you how much effort you want to put in installing the OS. Arch is a bit complicated to install, and you need a basic set of linux skills to be succesful. Or, if you want to learn in the process, go for it, the arch community is awesome. But beware that they will tell you RTFM first. On the other side, Ubuntu and derivatives are easy to install. You have plenty of distributions to choose from, and each one has it's perks an downsides. But IMHO GNU+Linux is GNU+Linux. Almost any distro will have anything you need out of the box, it's just a matter of taste. I have a bunch of machines around, now I'm in Debian, other has Linux Mint, on other I installed Arch, etc. And of course, you can always test a distro creating a live USB, or have a dual boot machine. Go for it!
Are Ubuntu dotfiles compatible with Arch dotfiles?
1,551,884,463,000
In my deployment script I have such as code to exclude certain files. shopt -s extglob mv !(deploy.sh|file1|file2) ~/$public It works almost well but ignores hidden files so they are not moved. How to improve the code to move hidden files too?
There is a dotglob option in bash exactly for this purpose: $ touch file1 file2 .file $ ls !(file1) file2 $ shopt -s dotglob $ ls !(file1) .file file2
Excluding certain files from moving but move hidden ones too
1,551,884,463,000
So my trusty Linux box died after 10 years of faithful service. The memorial will be Friday afternoon. Anyway, I am moving to a Mac (lesser of two evils - a Win 10 machine was the other option), and I don't think I want to run Linux on it directly - I booted with a live cd of Mint 18 and the video resolution was wonky and no extra drivers to install. So OS X it is. My issue is that I've got LOTS of settings, etc. for various apps (all cross platform - firefox, thunderbird, geany, filezilla, virtualbox, netbeans, android studio, etc) that I'd like to move over as well. I've pulled the drive my /home directory was on, so I have all of the files. Some things are trivial - my ssh private keys and config file for connecting to various hosts still go in ~/.ssh But most of the other apps I can't find where to put my data/settings/preferences/profile files. Where do these go on OS X? I opened terminal and looked in my home directory, there is no ~/.mozilla or ~/.filezilla etc directory.
In OS X, there is a hidden directory ~/Library, whose subdirectories will contain that kind of user settings. This is for historical reasons: it is similar to pre-OS X versions of MacOS used to do. Here is a MozillaZine KB article that has the exact paths for Firefox on Windows, Linux and Mac: http://kb.mozillazine.org/Profile_folder_-_Firefox
Migrate from Linux Mint to OS X [closed]
1,551,884,463,000
I keep my dotfiles in a private git repo on bitbucket and this works great for the majority of my files (.vimrc, .tmux.conf etc) then I just set up symlinks from my home directory to my cloned gitrepo of dotfiles and everything works great. My problem is that I also use the prezto framework to manage zsh plugins. Prezto does something similar in that it stores all the .zprezto* config files in its own directory and symlinks to them from home. One of those files is the .zshrc which it stores in its own directory. It looks like this: .zlogin -> /home/jordan/.zprezto/runcoms/zlogin .zlogout -> /home/jordan/.zprezto/runcoms/zlogout .zpreztorc -> /home/jordan/.zprezto/runcoms/zpreztorc .zprofile -> /home/jordan/.zprezto/runcoms/zprofile .zshenv -> /home/jordan/.zprezto/runcoms/zshenv .zshrc -> /home/jordan/.zprezto/runcoms/zshrc How am I able to track my .zshrc file in my own git dotfiles directory without breaking prezto.
You can use a hardlink in this instance, presuming you are not crossing file system boundaries. In case you are unaware, a hardlink is much like a symlink, but from a process perspective the file is a normal file. This includes git, which will properly work with them and archive them as normal files with content and not symlinks. Because git doesn't track such links, however, if the file is deleted and recreated by the repo for some reason, it will break the hardlink, so that is something to keep an eye on when using git. To be clear, I mean you create a hardlink from Pretzo's primary stored instance to a version in the directory where you keep the git backed dot files. Pretzo will see it as a regular file, so will git, and note hardlinked files can be symlinked, so their deployment that way is fine. Like a symlink, it means a change to one version changes the other, since technically they are the same data on storage (with multiple associated file nodes). Beware hardlinks are harder to notice than symlinks with many tools since they are usually not explicitly indicated (I don't know how this applies to various GUI filebrowsers; I think generally they will just be regular files). However, you can spot them based on the number of links shown with ls -l (second column), stat, etc. Normal files that aren't hardlinked have a link count of 1 (and directories are not normal files, so their link count varies). Unfortunately, unlike with symlinks, there is no simple way to find the other nodes, just the link count indicating they exist. So do not start doing this willy-nilly, do it systematically as in this context so you know why and where the other nodes are. Caveat This does mean there is the potential, if you are deploying this way on multiple systems (your post is ambiguous on this point), to run into issues if Prezto is prone to making changes to these files of its own accord. That will lead to situations where a file has updates pending via a pull but these conflict with local changes made by Pretzo, and merging at that point is probably bad, so you would have to decide what to do (note you can delete a hardlink and it does not delete all the other copies). However, if these are all configuration files that you know Pretzo only reads and does not screw with (which is sort of implicit in the idea of git tracking them across systems), then you are okay. Also, if you are just using this repo as a backup of one particular system it doesn't matter, the aforementioned scenario can't happen. The only other issue is that you cannot use hardlinks across filesystem boundaries. I.e., if your master git backed store is on a mounted filesystem separate from Pretzo's own store, you are out of luck with this method.
Git tracking dotfiles that are symlinked
1,551,884,463,000
The context of this question is the hg-ssh script. It is helpful but not critical to know something about Mercurial. This script sets up a forced command using public keys so the given public key setup on the server will only allow the owner of the corresponding private key to push to a permitted set of repositories on the server. This forced commands is usually prefixed to the public key in the file ~/.ssh/authorized_keys on the server. With regard to this permitted set, the documentation before the script in the link above says: You can use pattern matching of your normal shell, e.g.: command="cd repos && hg-ssh user/thomas/* projects/{mercurial,foo}" The idea is to permit only pushing to repositories on the server that match this pattern. I've been using hg-ssh with the forced command command="cd /srv/hg && /usr/local/bin/hg-ssh * */* */*/* */*/*/*",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa [...] to match all repositories (up to some number of path components) under /srv/hg, using shell globbing. I belatedly realized that it is not matching paths which contain components starting with .. My current non-working example is the MQ repository /srv/hg/faheem/bixfile/.hg/patches. So, my question is, can I select a pattern that corresponds to all paths? I would prefer to use shell globbing, which are less of a headache than regular expressions in general, but I'd take a regular expression if globbing is not an option.
For recursive matching, the right tool is often find. Since you want to match all files in the current directory and its subdirectories recursively, but only down to a certain depth, specify -maxdepth. This isn't in POSIX, but exists on all current *BSD and in GNU find (Linux, Cygwin) and in Busybox (embedded Linux) so it's a safe bet that you have it. -exec … {} + is a relatively recent addition to POSIX, but it's been in GNU and FreeBSD/NetBSD/OSX for a while now. cd /srv/hg && find . -type d -maxdepth 3 -exec /usr/local/bin/hg-ssh {} + (I added -type d because you seem to want to match directories only, even though your attempt with * */* etc. matches files of all types.)
restricting pushes to selected Mercurial repositories using `ssh` forced commands and `hg-ssh`
1,551,884,463,000
I would like to symlink my emacs init.el into a dotfiles repo - located at ~/Documents/Dotfiles. However, when I attempt to do so the command fails even though my prompt doesn't return an error - ls -la doesn't show a link there. For example, I might do the following: ln -s ~/.emacs.d/init.el ~/Documents/Dotfiles/.emacs.d/init.el Are emacs configs - due to their being, "under the covers", a directory - different in some way than other files you might want to symlink? Tl;dr Aliases are weird and although the commands work, this link doesn't show in ls -la which is not really emacs' fault.
As far as I can see, in my case this happens when the target link has directories which doesnt exist. Try this: File should exist: file /Users/Chris/.emacs.d/init.el Remove previous symbolic link if present: rm /Users/Chris/Documents/Dotfiles/.emacs.d/init.el Now create needed directories: mkdir -p /Users/Chris/Documents/Dotfiles/.emacs.d/ And create symolic link: ln -s /Users/Chris/.emacs.d/init.el /Users/Chris/Documents/Dotfiles/.emacs.d/init.el
Symlinking `init.el` in
1,551,884,463,000
I would like to backup config files (hidden, starting with a dot) with duplicity. Only files, no directories. The following command duplicity --include '/home/foo/.*' --exclude '/home/foo/**' /home/foo sftp://myserver/backup --dry-run backups everything starting with a dot, thus config directories are also included. On the other hand duplicity --exclude '/home/foo/**' --include '/home/foo/.*' /home/foo sftp://myserver/backup --dry-run produces Command-line include glob: /home/foo/.* only specifies that files be included. Because the default is to include all files, the expression is redundant. Exiting because this probably isn't what you meant. I have no other idea. How can I backup only files starting with a dot.
katonag, try to add --exclude '/home/foo/.*/' or --exclude '/home/foo/.*/**' in the beginning eg. --exclude '/home/foo/.*/' --include '/home/foo/.*' --exclude '**' . duplicity tests in/exclude by given order. so the above translates to - /home/foo/.*/ + /home/foo/.* - ** where the first matches .folder but not the .file, which is matched by the second directive and the third excludes everything else. if /home/foo/.*/ does not work, try /home/foo/.*/**. that is because the duplicity matching code might not differentiate between files and folders, i have no time to test that. good luck.. ede/duply.net PS: there is a chapter in the duplicity man page about in/exclusion http://duplicity.nongnu.org/duplicity.1.html#sect9
Backup only hidden (dot) files with duplicity
1,699,187,920,000
(If the score of this question is 72, please don't upvote!) I ran this: cat /usr/bin/* | perl -ne 'map {$a{$_}++} split//; END{print map { "$a{$_}\t$_\n" } keys %a}' | grep --text . | sort -n | plotpipe --log y {1} and got this: (Even with a log y-axis it still looks exponential! There is more than 100x between the top and the bottom) Looking at the numbers: : 31919597 ^H 32983719 ^B 33943030 ^O 39130281 \213 39893389 $ 52237360 \211 53229196 ^A 76884442 \377 100776756 H 746405320 ^@ It is hardly surprising that ^@ (NUL) is the most common byte in executables. \377 (255) and ^A (1) also make intuitively sense to me. But what causes 'H' (72) to be the second most common byte in executables - far more common than 255 and 1? Background For a Perl script, I needed to find the least common byte in Perl scripts. By accident, I didn't grep out only Perl scripts but ran the command on all binaries. I expected a few bytes to stand out, such as NUL, 1, and 255, but never 'H'. The input for the graph is the count of each byte, sorted. The y-axis represents the count, and the x-axis represents the line number (1-256, as a byte can only take on 256 different values). The y-axis is log scale, so the difference is bigger than exponential.
That would be the 64 bit operand size prefix of amd64 machine code instructions. You'll notice it only happens on amd64 executables. If you compare on the /bin/* of http://ftp.debian.org/debian/pool/main/c/coreutils/coreutils_9.1-1_arm64.deb, http://ftp.debian.org/debian/pool/main/c/coreutils/coreutils_9.1-1_amd64.deb and http://ftp.debian.org/debian/pool/main/c/coreutils/coreutils_9.1-1_i386.deb, you'll see: $ for f (coreutils_9.1-1_*.deb) bsdtar xOf $f da\* | bsdtar xO ./bin/\* | xxd -p -c1 | sort | uniq -c | sort -rn | head -n 5 | grep -H --label="${${f:r}##*_}" . amd64: 692417 00 amd64: 145689 ff amd64: 81911 48 amd64: 48006 89 amd64: 45331 0f arm64:1409826 00 arm64: 70391 ff arm64: 67915 03 arm64: 49380 20 arm64: 41655 40 i386: 515346 00 i386: 171643 ff i386: 78361 0e i386: 69317 24 i386: 50497 83 0x48 (72, 'H') is only in the top 3 on amd64. On ls on my amd64 Debian system: $ xxd -p -c1 =ls | sort | uniq -c | sort -rn | head -n 5 39187 00 7827 ff 5565 48 4181 20 3393 0f If we disassemble the code in that executable, we find a lot of 0x48 bytes in the instructions: $ objdump -d =ls | grep -cw 48 5353 Most of them in first position: $ objdump -d =ls | grep -wm10 48 4000: 48 83 ec 08 sub $0x8,%rsp 4004: 48 8b 05 ad ff 01 00 mov 0x1ffad(%rip),%rax # 23fb8 <__gmon_start__@Base> 400b: 48 85 c0 test %rax,%rax 4012: 48 83 c4 08 add $0x8,%rsp 44b6: 68 48 00 00 00 push $0x48 4751: 48 89 f3 mov %rsi,%rbx 4754: 48 83 ec 68 sub $0x68,%rsp 4758: 48 8b 3e mov (%rsi),%rdi 475b: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax 4764: 48 89 44 24 58 mov %rax,0x58(%rsp) $ objdump -d =ls | grep -Pc '^\s*[\da-f]+:\s+48' 5113 According to http://ref.x86asm.net/geek.html#x48, that 0x48 is the 64 Bit Operand Size REX.W opcode prefix which specify that the operation is to be made on 64 bit operands instead of whatever default it's meant to be. $ objdump -d =ls | pcregrep -o1 -o2 '^\s*[\da-f]+:\s+(48 .. ).*?\t(\S+)' | sort | uniq -c | sort -rn | head 1512 48 89 mov 1040 48 8b mov 630 48 8d lea 372 48 85 test 326 48 83 add 198 48 39 cmp 158 48 83 sub 79 48 01 add 72 48 83 cmp 69 48 c7 movq All instructions done on 64 bit operands.
Why is 'H' / 72 / 0x48 the second most common byte in executables?
1,699,187,920,000
I've seen discussion before about ELF magic, most recently the comments in this Security stack exchange question. I've seen it mentioned before, and I've seen it in my own boot logs.. But I'm not sure what it is. The man page on elf is a bit over my head, as I don't do C or lower level languages. As someone who uses Linux as an every day operating system, what is ELF?
Right from the man page you reference: elf - format of Executable and Linking Format (ELF) files ELF defines the binary format of executable files used by Linux. When you invoke an executable, the OS must know how to load the executable into memory properly, how to resolve dynamic library dependencies and then where to jump into the loaded executable to start executing it. The ELF format provides this information. ELF magic is used to identify ELF files and is merely the very first few bytes of a file: % od -c -N 16 /bin/ls 0000000 177 E L F 002 001 001 \0 \0 \0 \0 \0 \0 \0 \0 \0 0000020 or % readelf -h /bin/ls | grep Magic Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 These 16 bytes unambiguously identify a file as an ELF executable. Many file formats have "magic" bytes that accomplish the same task -- identifying a type of file.
What is ELF Magic?
1,699,187,920,000
I have found the term "LSB executable" or "LSB shared object" in the output of the file command in Linux. For example: $ file /bin/ls /bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=4637713da6cd9aa30d1528471c930f88a39045ff, stripped What does "LSB" mean in this context?
“LSB” here stands for “least-significant byte” (first), as opposed to “MSB”, “most-significant byte”. It means that the binary is little-endian. file determines this from the sixth byte of the ELF header.
What does "LSB" mean when referring to executable files in the output of /bin/file?
1,699,187,920,000
Given a 2.6.x or newer Linux kernel and existing userland that is capable of running both ELF32 and ELF64 binaries (i.e. well past How do I know that my CPU supports 64bit operating systems under Linux?) how can I determine if a given process (by PID) is running in 32- or 64-bit mode? The naive solution would be to run: file -L /proc/pid/exe | grep -o 'ELF ..-bit [LM]SB' but is that information exposed directly in /proc without relying on libmagic?
If you want to limit yourself to ELF detection, you can read the ELF header of /proc/$PID/exe yourself. It's quite trivial: if the 5th byte in the file is 1, it's a 32-bit binary. If it's 2, it's 64-bit. For added sanity checking: If the first 5 bytes are 0x7f, "ELF", 1: it's a 32 bit ELF binary. If the first 5 bytes are 0x7f, "ELF", 2: it's a 64 bit ELF binary. Otherwise: it's inconclusive. You could also use objdump, but that takes away your libmagic dependency and replaces it with a libelf one. Another way: you can also parse the /proc/$PID/auxv file. According to proc(5): This contains the contents of the ELF interpreter information passed to the process at exec time. The format is one unsigned long ID plus one unsigned long value for each entry. The last entry contains two zeros. The meanings of the unsigned long keys are in /usr/include/linux/auxvec.h. You want AT_PLATFORM, which is 0x00000f. Don't quote me on that, but it appears the value should be interpreted as a char * to get the string description of the platform. You may find this StackOverflow question useful. Yet another way: you can instruct the dynamic linker (man ld) to dump information about the executable. It prints out to standard output the decoded AUXV structure. Warning: this is a hack, but it works. LD_SHOW_AUXV=1 ldd /proc/$SOME_PID/exe | grep AT_PLATFORM | tail -1 This will show something like: AT_PLATFORM: x86_64 I tried it on a 32-bit binary and got i686 instead. How this works: LD_SHOW_AUXV=1 instructs the Dynamic Linker to dump the decoded AUXV structure before running the executable. Unless you really like to make your life interesting, you want to avoid actually running said executable. One way to load and dynamically link it without actually calling its main() function is to run ldd(1) on it. The downside: LD_SHOW_AUXV is enabled by the shell, so you'll get dumps of the AUXV structures for: the subshell, ldd, and your target binary. So we grep for AT_PLATFORM, but only keep the last line. Parsing auxv: if you parse the auxv structure yourself (not relying on the dynamic loader), then there's a bit of a conundrum: the auxv structure follows the rule of the process it describes, so sizeof(unsigned long) will be 4 for 32-bit processes and 8 for 64-bit processes. We can make this work for us. In order for this to work on 32-bit systems, all key codes must be 0xffffffff or less. On a 64-bit system, the most significant 32 bits will be zero. Intel machines are little endians, so these 32 bits follow the least significant ones in memory. As such, all you need to do is: 1. Read 16 bytes from the `auxv` file. 2. Is this the end of the file? 3. Then it's a 64-bit process. 4. Done. 5. Is buf[4], buf[5], buf[6] or buf[7] non-zero? 6. Then it's a 32-bit process. 7. Done. 8. Go to 1. Parsing the maps file: this was suggested by Gilles, but didn't quite work. Here's a modified version that does. It relies on reading the /proc/$PID/maps file. If the file lists 64-bit addresses, the process is 64 bits. Otherwise, it's 32 bits. The problem lies in that the kernel will simplify the output by stripping leading zeroes from hex addresses in groups of 4, so the length hack can't quite work. awk to the rescue: if ! [ -e /proc/$pid/maps ]; then   echo "No such process" else case $(awk </proc/$pid/maps -- 'END { print substr($1, 0, 9); }') in *-) echo "32 bit process";; *[0-9A-Fa-f]) echo "64 bit process";; *) echo "Insufficient permissions.";; esac fi This works by checking the starting address of the last memory map of the process. They're listed like 12345678-deadbeef. So, if the process is a 32-bit one, that address will be eight hex digits long, and the ninth will be a hyphen. If it's a 64-bit one, the highest address will be longer than that. The ninth character will be a hex digit. Be aware: all but the first and last methods need Linux kernel 2.6.0 or newer, since the auxv file wasn't there before.
Determine if a specific process is 32- or 64-Bit
1,699,187,920,000
Whenever I run file on an ELF binary I get this output: [jonescb@localhost ~]$ file a.out a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped I'm just wondering what changed in Linux 2.6.9 that this binary couldn't run on 2.6.8? Wasn't ELF support added in Linux 2.0?
glibc has a configure option called --enable-kernel that lets you specify the minimum supported kernel version. When object files are linked with that glibc build, the linker adds a SHT_NOTE section to the resulting executable named .note.ABI-tag that includes that minimum kernel version. The exact format is defined in the LSB, and file knows to look for that section and how to interpret it. The reason your particular glibc was built to require 2.6.9 depends on who built it. It's the same on my system (Gentoo); a comment in the glibc ebuild says that it specifies 2.6.9 because it's the minimum required for the NPTL, so that's likely a common choice. Another one that seems to come up is 2.4.1, because it was the minimum required for LinuxThreads, the package used before NPTL
Why does the file command say that ELF binaries are for Linux 2.6.9?
1,699,187,920,000
I'm trying to learn more about library versioning in Linux and how to put it all to work. Here's the context: -- I have two versions of a dynamic library which expose the same set of interfaces, say libsome1.so and libsome2.so. -- An application is linked against libsome1.so. -- This application uses libdl.so to dynamically load another module, say libmagic.so. -- Now libmagic.so is linked against libsome2.so. Obviously, without using linker scripts to hide symbols in libmagic.so, at run-time all calls to interfaces in libsome2.so are resolved to libsome1.so. This can be confirmed by checking the value returned by libVersion() against the value of the macro LIB_VERSION. -- So I try next to compile and link libmagic.so with a linker script which hides all symbols except 3 which are defined in libmagic.so and are exported by it. This works... Or at least libVersion() and LIB_VERSION values match (and it reports version 2 not 1). -- However, when some data structures are serialized to disk, I noticed some corruption. In the application's directory if I delete libsome1.so and create a soft link in its place to point to libsome2.so, everything works as expected and the same corruption does not happen. I can't help but think that this may be caused due to some conflict in the run-time linker's resolution of symbols. I've tried many things, like trying to link libsome2.so so that all symbols are alised to symbol@@VER_2 (which I am still confused about because the command nm -CD libsome2.so still lists symbols as symbol and not symbol@@VER_2)... Nothing seems to work!!! Help!!!!!!
This doesn't exactly answer your question, but... First of all, ELF is the specification use by Linux for executable files (programs), shared libraries, and also object files which are the intermediate files found when compiling software. Object files end in .o, shared libraries end with .so followed by zero or more digits separated by periods, and executable files don't have any extension normally. There are typically three forms to name a shared library, the first form simply ends in .so. For example, a library called readline is stored in a file called libreadline.so and is located under one of /lib, /usr/lib, or /usr/local/lib normally. That file is located when compiling software with an option like -lreadline. -l tells the compiler to link with the following library. Because libraries change from time to time, it may become obsolete so libraries embed something called a SONAME. The SONAME for readline might look like libreadline.so.2 for the second version major version of libreadline. There may also be many minor versions of readline that are compatible and do not require software to be recompiled. A minor version of readline might be named libreadline.so.2.14. Normally libreadline.so is just a symbolic link to the most recent major version of readline, libreadline.so.2 in this case. libreadline.so.2 is also a symbolic link to libreadline.so.2.14 which is actually the file being used. The SONAME of a library is embedded inside the library file itself. Somewhere inside the file libreadline.so.2.14 is the string libreadline.so.2. When a program is compiled and linked with readline, it will look for the file libreadline.so and read the SONAME embedded in it. Later, when the program is actually executed, it will load libreadline.so.2, not just libreadline.so, since that was the SONAME that was read when it was first linked. This allows a system to have multiple incompatible versions of readline installed, and each program will load the appropriate major version it was linked with. Also, when upgrading readline, say, to 2.17, I can just install libreadline.so.2.17 alongside the existing library, and once I move the symbolic link libreadline.so.2 from libreadline.so.2.13 to libreadline.so.2.17, all software using that same major version will now see the new minor update to it.
Linux, GNU GCC, ld, version scripts and the ELF binary format -- How does it work?
1,699,187,920,000
I have an executable binary; let's call it a.out. I can see the binary contains strings $ strings a.out ... /usr/share/foo .... I need to change the string /usr/share/foo to /usr/share/bar. Can I just replace the string with sed?: sed -i 's@/usr/share/foo@/usr/share/bar@' a.out This looks like a safe thing to do. Will this also work when the strings are not the same length?
I don't know if your version of sed will be binary-clean or if will choke on what it thinks are really long lines in its input, but barring those issues, editing the string in-place should work. To see whether it does, compare the old and new versions with cmp -l. It should tell you whether or not the only three differences between the two files are those 3 bytes. Editing strings in a compiled executable will indeed work if the strings are of the same length, but it will almost always also work if you are shortening the string, due to the way that strings work in C. In C strings, everything after the NUL terminator does not count, so if you write a new NUL terminator before the position of the old one, you will effectively shorten the string. In general, there is no way you can lengthen a string using this hack.
When can I edit strings in an executable binary?
1,699,187,920,000
What I already know: An ELF executable has a number of sections, obviously the .text and .data sections get loaded into memory as these are the main parts of the program. But for a program to work, it needs more info, especially when linked dynamically. What I'm interested in are sections like .plt, .got, .dynamic, .dynsym, .dynstr etcetera. The parts of the ELF that are responsible for the linking of functions to addresses. From what I've been able to figure out so far, is that things like .symtab and .strtab do not get loaded (or do not stay) in memory. But are .dynsym and and .dynstr used by the linker? Do they stay in memory? Can I access them from program code? And are there any parts of an executable that reside in kernel memory? My interest in this is mostly forensic, but any information on this topic will help. The resources I've read about these tables and dynamic linking are more high level, they only explain the workings, not anything practical about the contents in memory. Let me know if anything in unclear about my question.
The following is a really good reference: http://www.ibm.com/developerworks/linux/library/l-dynamic-libraries/. It contains a bibliography at the end of a variety of different references at different levels. If you want to know every gory detail you can go straight to the source: http://www.akkadia.org/drepper/dsohowto.pdf. (Ulrich Drepper wrote the Linux dynamic linker.) You can get a really good overview of all the sections in your executable by running a command like "objdump -h myexe" or "readelf -S myexe". The .interp section contains the name of the dynamic loader that will be used to dynamically link the symbols in this object. The .dynamic section is a distillation of the program header that is formatted to be easy for the dynamic loader to read. (So it has pointers to all the other sections.) The .got (Global Offset Table) and .plt (Procedure Linkage Table) are the two main structures that are manipulated by the dynamic linker. The .got is an indirection table for variables and the .plt is an indirection table for functions. Each executable or library (which are called "shared objects") has its own .got and .plt and these are tables of the symbols referenced by that shared object that are actually contained in some other shared object. The .dynsyn contains all the information about the symbols in your shared object (both the ones you define and the external ones you need to reference.) The .dynsyn doesn't contain the actual symbol names. Those are contained in .dynstr and .dynsyn has pointers into .dynstr. .gnu.hash is a hash table used for quick lookup of symbols by name. It also contains only pointers (pointers into .dynstr, and pointers used for making bucket chains.) When your shared object dereferences some symbol "foo" the dynamic linker has to go look up "foo" in all the dynamic objects you are linked against to figure out which one contains the "foo" you are looking for (and then what the relative address of "foo" is inside that shared object.) The dynamic linker does this by searching the .gnu.hash section of all the linked shared objects (or the .hash section for old shared objects that don't have a .gnu.hash section.) Once it finds the correct address in the linked shared object it puts it in the .got or .plt of your shared object.
Which parts of an ELF executable get loaded into memory, and where?
1,699,187,920,000
I want to find file types that are executable from the kernel's point of view. As far as I know all the executable files on Linux are ELF files. Thus I tried the following: find * | file | grep ELF However that doesn't work; does anybody have other ideas?
Later edit: only this one does what jan needs: thank you huygens; find . -exec file {} \; | grep -i elf
How to find executable filetypes?
1,699,187,920,000
Is it possible to check if given program was compiled with GNU gprof instrumentation, i.e. with '-pg' flag passed to both compiler and linker, without running it to check if it would generate a gmon.out file?
You could check for references to function mcount (or possibly _mcount or __mcount according to Implementation of Profiling). This function is necessary for profiling to work, and should be absent for non-profiled binaries. Something like: $ readelf -s someprog | egrep "\s(_+)?mcount\b" && echo "Profiling is on for someprog" The above works on a quick test here.
Detect if an ELF binary was built with gprof instrumentation?
1,699,187,920,000
I'm studying the ELF specification (http://www.skyfree.org/linux/references/ELF_Format.pdf), and one point that is not clear to me about the program loading process is how the stack is initialized, and what the initial page size is. Here's the test (on Ubuntu x86-64): $ cat test.s .text .global _start _start: mov $0x3c,%eax mov $0,%edi syscall $ as test.s -o test.o && ld test.o $ gdb a.out -q Reading symbols from a.out...(no debugging symbols found)...done. (gdb) b _start Breakpoint 1 at 0x400078 (gdb) run Starting program: ~/a.out Breakpoint 1, 0x0000000000400078 in _start () (gdb) print $sp $1 = (void *) 0x7fffffffdf00 (gdb) info proc map process 20062 Mapped address spaces: Start Addr End Addr Size Offset objfile 0x400000 0x401000 0x1000 0x0 ~/a.out 0x7ffff7ffa000 0x7ffff7ffd000 0x3000 0x0 [vvar] 0x7ffff7ffd000 0x7ffff7fff000 0x2000 0x0 [vdso] 0x7ffffffde000 0x7ffffffff000 0x21000 0x0 [stack] 0xffffffffff600000 0xffffffffff601000 0x1000 0x0 [vsyscall] The ELF specification has very little to say about how or why this stack page exists in the first place, but I can find references that say that the stack should be initialized with SP pointing to argc, with argv, envp and the auxiliary vector just above that, and I have confirmed this. But how much space is available below SP? On my system there are 0x1FF00 bytes mapped below SP, but presumably this is counting down from the top of the stack at 0x7ffffffff000, and there are 0x21000 bytes in the full mapping. What influences this number? I am aware that the page just below the stack is a "guard page" that automatically becomes writable and "grows down the stack" if I write to it (presumably so that naive stack handling "just works"), but if I allocate a huge stack frame then I could overshoot the guard page and segfault, so I want to determine how much space is already properly allocated to me right at process start. EDIT: Some more data makes me even more unsure what's going on. The test is the following: .text .global _start _start: subq $0x7fe000,%rsp movq $1,(%rsp) mov $0x3c,%eax mov $0,%edi syscall I played with different values of the constant 0x7fe000 here to see what happens, and for this value it is nondeterministic whether I get a segfault or not. According to GDB, the subq instruction on its own will expand the size of the mmap, which is mysterious to me (how does linux know what's in my register?), but this program will usually crash GDB on exit for some reason. It can't be ASLR causing the nondeterminism because I'm not using a GOT or any PLT section; the executable is always loaded at the same locations in virtual memory every time. So is this some randomness of the PID or physical memory bleeding through? All in all I'm very confused as to how much stack is actually legally available for random access, and how much is requested on changing RSP or on writing to areas "just out of range" of legal memory.
I don't believe this question is really to do with ELF. As far as I know, ELF defines a way to "flat pack" a program image into files and then re-assemble it ready for first execution. The definition of what the stack is and how it's implemented sits somewhere between CPU specific and OS specific if the OS behaviour hasn't been elevated to POSIX. Though no-doubt the ELF specification makes some demands about what it needs on the stack. Minimum stack Allocation From your question: I am aware that the page just below the stack is a "guard page" that automatically becomes writable and "grows down the stack" if I write to it (presumably so that naive stack handling "just works"), but if I allocate a huge stack frame then I could overshoot the guard page and segfault, so I want to determine how much space is already properly allocated to me right at process start. I'm struggling to find an authoritative reference for this. But I have found a large enough number of non-authoritative references to suggest this is incorrect. From what I've read, the guard page is used to catch access outside the maximum stack allocation, and not for "normal" stack growth. The actual memory allocation (mapping pages to memory addresses) is done on demand. Ie: when un-mapped addresses in memory are accessed which are between stack-base and stack-base - max-stack-size + 1, an exception might be triggered by the CPU, but the Kernel will handle the exception by mapping a page of memory, not cascading a segmentation fault. So accessing the stack inside the maximum allocation shouldn't cause a segmentation fault. As you've discovered Maximum stack Allocation Investigating documentation ought to follow lines of Linux documentation on thread creation and image loading (fork(2), clone(2), execve(2)). The documentation of execve mentions something interesting: Limits on size of arguments and environment ...snip... On kernel 2.6.23 and later, most architectures support a size limit derived from the soft RLIMIT_STACK resource limit (see getrlimit(2)) ...snip... This confirms that the limit requires the architecture to support it and also references where it's limited (getrlimit(2)). RLIMIT_STACK This is the maximum size of the process stack, in bytes. Upon reaching this limit, a SIGSEGV signal is generated. To handle this signal, a process must employ an alternate signal stack (sigaltstack(2)). Since Linux 2.6.23, this limit also determines the amount of space used for the process's command-line arguments and envi‐ronment variables; for details, see execve(2). Growing the stack by changing the RSP register I don't know x86 assembler. But I'll draw your attention to the "Stack Fault Exception" which can be triggered by x86 CPUs when the SS register is changed. Please do correct me if I'm wrong, but I believe on x86-64 SS:SP has just become "RSP". So if I understand correctly a Stack Fault Exception can be triggered by decremented RSP (subq $0x7fe000,%rsp). See page 222 here: https://xem.github.io/minix86/manual/intel-x86-and-64-manual-vol3/o_fe12b1e2a880e0ce.html
How does the ELF loader determine the initial stack size?
1,699,187,920,000
With two files, one compiled and linked with gcc and the other manually with nasm and ld I get ELF 32-bit LSB shared object ... ELF 32-bit LSB executable ... What's the difference between these two things? I can see with readelf -h that one is Type: DYN (Shared object file) Type: EXEC (Executable file) I can see these documented on Wikipedia as ET_DYN and ET_EXEC. What are the practical differences between these two?
It seems this has something to do with Position Independent Executable (PIE). When GCC compiles executable by defaults it makes them PIE which changes the output flag on the ELF Header to ET_DYN. You can disable the generation of PIE executables with gcc -no-pie If you're seeing this check the default options gcc is configured with gcc -v, you should see something like --enable-default-pie. Answer inspired by this submission on StackOverflow. I intend to play more with it and explain more here.
What is the difference between "LSB executable" (ET_EXEC) and "LSB shared object" (ET_DYN)?
1,699,187,920,000
I compiled a small C program (2 lines of codes) with gcc to try to understand ELF file format. Doing a readelf -h on the object file, I have in the header : OS/ABI: UNIX - System V I am using Fedora, so why isn't it Linux instead ? Edit: I compiled int main(){ int x = 0; x++; } with gcc -o main.o -c main.c. My gcc version is gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
There are few differences between ELF executables on different platforms. “UNIX - System V” is the common ground; System V is where the ELF format came from. The corresponding numerical value is 0. This value indicates that the executable doesn't use any OS-specific extension. Debian GNU/Linux, at least, configures GCC/binutils to generate executables with this field set to 0 by default.
Why does readelf show "System V" as my OS instead of Linux?
1,699,187,920,000
I'm trying to decrease a Linux image running SuSE, and thought about running strip on all of the system's executables. Even though I may not re-gain much disk space this way, would there be any harm in doing so?
It's not the case for Linux (just checked...), but on other systems (such as BSDs, e.g., OSX) doing this will remove any setuid/setgid permissions as a side-effect. Also (still looking at OSX), the ownership of the file may change (to the user doing the writing). For Linux, I recall that early on, stripping a shared library would prevent linking to it. That is not a problem now, though as the Program Library HOWTO notes, it will make debuggers not useful. It prevents linking to static libraries. Further reading: 24.14 Don't Use strip Carelessly (Unix Power Tools) How do I strip local symbols from linux kernel module without breaking it? What Linux and Solaris can learn from each other
What harm would there be in running strip on all files?
1,699,187,920,000
When I use strace to examine a program, I often have a hard time finding where the syscalls from the dynamic loader end and the syscalls from the program begin. The output from strace ./hello where hello a simple hello world C program is 36 lines. Here's a sample: execve("./hello", ["./hello"], 0x7fffb38f4a30 /* 73 vars */) = 0 brk(NULL) = 0x1304000 arch_prctl(0x3001 /* ARCH_??? */, 0x7ffe6715fe60) = -1 EINVAL (Invalid argument) access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=92340, ...}, AT_EMPTY_PATH) = 0 mmap(NULL, 92340, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f78d9fbd000 close(3) = 0 openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260|\2\0\0\0\0\0"..., 832) = 832 pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784 pread64(3, "\4\0\0\0 \0\0\0\5\0\0\0GNU\0\2\0\0\300\4\0\0\0\3\0\0\0\0\0\0\0"..., 48, 848) = 48 Is there a way to ignore the dynamic loader syscalls?
On x86_64 the main program starts just after arch_prctl(ARCH_SET_FS) and a couple of mprotect()s, so you can sed 1,/ARCH_SET_FS/d on the strace's output. A trick you can use on all platforms is to LD_PRELOAD a small library which overides __libc_start_main() and does a pointless system call like write(-1, "IT_STARTS_HERE", 14) before calling the original __libc_start_main(). cat >hack.c <<'EOT' #define _GNU_SOURCE #include <dlfcn.h> #include <unistd.h> #include <errno.h> #include <err.h> int __libc_start_main( int (*main)(int,char**,char**), int ac, char **av, int (*init)(int,char**,char**), void (*fini)(void), void (*rtld_fini)(void), void *stack_end) { typeof(__libc_start_main) *next = dlsym(RTLD_NEXT, "__libc_start_main"); write(-1, "IT_STARTS_HERE", 14); errno = 0; return next(main, ac, av, init, fini, rtld_fini, stack_end); } EOT cc -shared -ldl hack.c -o hack.so hack_strace(){ strace -E LD_PRELOAD=./hack.so "$@" 2>&1 >&3 3>&- | sed 1,/IT_STARTS_HERE/d >&2; } 3>&1 # usage hack_strace sh -c 'echo LOL' getuid() = 2000 getgid() = 2000 getpid() = 11443 rt_sigaction(SIGCHLD, {sa_handler=0x55eba5c19380, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7fae5c55f840}, NULL, 8) = 0 geteuid() = 2000
Can I skip syscalls made by the dynamic loader in strace?
1,699,187,920,000
I've been doing an exersice in attempt to understanding some of what's going on under the hood of a program. I wrote a small C program, and compiled it on i386 Linux (Ubuntu 12.04) using gcc. I then did a hexdump -C on the output to text file. I noticed that there were some gaps on the offset with an *: 00000670 00 3f 1a 3b 2a 32 24 22 1c 00 00 00 40 00 00 00 |.?.;*2$"....@...| 00000680 94 fd ff ff 05 01 00 00 00 41 0e 08 85 02 42 0d |.........A....B.| 00000690 05 03 01 01 c5 0c 04 04 38 00 00 00 60 00 00 00 |........8...`...| 000006a0 80 fe ff ff 61 00 00 00 00 41 0e 08 85 02 41 0e |....a....A....A.| 000006b0 0c 87 03 41 0e 10 86 04 41 0e 14 83 05 4e 0e 30 |...A....A....N.0| 000006c0 02 4a 0e 14 41 0e 10 c3 41 0e 0c c6 41 0e 08 c7 |.J..A...A...A...| 000006d0 41 0e 04 c5 10 00 00 00 9c 00 00 00 b4 fe ff ff |A...............| 000006e0 02 00 00 00 00 00 00 00 10 00 00 00 b0 00 00 00 |................| 000006f0 a2 fe ff ff 04 00 00 00 00 00 00 00 00 00 00 00 |................| 00000700 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000f10 00 00 00 00 ff ff ff ff 00 00 00 00 ff ff ff ff |................| 00000f20 00 00 00 00 00 00 00 00 01 00 00 00 10 00 00 00 |................| 00000f30 0c 00 00 00 d4 82 04 08 0d 00 00 00 cc 85 04 08 |................| 00000f40 f5 fe ff 6f ac 81 04 08 05 00 00 00 2c 82 04 08 |...o........,...| 00000f50 06 00 00 00 cc 81 04 08 0a 00 00 00 54 00 00 00 |............T...| 00000f60 0b 00 00 00 10 00 00 00 15 00 00 00 00 00 00 00 |................| 00000f70 03 00 00 00 f4 9f 04 08 02 00 00 00 20 00 00 00 |............ ...| 00000f80 14 00 00 00 11 00 00 00 17 00 00 00 b4 82 04 08 |................| 00000f90 11 00 00 00 ac 82 04 08 12 00 00 00 08 00 00 00 |................| 00000fa0 13 00 00 00 08 00 00 00 fe ff ff 6f 8c 82 04 08 |...........o....| 00000fb0 ff ff ff 6f 01 00 00 00 f0 ff ff 6f 80 82 04 08 |...o.......o....| 00000fc0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00000ff0 00 00 00 00 28 9f 04 08 00 00 00 00 00 00 00 00 |....(...........| 00001000 26 83 04 08 36 83 04 08 46 83 04 08 56 83 04 08 |&...6...F...V...| 00001010 00 00 00 00 00 00 00 00 47 43 43 3a 20 28 55 62 |........GCC: (Ub| 00001020 75 6e 74 75 2f 4c 69 6e 61 72 6f 20 34 2e 36 2e |untu/Linaro 4.6.| 00001030 33 2d 31 75 62 75 6e 74 75 35 29 20 34 2e 36 2e |3-1ubuntu5) 4.6.| 00001040 33 00 00 2e 73 79 6d 74 61 62 00 2e 73 74 72 74 |3...symtab..strt| 00001050 61 62 00 2e 73 68 73 74 72 74 61 62 00 2e 69 6e |ab..shstrtab..in| 00001060 74 65 72 70 00 2e 6e 6f 74 65 2e 41 42 49 2d 74 |terp..note.ABI-t| 00001070 61 67 00 2e 6e 6f 74 65 2e 67 6e 75 2e 62 75 69 |ag..note.gnu.bui| 00001080 6c 64 2d 69 64 00 2e 67 6e 75 2e 68 61 73 68 00 |ld-id..gnu.hash.| 00001090 2e 64 79 6e 73 79 6d 00 2e 64 79 6e 73 74 72 00 |.dynsym..dynstr.| My question is, how should I interpret the *? I assume it means there's a gap in the file, but then the question turns to why does a gap exist? Is this part of the standard format of an ELF file?
Like in the standard od command or hd, it means all the elided lines are the same as the preceding line. You can pass -v to make it display those lines anyway. From hexdump(1): The -v option causes hexdump to display all input data. Without the -v option, any number of groups of output lines, which would be identical to the immediately preceding group of output lines (except for the input offsets), are replaced with a line comprised of a single asterisk.
What does `*` mean using hexdump -C?
1,699,187,920,000
A minimal ELF executable only requires the ELF header and at least one program header in order to be functional. However, when I run strip on a short executable, it decides not to throw out the section header table or the section strings section, keeping them around although they have no purpose (as far as I know) for the program's execution. Is there a reason why these aren't removed by strip? Is there another utility which removes everything which isn't required for the executable to run? I've tried manually editing the code-golfing executable I was making to remove the section headers, and it appears to work fine, and be much smaller.
The documentation for GNU binutils strip alludes to the reason, but is not explicit, mentioning in the description of --only-keep-debug that Note - the section headers of the stripped sections are preserved, including their sizes, but the contents of the section are discarded. The section headers are preserved so that other tools can match up the debuginfo file with the real executable, even if that executable has been relocated to a different address space. That is, unless told to explicitly via the -R option, strip will retain section headers to help other programs (including gdb) do their job. The page Correct use of the strip command (part of Reverse Engineering using the Linux Operating System) notes Running the strip command on an executable is the most common program protection method. In its default operation, the strip command removes the symbol table and any debugging information from an executable. This is how it is typically used. However, there is still useful information that is not removed. and goes on to enumerate several useful things that might be left behind — for analysis of a "stripped" executable. In Learning Linux Binary Analysis, this is reiterated, commenting that section headers are normally only missing when someone has deliberately removed them, and that without section headers, gdb and objdump are nearly useless.
Why doesn't `strip` remove section headers from ELF executables?
1,699,187,920,000
When I'm on my Linux Box I use bash as a shell. Now I wondered how bash handles the execution of an ELF file, that is when I type ./program and program is an ELF file. I grepped the bash-4.3.tar.gz, there does not seem to be some sort of magic number parser to find out if the file is an ELF nor did I find an exec() syscall. How does the process work? How does bash pass the execution of the ELF to the OS?
Bash knows nothing about ELF. It simply sees that you asked it to run an external program, so it passes the name you gave it as-is to execve(2). Knowledge of things like executable file formats, shebang lines, and execute permissions lives behind that syscall, in the kernel. (It is the same for other shells, though they may choose to use another function in the exec(3) family instead.) In Bash 4.3, this happens on line 5195 of execute_cmd.c in the shell_execve() function. If you want to understand Linux at the source code level, I recommend downloading a copy of Research Unix V6 or V7, and going through that rather than all the complexity that is in the modern Linux systems. The Lions Book is a good guide to the code. V7 is where the Bourne shell made its debut. Its entire C source code is just a bit over half the size of just that one C file in Bash. The Thompson shell in V6 is nearly half the size of the original Bourne shell. Yet, both of these simpler shells do the same sort of thing as Bash, and for the same reason. (It appears to be an execv(2) call from texec() in the Thompson shell and an execve() call from execs() in the Bourne shell's service.c module.)
How does bash execute an ELF file?
1,699,187,920,000
On every loading of a lib, I get the error: no version information available This lib has been compiled on another PC (ubuntu 10.04) than the one running it (mandriva 2010.2). $ ldd /usr/local/gnu-eabi-4.5.2/i686-pc-linux-gnu/arm-eabi/lib/libbfd-2.21.so /usr/local/gnu-eabi-4.5.2/i686-pc-linux-gnu/arm-eabi/lib/libbfd-2.21.so: /lib/libz.so.1: no version information available (required by /usr/local/gnu-eabi-4.5.2/i686-pc-linux-gnu/arm-eabi/lib/libbfd-2.21.so) linux-gate.so.1 => (0xffffe000) libz.so.1 => /lib/libz.so.1 (0xb77a7000) libc.so.6 => /lib/i686/libc.so.6 (0xb7655000) /lib/ld-linux.so.2 (0xb787a000) Edit: the workaround didn't work.
No, it doesn't. It appears to mean that the version of libz you linked against when you compiled your program was built with different tools than the version on the madriva system you're using. The mandriva copy is missing symbol version info which was present in the copy of the libz library your program originally linked against. This has to do with differences int he respective build environments, not with versions of the libz library itself. I suspect you'll continue to get the message until you supply a copy of libz that was built with the same toolset as your binary, i.e., a toolset that inserts symbol versions into the library. Or build your binary with tools similar to those used when libz was compiled on your mandriva system, so no symbol version references are present in the binary. See: http://harmful.cat-v.org/software/dynamic-linking/versioned-symbols http://www.linux-kongress.org/1997/youngdale.html http://www.usenix.org/publications/library/proceedings/als00/2000papers/papers/full_papers/browndavid/browndavid_html/ I don't know of any tool that would let you modify the binary compiled on the other system to delete the symbol version references you don't want, and leave all others, if any.
Why does LD keep outputting "no version information available"
1,699,187,920,000
when loading a shared library in Linux system, what is the memory layout of the shared library? For instance, the original memory layout is the following: +-----------+ |heap(ori) | +-----------+ |stack(ori) | +-----------+ |.data(ori) | +-----------+ |.text(ori) | +-----------+ When I dlopen foo.so, will the memory layout be A or B? A +-----------+ |heap(ori) | +-----------+ |stack(ori) | +-----------+ |.data(ori) | +-----------+ |.text(ori) | +-----------+ |heap(foo) | +-----------+ |stack(foo) | +-----------+ |.data(foo) | +-----------+ |.text(foo) | +-----------+ Or B +-----------+ |heap(ori) | +-----------+ |heap(foo) | +-----------+ |stack(foo) | +-----------+ |stack(ori) | +-----------+ |.data(foo) | +-----------+ |.data(ori) | +-----------+ |.text(foo) | +-----------+ |.text(ori) | +-----------+ Or anything other than A and B... ?
The answer is "Other". You can get a glimpse of the memory layout with cat /proc/self/maps. On my 64-bit Arch laptop:: 00400000-0040c000 r-xp 00000000 08:02 1186758 /usr/bin/cat 0060b000-0060c000 r--p 0000b000 08:02 1186758 /usr/bin/cat 0060c000-0060d000 rw-p 0000c000 08:02 1186758 /usr/bin/cat 02598000-025b9000 rw-p 00000000 00:00 0 [heap] 7fe4b805c000-7fe4b81f5000 r-xp 00000000 08:02 1182914 /usr/lib/libc-2.21.so 7fe4b81f5000-7fe4b83f5000 ---p 00199000 08:02 1182914 /usr/lib/libc-2.21.so 7fe4b83f5000-7fe4b83f9000 r--p 00199000 08:02 1182914 /usr/lib/libc-2.21.so 7fe4b83f9000-7fe4b83fb000 rw-p 0019d000 08:02 1182914 /usr/lib/libc-2.21.so 7fe4b83fb000-7fe4b83ff000 rw-p 00000000 00:00 0 7fe4b83ff000-7fe4b8421000 r-xp 00000000 08:02 1183072 /usr/lib/ld-2.21.so 7fe4b85f9000-7fe4b85fc000 rw-p 00000000 00:00 0 7fe4b85fe000-7fe4b8620000 rw-p 00000000 00:00 0 7fe4b8620000-7fe4b8621000 r--p 00021000 08:02 1183072 /usr/lib/ld-2.21.so 7fe4b8621000-7fe4b8622000 rw-p 00022000 08:02 1183072 /usr/lib/ld-2.21.so 7fe4b8622000-7fe4b8623000 rw-p 00000000 00:00 0 7ffe430c4000-7ffe430e5000 rw-p 00000000 00:00 0 [stack] 7ffe431ed000-7ffe431ef000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] You can see that the executable gets loaded in low memory, apparently .text segment, read-only data, and .bss. Just about that is "heap". In much higher memory the C library and the "ELF file interpreter", "ld-so" get loaded. Then comes the stack. There's only one stack and one heap for any given address space, no matter how many shared libraries get loaded. cat only seems to get the C library loaded. Doing cat /proc/$$/maps will get you the memory mappings of the shell from which you invoked cat. Any shell is going to have a number of dynamically loaded libraries, but zsh and bash will load in a large number. You'll see that there's just one "[heap]", and one "[stack]". If you call dlopen(), the shared object file will get mapped in the address space at a higher address than /usr/lib/libc-2.21.so. There's something of an "implementation dependent" memory mapping segment, where all addresses returned by mmap() show up. See Anatomy of a Program in Memory for a nice graphic. The source for /usr/lib/ld-2.21.so is a bit tricky, but it shares a good deal of its internals with dlopen(). dlopen() isn't a second class citizen. "vdso" and "vsyscall" are somewhat mysterious, but this Stackoverflow question has a good explanation, as does Wikipedia.
Memory layout of dynamic loaded/linked library
1,699,187,920,000
I compiled a simple "Hello World" C program on Raspberry Pi 3, which was then transferred to an AMD64 laptop. Out of curiosity, I executed it, and it runs even though I did not expect it to: $ uname -a Linux 15ud490-gx76k 6.5.0-25-generic #25~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Feb 20 16:09:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux $ file hello64 hello64: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=486ee1cde035cd704b49c037a32fb77239b6a1c2, for GNU/Linux 3.7.0, not stripped $ ./hello64 Hello World! Like that, how can it execute? QEMU User Emulation is installed, but I don't know whether it is playing a part in this or not.
QEMU user emulation is exactly why your binary runs: on your system, one of the QEMU-related packages you’ve installed ensures that QEMU is registered as a handler for all the architectures it can emulate, and the kernel then passes binaries to it. As long as you have the required libraries, if any, the binary will run; since your binary is statically linked, it has no external dependencies. See Why can my statically compiled ARM binary of BusyBox run on my x86_64 PC? and How is Mono magical? for details.
Why can an aarch64 ELF executable be run on an x86_64 machine?
1,699,187,920,000
The NASM docs on "elf Extensions to the GLOBAL Directive" say, Optionally, you can control the ELF visibility of the symbol. Just add one of the visibility keywords: default, internal, hidden, or protected. The default is default of course. Where are these defined? and how does ld use them? I see access levels mentioned frequently in C++ which include protected, public, and private, but I don't know if this is what ELF is referencing? My use-case is C and Assembly so if you can make this relevant to those two languages and the linker, extra points.
It seems from the NASM source these seem to correspond with the docs from Oracle "Linker and Libraries Guide", these seem to correspond to STV_DEFAULT, STV_INTERNAL, STV_HIDDEN, and STV_PROTECTED. Oracle says this: STV_DEFAULT The visibility of symbols with the STV_DEFAULT attribute is as specified by the symbol's binding type. That is, global and weak symbols are visible outside of their defining component, the executable file or shared object. Local symbols are hidden. Global and weak symbols can also be preempted, that is, they may by interposed by definitions of the same name in another component. STV_PROTECTED A symbol defined in the current component is protected if it is visible in other components but cannot be preempted. Any reference to such a symbol from within the defining component must be resolved to the definition in that component, even if there is a definition in another component that would interpose by the default rules. A symbol with STB_LOCAL binding will not have STV_PROTECTED visibility. STV_HIDDEN A symbol defined in the current component is hidden if its name is not visible to other components. Such a symbol is necessarily protected. This attribute is used to control the external interface of a component. An object named by such a symbol may still be referenced from another component if its address is passed outside. A hidden symbol contained in a relocatable object is either removed or converted to STB_LOCAL binding by the link-editor when the relocatable object is included in an executable file or shared object. STV_INTERNAL This visibility attribute is currently reserved. As for the effect on C and Assembly, the Oracle docs go on to say None of the visibility attributes affects the resolution of symbols within an executable or shared object during link-editing. Such resolution is controlled by the binding type. Once the link-editor has chosen its resolution, these attributes impose two requirements. Both requirements are based on the fact that references in the code being linked may have been optimized to take advantage of the attributes. First, all of the non-default visibility attributes, when applied to a symbol reference, imply that a definition to satisfy that reference must be provided within the current executable or shared object. If this type of symbol reference has no definition within the component being linked, then the reference must have STB_WEAK binding and is resolved to zero. Second, if any reference to or definition of a name is a symbol with a non-default visibility attribute, the visibility attribute must be propagated to the resolving symbol in the linked object. If different visibility attributes are specified for distinct references to or definitions of a symbol, the most constraining visibility attribute must be propagated to the resolving symbol in the linked object. The attributes, ordered from least to most constraining, are STV_PROTECTED, STV_HIDDEN and STV_INTERNAL. See also IBM "What is symbol and symbol visibility" Oracle "Linker and Libraries Guide"
What are difference between the ELF symbol visibility levels?
1,699,187,920,000
In How do I extract the filesystem image from vmlinux.bin? and https://wiki.gentoo.org/wiki/Custom_Initramfs#Salvaging methods are presented for getting and unpacking an embedded initramfs/initrd included in the kernel image. Now I would like to insert the modified file system (cpio + possibly packed using e.g. lzma) into the kernel executable without having to recompile it. Would it be possible to modify the ELF image of the kernel in this way? If so then how? Would I need to keep something in respect if I were to simply replace the bytes in-place (maybe some hash?)? objdump-h Output: vmlinux.64.orig: file format elf64-big Sections: Idx Name Size VMA LMA File off Algn 0 .text 004162b8 ffffffff80100000 ffffffff80100000 00010000 2**7 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 __ex_table 000063a0 ffffffff805162c0 ffffffff805162c0 004262c0 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA 2 .notes 00000024 ffffffff8051c660 ffffffff8051c660 0042c660 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .rodata 0041f700 ffffffff8051d000 ffffffff8051d000 0042d000 2**8 CONTENTS, ALLOC, LOAD, READONLY, DATA 4 .pci_fixup 00000d40 ffffffff8093c700 ffffffff8093c700 0084c700 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA 5 __ksymtab 0000a430 ffffffff8093d440 ffffffff8093d440 0084d440 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA 6 __ksymtab_gpl 00004ff0 ffffffff80947870 ffffffff80947870 00857870 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA 7 __ksymtab_strings 00010f14 ffffffff8094c860 ffffffff8094c860 0085c860 2**0 CONTENTS, ALLOC, LOAD, READONLY, DATA 8 __init_rodata 00000500 ffffffff8095d778 ffffffff8095d778 0086d778 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA 9 __param 00001388 ffffffff8095dc78 ffffffff8095dc78 0086dc78 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA 10 .data 000508c0 ffffffff80960000 ffffffff80960000 00870000 2**14 CONTENTS, ALLOC, LOAD, DATA 11 .init.text 0002b084 ffffffff809b1000 ffffffff809b1000 008c1000 2**5 CONTENTS, ALLOC, LOAD, READONLY, CODE 12 .init.data 00bc6d78 ffffffff809dc088 ffffffff809dc088 008ec088 2**3 CONTENTS, ALLOC, LOAD, DATA 13 .exit.text 000019e0 ffffffff815a2e00 ffffffff815a2e00 014b2e00 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 14 .data.percpu 00003680 ffffffff815a5000 ffffffff815a5000 014b5000 2**7 CONTENTS, ALLOC, LOAD, DATA 15 .bss 00068fb0 ffffffff815b0000 ffffffff815b0000 014b8680 2**16 ALLOC 16 .mdebug.abi64 00000000 ffffffff81618fb0 ffffffff81618fb0 014b8680 2**0 CONTENTS, READONLY 17 .comment 0000cd74 0000000000000000 0000000000000000 014b8680 2**0 CONTENTS, READONLY 18 .gnu.attributes 00000010 0000000000000000 0000000000000000 014c53f4 2**0
As mentioned in the answer to a similar question about replacing ELF sections discussed at reverseengineering.se simply using dd might be enough under some circumstances apart from the new archive not being larger, e.g. whether there are relocations.
Repack the filesystem image from vmlinux.bin (embedded initramfs) without rebuilding?
1,699,187,920,000
I'm trying to understand how does symbol tables relate to the .data section in ELF. First some assumptions that I'm using as ground to start with. A symbol is a human readable (or "as written in the source file") representation of a function or a variable that is mapped to the actual binary value (that the CPU operates on) of that. Here is an example //simple.c int var_global_init = 5; int main(void) { return 0; } Let's build it and examine the binary: $ gcc simple.c -o simple $ objdump -t simple | grep var_global_init 0000000000201010 g O .data 0000000000000004 var_global_init It lists the symbol in the .data section of the ELF file. Page 20 of the ELF documentation defines the .data section as: These sections hold initialized data that contribute to the program's memory image. Ok, that kind of fits. So then I ask myself Does this mean that the symbol table is embedded in the .data section?. But that seems to be disproved by the exmple below: $ readelf -s simple Symbol table '.symtab' contains 66 entries: .... 50: 0000000000201010 4 OBJECT GLOBAL DEFAULT 23 var_global_init readelf shows that there is a dedicated .symtab section in the ELF that holds the symbol. Does the .data section need the actual symbol table. The first example points to concluding that there is one in the data section, but shouldn't it be able to execute just the binary values? By checking hexdump I was able to detect only a single entry, so either I got the concepts wrong or some of them is lying. :)
The .data section contains the data itself, i.e. the four bytes which hold the int value 5. The .symtab section contains the symbols, i.e. the names given to various parts of the binary; the var_global_init symbol name points to the four bytes of storage in the .data section. That’s why you only see one entry: there is only one symbol, in the symbol table. But you do need both sections if you want to go from a name to a value: the symbol table tells you where to find the value corresponding to the var_global_init symbol, and the data section contains the storage for the value.
Symbol table in the .data section of ELF
1,699,187,920,000
;TL-DR - Answer: because the dynamic linker ld-linux-x86-64.so.2 was missing. I have mounted a squashfs (shouldn't matter) filesystem -ro,loop at /mnt/foo. It contains among other things the following (/mnt/foo is the mount point): -rwxr-xr-x 1 root root 110088 jan 17 2013 /mnt/foo/bin/ls -rw-r--r-- 1 root root 5212 jul 23 09:35 /mnt/foo/etc/ld.so.cache -rw-r--r-- 1 root root 5 jul 23 09:35 /mnt/foo/etc/ld.so.conf -rw-r--r-- 1 root root 31168 maj 23 2013 /mnt/foo/lib/libacl.so.1 -rw-r--r-- 1 root root 18624 maj 20 2013 /mnt/foo/lib/libattr.so.1 -rwxr-xr-x 1 root root 1853400 okt 12 2013 /mnt/foo/lib/libc.so.6 -rw-r--r-- 1 root root 14664 okt 12 2013 /mnt/foo/lib/libdl.so.2 -rw-r--r-- 1 root root 256224 mar 11 2013 /mnt/foo/lib/libpcre.so.3 -rwxr-xr-x 1 root root 135757 okt 12 2013 /mnt/foo/lib/libpthread.so.0 -rw-r--r-- 1 root root 31760 okt 12 2013 /mnt/foo/lib/librt.so.1 -rw-r--r-- 1 root root 134224 maj 23 2013 /mnt/foo/lib/libselinux.so.1 /mnt/foo/etc/ld.so.conf contains a single row (including newline) with just /lib on it. Before creating the file system, I ran ldconfig -r ${TOPDIR} where ${TOPDIR} resolved to the place that is now mounted at /mnt/foo. A strings on /mnt/foo/etc/ld.so.cache shows it contains strings like /lib/libpcre.so.3 and so on, so I don't think it is a problem with the shared libraries. I figure it must be something silly I'm overlooking, but I cannot figure out myself why a simple chroot /mnt/foo /bin/ls doesn't work. readelf -d /mnt/foo/bin/ls | grep NEEDED shows these libraries as needed: 0x0000000000000001 (NEEDED) Shared library: [libselinux.so.1] 0x0000000000000001 (NEEDED) Shared library: [librt.so.1] 0x0000000000000001 (NEEDED) Shared library: [libacl.so.1] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] Finally, strace shows this: chroot("/mnt/foo") = 0 chdir("/") = 0 execve("/bin/ls", ["/bin/ls"], [/* 32 vars */]) = -1 ENOENT (No such file or directory) This is the full strace chroot: # strace -f chroot /mnt/foo /bin/ls execve("/usr/sbin/chroot", ["chroot", "/mnt/foo", "/bin/ls"], [/* 32 vars */]) = 0 brk(0) = 0x1985000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc115ac8000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=96457, ...}) = 0 mmap(NULL, 96457, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc115ab0000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\36\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1853400, ...}) = 0 mmap(NULL, 3961912, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc1154e0000 mprotect(0x7fc11569d000, 2097152, PROT_NONE) = 0 mmap(0x7fc11589d000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7fc11589d000 mmap(0x7fc1158a3000, 17464, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc1158a3000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc115aaf000 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc115aad000 arch_prctl(ARCH_SET_FS, 0x7fc115aad740) = 0 mprotect(0x7fc11589d000, 16384, PROT_READ) = 0 mprotect(0x606000, 4096, PROT_READ) = 0 mprotect(0x7fc115aca000, 4096, PROT_READ) = 0 munmap(0x7fc115ab0000, 96457) = 0 brk(0) = 0x1985000 brk(0x19a6000) = 0x19a6000 open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=8463952, ...}) = 0 mmap(NULL, 8463952, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fc114ccd000 close(3) = 0 chroot("/mnt/foo") = 0 chdir("/") = 0 execve("/bin/ls", ["/bin/ls"], [/* 32 vars */]) = -1 ENOENT (No such file or directory) open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/charset.alias", O_RDONLY|O_NOFOLLOW) = -1 ENOENT (No such file or directory) write(2, "chroot: ", 8chroot: ) = 8 write(2, "failed to run command \342\200\230/bin/ls"..., 35failed to run command ‘/bin/ls’) = 35 open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) write(2, ": No such file or directory", 27: No such file or directory) = 27 write(2, "\n", 1 ) = 1 close(1) = 0 close(2) = 0 exit_group(127) = ? +++ exited with 127 +++ So, is this ENOENT misleading? YES - ENOENT is a bit misleading. To me it has always meant "file not found". When the dynamic linker cannot be found, execve() gets ENOENT. When the booting kernel tries to load init (or linuxrc or whatever), the error I get is "Failed to execute /linuxrc (error -2). Attempting defaults...". The problem happened due to a bug in my script that created this initial ramdisk. (it omitted libraries not pointed out by "=>" by ldd). Two bonus questions to ponder for extra credits: what is linux-vdso.so.1 that ldd shows without a path? why does ldd show ld-linux.so without a "=>"?
The problem is /bin/ls don't just need the shared libraries, which you provided. It also needs the program that loads them; the linux loader. To solve your problem you can copy the loader from your system (usually /lib/ld-linux.so.2) to the location of your chroot (/mnt/foo/lib/ld-linux.so.2).
Why does chroot get ENOENT on an existing file?
1,699,187,920,000
If one program, for example grep, is curretly running, and a user executes another instance, do the two instances share the read-only .text sections between them to save memory? Would the sharing of the main executable text sharing be done similarly to shared libraries? Is this behavior exhibited in Linux? If so, do other Unices do so as well? If this is not done in Linux, would any benefit come from implementing executables that often run multiple instances in parallel as shared libraries, with the invoked executable simply calling a main function in the library?
Unix shares executables, and shared libraries are called shared (duh...) because their in-memory images are shared between all users. I.e., if I run two instances of bash(1), and in one of them run, say, vim(1), I'll have one copy each of the bash and the vim executables in memory, and (as both programs use the C library) one copy of libc. But even better: Linux pages from the disk copies of the above executables/libraries (files). So what stays in memory is just those pages that have been used recently. So, code for rarely used vim commands or bash error handling, not used functions in libc, and so on just use up disk space, not memory.
Are .text sections shared between loaded ELF executables?
1,699,187,920,000
I am trying to port Android apps to Linux (don't laugh :) and I have come across a problem. When trying to execute an Android executable (app_process) after adding the executable permission with ./app_process it says it doesn't exist although cat ./app_process works. Also in my file manager (Pantheon Files) the executable shows the shared library icon. Is there any way to get these execute on Linux.
Android and Linux are two different operating systems. You can't just take an executable from one and run it on the other. The first hurdle is the kernel. Android and Linux are based on the same kernel, but they have a few different features. In particular, Android provides binders, which only exist in the mainstream kernel (the one found in Linux distributions) since version 3.19. A pure native-code application might not use binders but most Java apps do. The second hurdle is the dynamic libraries. If you have a dynamically-linked executable, it invokes the dynamic linker. Android and Linux have different dynamic linkers, and if the dynamic linker is not present, you get the same error as if the executable itself was not present. If you copy the dynamic linker, and the configuration files that it needs, and the native libraries, then you should be able to run most native programs. You'll need to copy most of /system, and the copy needs to be located at /system. If you want to run Java apps, it's more complicated. You need the Java runtime environment (Dalvik/ART), and most apps require some Android daemons as well (some native-code apps also require those demons). The upshot is that while the two systems can cohabit on one kernel, this needs to be a recent enough kernel, or an Android kernel (an Android kernel can run most Linux applications), and both operating systems need be installed — you can't just run an application from one on the other. I'm not aware of any ready-made installer for Android on top of Linux. There are installers for the other way round, however, in particular LinuxonAndroid. If the objective is to run an Android app on a Linux system, then the easiest way by far is to run it inside the emulator which is part of the Android development tools.
Why can't I execute Android x86 executables on Linux
1,699,187,920,000
I was working through my C programs, I am new to Linux/UNIX development and was having a look around. I created a simple C program of Hello world and was inspecting the compilation process. I tried to read the file header of the final executable and got the Output as this $ objdump -f my_output file format elf32-i386 architecture: i386, flags 0x00000112: EXEC_P, HAS_SYMS, D_PAGED start address 0x08048320** I understand the elf32-i386 part but I am not pretty sure with the other portions of the header. is D_PAGED somehow related to demand paging? and what does EXEC_P, HAS_SYSMS mean? is start address , the logical address of main() of the program?
The flags in the output are BFD - Binary File Descriptors. They're part of the binutils package, you can read what the flags mean if you look in the bfd header file /usr/include/bfd.h for their meaning or here. The reference to the "flags" 0x00000112 is what's called a flag field. It's binary and each bit represents a particular feature, a one means the flag is on, or set, and a zero means it's not. Also note that the "0x..." means it's a hexidecimal value so if you convert it from HEX to BIN: 0x00000112 = 0001 0001 0010 in binary. So the flags that correspond to the 2nd, 5th, and 9th bits in the flag field are set. Those are the flags that are being shown by name in the 3rd line of output from the objdump command. Meaning of Flags The 3 flags that your executable has are pretty standard. Read the bits from right to left! 1st bit - 0000 0000 0010 /* BFD is directly executable. */ #define EXEC_P 0x02 2nd bit - 0000 0001 0000 /* BFD has symbols. */ #define HAS_SYMS 0x10 3rd bit - 0001 0000 0000 /* BFD is dynamically paged (this is like an a.out ZMAGIC file) (the linker sets this by default, but clears it for -r or -n or -N). */ #define D_PAGED 0x100 So the take aways: this is an executable file it includes a symbol table if you want to debug it using Gnu Debugger, gdb, so the functions will have meaningful names the executable is dynamically linked to the standard libraries such as glibc etc. Start Address The last line, start address ..., is as you guessed it, where the actual .CODE starts for the executable.
Portions of the file Header
1,699,187,920,000
https://linux-audit.com/elf-binaries-on-linux-understanding-and-analysis/ says The type field tells us what the purpose of the file is. There are a few common file types. CORE (value 4) DYN (Shared object file), for libraries (value 3) EXEC (Executable file), for binaries (value 2) REL (Relocatable file), before linked into an executable file (value 1) https://unix.stackexchange.com/a/476157/674 shows that a kernel module is REL. Why is it REL not DYN? What is the difference between DYN and REL? Thanks.
See the System V ABI, which contains the specifications of the ELF format. It says Relocation entries for different object files have slightly different interpretations for the r_offset member. In relocatable files, r_offset holds a section offset. That is, the relocation section itself describes how to modify another section in the file; relocation offsets designate a storage unit within the second section. In executable and shared object files, r_offset holds a virtual address. To make these files’ relocation entries more useful for the dynamic linker, the section offset (file interpretation) gives way to a virtual address (memory interpretation). Relocatable files are still fully relocatable, whereas shared objects are one step further along the linking process and have been largely relocated. Shared objects are only relocatable if their code is position-independent (e.g. it was built with GCC’s -fPIC option). Kernel modules need to be relocatable without being position-independent, so they are shipped as relocatable files.
What is the difference between Shared object file and Relocatable file?
1,699,187,920,000
I read somewhere that (at least since Linux v. 2.6) all user-space code is placed at load address 0x8048000 in the virtual memory address space. My own observations confirm this. I have done a cat /proc/......../maps for several processes and the very first section of a process' program text always starts at '0x8048000'. Furthermore the C library startup code and all the other runtime goodies all seem to be mapped after this default value. This constitutes almost 128 M of address space, not a lot considering that 0xC0000000 - 0x8048000 is still almost 3G of address space for user space stuff. So my question is why? We are dealing with virtual addresses, interference or overlap with other programs is excluded by definition of the way VM works. Are there some fixed/default mappings in the range 0x00000000 to 0x8048000 ? Apart from the fact that the default start address falls on a page boundary, what is the rationale for having chosen this number as opposed to any other value?
I admit that the following isn't a great answer, but I believe the 0x8048000 value is enshrined in the ELF Specification. See figures A.4, A.5 and A.6 in that doc. The System V ABI Intel 386 Architecture Supplement also standardizes on 0x8048000. See page 3-22, Figue 3-25. 0x804800 is prescribed as the low text segment address/high stack address. And that's weird in and of itself, as stacks are usually set in the high addresses of a process' memory space, and Linux is no exception. You can get the GNU linker ld to set up an ELF executable so that the kernel maps it in to a somewhat lower or somewhat higher address. The method to do this varies from version to version of GCC and ld, so read man pages carefully. This would tend to indicate that 0x8048000 doesn't derive from some hardware requirement, but rather from other considerations.
Rationale for making user space text segment start at 0x8048000
1,699,187,920,000
I was wondering what are some formats of object files in Linux? There are two types of object files that I know: executable, which has ELF format object files that are generated by gcc after compilation but before linkage. what is the format of such object files? Or are they also ELF format but with some different sub-formats than executables? Is the job of a linker to convert the format of this type of object files into the format of executables? Are there other types of object files?
Core dumps are also object files, of a sort, and usually in ELF format, too. Running this program will probably produce a file named "core": int main(int ac, char **av) { char *p = 0; *p = 'a'; return 0; } My file command says: core: ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4-style, from './dump'
Different formats of object files in Linux
1,699,187,920,000
How do I use file to differentiate between ELFves and scripts as quickly as possible? I don't need any further details, just ELF, script (/plaintext), or other/error.
If it's just between ELF and script, you may not need file at all. With bash: IFS= LC_ALL=C read -rn4 -d '' x < file case $x in ($'\x7fELF') echo ELF;; ("#!"*) echo script;; (*) echo other;; esac (-d '' (to use NUL character as delimiter) is to work around the fact that bash's read otherwise just ignores the NUL bytes in the input). See also: Searching for 32-bit ELF file Fastest way to determine if shebang is present
Differentiate between ELFves and scripts quickly
1,699,187,920,000
Look at the following output snippet generated by running objdump -T on libc.so.6: 000000000009f8a0 g DF .text 000000000000001d (GLIBC_2.2.5) aio_write64 0000000000119d00 g DF .text 0000000000000034 GLIBC_PRIVATE __pread64_nocancel 000000000009aae0 g DF .text 00000000000003c0 GLIBC_2.34 pthread_rwlock_timedwrlock 0000000000133db0 g DF .text 0000000000000354 GLIBC_2.2.5 __backtrace_symbols 00000000001184f0 w DF .text 00000000000006c2 GLIBC_2.23 fts64_read 000000000009aae0 g DF .text 00000000000003c0 (GLIBC_2.2.5) pthread_rwlock_timedwrlock Row 1 and 4 of the output have the same GLIBC version string but one of them is enclosed in parentheses and the other is not. I've observed this difference across the objdump output of a lot of other elf binaries. Is there any subtle difference between (GLIBC_2.2.5) and GLIBC_2.2.5 in objdump output?
See the description of the -T option: If the version is the default version to be used when resolving unversioned references to the symbol then it’s displayed as is, otherwise it’s put into parentheses. So the library provides version 2.2.5 of aio_write64, but only for backward-compatibility; there’s another version that’s used by default. Likewise, the default pthread_rwlock_timedwrlock verison is 2.34, but 2.2.5 is also provided.
Why are some instances of the same version string in objdump -T enclosed in paranthesis?
1,699,187,920,000
There are at least two standards of Executable and Linkable Format (ELF), one of them System V Application Binary Interface AMD64 Architecture Processor Supplement (With LP64 and ILP32 Programming Models) Version 1.0 Tool Interface Standard (TIS) Executable and Linking Format (ELF) Specification Version 1.2 The older one, the TIS ELF Standard 1.2 is 106 pages while the SysV ABI is 157 pages but covers ELF only on pages 63-86 (23 pages). How do these two standards relate to each other? And which one does Linux and GNU Linker use? What is the Tool Interface Standard?
The TIS/ELF one covers ELF in general, while the System V ABI is a supplement which documents the x86_64 Application Binary Interface. The second document does not contain any information about x86_64 since the architecture didn't exist at the time it was written.
Different standards of ELF (SysV vs TIS) and Linux?
1,699,187,920,000
I have a local static variable, something like this: void function(void) { static unsigned char myVariable = 0; ... I dump the symbol table using readelf as follows: readelf -s myprogram.elf and I get the symbol table, that contains myVariable as follows: ... 409: 00412668 1 NOTYPE LOCAL DEFAULT 16 myVariable.9751 ... My question is: what does the number mean after the name of the variable and the dot? And is there any detailed documentation about the output format of readelf? The man page does not contain information about the format of the symbol table, and I cannot find anything about this. (I'm using Xilinx's ARM GNU tools, but I guess, this is kind of the same for other platforms as well) Thanks!
That's not an artifact of readelf's output; myVariable.9751 is really that symbol's name. In order to distinguish static variables defined in different scopes/functions, the compiler has to decorate their names in some way: $ cat a.c static int var; int foo(void){ static int var; if(var++ > 3){ static int var; return var++; } else return var++; } int bar(void){ static int var; return var++; } int baz(void){ return var++; } $ cc -Wall -o - -S a.c | grep local.*var .local var .local var.1759 .local var.1760 .local var.1764 Notice that the dot (.) cannot be used in C as part of an identifier, so var.num is not going to collide with any other variable defined by the user. As to readelf documentation, there isn't much else beyond the man page and reading the source code; but you can also use objdump -tT instead of readelf -s; maybe you'll find its man page better.
What is the number in readelf symbol table name?
1,699,187,920,000
As far as I can tell, prelink can only works with dynamic libraries which an executable declares it needs at compile time (the libraries that can be found with ldd). It doesn't seem to include dynamic libraries which are manually loaded by the executable, like plugins or (in my particular case) Java native libraries. Is there any way to force prelink to cover these sort of libraries?
When you run prelink on an ELF binary it will only inspect the binary itself and its dependencies (as referenced in the ELF .dynamic and .dynstr sections). You should be able to use: prelink --libs-only libone.so libtwo.so [...] If one library is dependent on another you may need to specify these together on the same command line (i.e. if they are not in the normal linker path). However, an important part of pre-linking is being able to determine the best place to load every library for a process, it is possible you will not gain the full benefit of prelinking by doing libraries in isolation. This should not happen as long a both of these are true: you use the shared cache (/etc/prelink.cache) so that all libraries get a unique base you do not use the -m (conserve memory) when prelinking Confirm the operation was successful with prelink --print-cache
Using prelink on manually loaded libraries? (like Java native libraries)
1,613,647,156,000
I am studying ELF binary anatomy / structure and there are lots and lots of resources out there that describes what the ELF magic is. I understand the 45 4c 46 = ELF signature thing but what no source even touches on is what the 7f in 7f 45 4c 46 is. I found one source saying it's a "fixed byte", but what does that mean? Is it just some random fixed byte that, if things were a little different, might have been something else?
This is the first byte of the ELF file. Linux has a system of "magic numbers" that are use to recognise specific file types. Apart from being helpful for the file utility, they are used by the kernel to recognise executables. The 'magic' concept has a long history, but there has been little or no correlation on specific values between either manufacturers (such as Sun, Dell, HP etc), or package creators. Using any initial printable character (such as E) could be plain text. Using 0x80 (octal 0200) and above could mark a UTF-8 multi-byte character. Many of the ASCII control chars would be problematical (NUL, NL, TAB). There is not a great number of options. So the initial 0x7F (DEL) byte is a reasonable choice to prevent any such confusion. You could look at your local man pages for magic and file. It is actually no accident that DEL is 0x7F. When data was often held on paper tape, a mis-punch could be obliterated by punching out all the chads (plus the 8th bit, for even parity). Most readers skipped the NUL and DEL characters completely.
ELF Magic meaning of "7f" magic number?
1,613,647,156,000
— It's known you can run x86_32 programms with x86_64 kernel if it was compiled with support for that. But dynamic linker doesn't provide any way to define a separate set of preload libraries for 32-bit programs, so every time you run such a program, had you x86_64 preloads, you would face this error message: ERROR: ld.so: object '… … …' from /etc/ld.so.preload cannot be preloaded (wrong ELF class: ELFCLASS64): ignored. In case you put there the same list of x86_32-libraries to pre-load, you would get it working, but all pure x86_64 runs would start complaining as well. The best possible way is to modify the dynamic loader to support pre-loading from separate files, obviously, but it's at least lengthy process. Can you think of some clean workaround?… For now I'm thinking about some multi-class-pre-load.so, which could load needed files by itself, but, as I can see, there's no "multi-class" support in ELF.
In your ld.so.preload, you want to specify "$LIB" in your path rather than an explicit "lib" or "lib64". Thus, on a Redhat-style distro, "/usr/alternates/$LIB/libfoo.so" becomes "/usr/alternates/lib/libfoo.so" for a 32-bit process and "/usr/alternates/lib64/libfoo.so" for a 64-bit process. On an Debian-style distro, "/usr/alternates/$LIB/libfoo.so" becomes "/usr/alternates/lib/i386-linux-gnu/libfoo.so" and "/usr/alternates/x86_64-linux-gnu/libfoo.so" respectively. Your tree then needs to be populated with libraries for both architectures. See "rpath token expansion" in the ld.so(8) man page for more on this. Note however, that rather than preloading a library, if you're compiling the binaries whose loading you are attempting to modify, you may find it better to modify the paths by setting DT_RUNPATHon the link line (using the same "$LIB"-style paths, thus configuring the binary to prefer your library location over the system defaults. Alternately, as others have noted, you may edit an ELF file to set DT_RUNPATH on binaries you're not compiling. The following works for me on an x86_64 Centos 6.5 box: cd /tmp mkdir lib lib64 wget http://carrera.databits.net/~ksb/msrc/local/lib/snoopy/snoopy.h wget http://carrera.databits.net/~ksb/msrc/local/lib/snoopy/snoopy.c gcc -m64 -shared -fPIC -ldl snoopy.c -o /tmp/lib64/snoopy.so gcc -m32 -shared -fPIC -ldl snoopy.c -o /tmp/lib/snoopy.so cat > true.c <<EOF int main(void) { return 0; } EOF gcc -m64 true.c -o true64 gcc -m32 true.c -o true32 sudo bash -c "echo '/tmp/\$LIB/snoopy.so' > /etc/ld.so.preload" strace -fo /tmp/strace64.out /tmp/true64 strace -fo /tmp/strace32.out /tmp/true32 sudo rm /etc/ld.so.preload" In the strace output, strace64.out has: open("/tmp/lib64/snoopy.so", O_RDONLY) = 3 while strace32.out has: open("/tmp/lib/snoopy.so", O_RDONLY) = 3 This is with an ld.so.preload contents of: /tmp/$LIB/snoopy.so
ld.so.preload doesn't differ x86_32 and x86_64
1,613,647,156,000
I'm following the course of Baking Pi – Operating Systems Development. In it they created another section .init. So can we create as many sections as we want (not just .data, .bss, .text) and can we put code and data (initialized of no) in any of them?. If so, what's the purpose of sections then?
Initial research At first sight it would appear that the answer would be "no" the specification for ELF only allows the following sections. C32/kernel/bin/.process.o architecture: i386, flags 0x00000011: HAS_RELOC, HAS_SYMS start address 0x00000000 Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000333 00000000 00000000 00000040 2**4 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 1 .data 00000050 00000000 00000000 00000380 2**5 CONTENTS, ALLOC, LOAD, DATA 2 .bss 00000000 00000000 00000000 000003d0 2**2 ALLOC 3 .note 00000014 00000000 00000000 000003d0 2**0 CONTENTS, READONLY 4 .stab 000020e8 00000000 00000000 000003e4 2**2 CONTENTS, RELOC, READONLY, DEBUGGING 5 .stabstr 00008f17 00000000 00000000 000024cc 2**0 CONTENTS, READONLY, DEBUGGING 6 .rodata 000001e4 00000000 00000000 0000b400 2**5 CONTENTS, ALLOC, LOAD, READONLY, DATA 7 .comment 00000023 00000000 00000000 0000b5e4 2**0 CONTENTS, READONLY Source: http://wiki.osdev.org/ELF Other sources such as Wikipedia also show only the most basic section names, leading you to believe that these are all that are allowed. Additional searching showed that there are these 2 sections as well: .fini This section holds executable instructions that contribute to the process termination code. That is, when a program exits normally, the system arranges to execute the code in this section. .init This section holds executable instructions that contribute to the process initialization code. That is, when a program starts to run the system arranges to execute the code in this section before the main program entry point (called main in C programs). The .init and .fini sections have a special purpose. If a function is placed in the .init section, the system will execute it before the main function. Also the functions placed in the .fini section will be executed by the system after the main function returns. This feature is utilized by compilers to implement global constructors and destructors in C++. Source: http://l4u-00.jinr.ru/usoft/WWW/www_debian.org/Documentation/elf/node3.html But, yes you can have any sections But thanks to @AProgrammer for pointing me to the actual ELF Specification v1.2, there's a paragraph on page 1-16 which states the following: Section names with a dot (.) prefix are reserved for the system, although applications may use these sections if their existing meanings are satisfactory. Applications may use names without the prefix to avoid conflicts with system sections. The object file format lets one define sections not in the list above. An object file may have more than one section with the same name. So it would appear that it's entirely up to the program what sections it wants to utilize.
How many sections can I create in object file?
1,613,647,156,000
A while ago I was exploring a simple C program's ELF binary using GDB. I saw that the environment variables that are printed when I run printenv in the terminal are also present at the top of the stack of the C program's binary that I ran in that terminal. How does Bash actually execute a program and at the same time all the environment variables are also added onto the new process's stack? In short, what happens step by step when I run a program like this: ./myprogram
A Linux program is executed using the execve system call. execve has the following signature: int execve(const char *filename, char *const argv[], char *const envp[]); The last argument, envp, is used to pass the environment to the process, as an array of strings, each of the form key=value. By convention, the same environment is passed from one process to another, unless the calling process makes some changes to it. The kernel arranges for the new program to receive the environment on the stack, in the same manner the program arguments are passed. The library functions execl, execlp, execv, and execvp do not take the envp parameter (but the execle and execvpe functions do). These functions take the environment from the global variable environ in the calling process. This way a program using the execle function to start another program does not have to worry about passing the environment, but the library function does it automatically "behind the scenes". All the mentioned library functions eventually call the execve system call, passing the environment in theenvp parameter.
How does a new process executed in Bash always has the same environment variables?
1,613,647,156,000
https://linux-audit.com/elf-binaries-on-linux-understanding-and-analysis/ says The type field tells us what the purpose of the file is. There are a few common file types. CORE (value 4) DYN (Shared object file), for libraries (value 3) EXEC (Executable file), for binaries (value 2) REL (Relocatable file), before linked into an executable file (value 1) ... A common misconception is that ELF files are just for binaries or executables. We already have seen they can be used for partial pieces (object code). Another example is shared libraries or even core dumps (those core or a.out files). The ELF specification is also used on Linux for the kernel itself and Linux kernel modules. What ELF types do kernel itself and kernel modules have? Could you give some examples of the files of kernel itself and kernel modules, for me to try out with file? I am using Ubuntu 18.04. Thanks.
You can find out yourself: For modules, by looking under /lib/modules/$(uname -r)/kernel/.../*.ko: $ file xfs.ko xfs.ko: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=bcb5e287509cedbb0c5ece383e0b97fb99e4781e, not stripped $ readelf -h xfs.ko ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: REL (Relocatable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x0 Start of program headers: 0 (bytes into file) Start of section headers: 1829088 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 0 (bytes) Number of program headers: 0 Size of section headers: 64 (bytes) Number of section headers: 45 Section header string table index: 44 For the kernel, an easy way is by compiling one and looking at vmlinux: $ file vmlinux vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=eaf006a7ccfedbc40a6feddb04088bdb2ef0112f, with debug_info, not stripped $ readelf -h vmlinux ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x1000000 Start of program headers: 64 (bytes into file) Start of section headers: 171602920 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 5 Size of section headers: 64 (bytes) Number of section headers: 43 Section header string table index: 42
What ELF types do kernel itself and kernel modules have?
1,613,647,156,000
I was experimenting with how Linux allocates and protects memory. For some of my experiments, I have created a small program in C: #include <stdio.h> int gv=10; int main(){ char *v=(char*)0x601000;//0x601030 printf("gv=%p\n", &gv); scanf("%s", v); printf("You gave=%s\n", v); } After compilation (partial relro), readelf -t a.out returns: There are 30 section headers, starting at offset 0x1a18: Section Headers: [Nr] Name Type Address Offset Link Size EntSize Info Align Flags [ 0] NULL NULL 0000000000000000 0000000000000000 0 0000000000000000 0000000000000000 0 0 [0000000000000000]: [ 1] .interp PROGBITS PROGBITS 0000000000400238 0000000000000238 0 000000000000001c 0000000000000000 0 1 [0000000000000002]: ALLOC [ 2] .note.ABI-tag NOTE NOTE 0000000000400254 0000000000000254 0 0000000000000020 0000000000000000 0 4 [0000000000000002]: ALLOC [ 3] .note.gnu.build-id NOTE NOTE 0000000000400274 0000000000000274 0 0000000000000024 0000000000000000 0 4 [0000000000000002]: ALLOC [ 4] .gnu.hash GNU_HASH GNU_HASH 0000000000400298 0000000000000298 5 000000000000001c 0000000000000000 0 8 [0000000000000002]: ALLOC [ 5] .dynsym DYNSYM DYNSYM 00000000004002b8 00000000000002b8 6 0000000000000078 0000000000000018 1 8 [0000000000000002]: ALLOC [ 6] .dynstr STRTAB STRTAB 0000000000400330 0000000000000330 0 0000000000000058 0000000000000000 0 1 [0000000000000002]: ALLOC [ 7] .gnu.version VERSYM VERSYM 0000000000400388 0000000000000388 5 000000000000000a 0000000000000002 0 2 [0000000000000002]: ALLOC [ 8] .gnu.version_r VERNEED VERNEED 0000000000400398 0000000000000398 6 0000000000000030 0000000000000000 1 8 [0000000000000002]: ALLOC [ 9] .rela.dyn RELA RELA 00000000004003c8 00000000000003c8 5 0000000000000018 0000000000000018 0 8 [0000000000000002]: ALLOC [10] .rela.plt RELA RELA 00000000004003e0 00000000000003e0 5 0000000000000060 0000000000000018 12 8 [0000000000000042]: ALLOC, INFO LINK [11] .init PROGBITS PROGBITS 0000000000400440 0000000000000440 0 000000000000001a 0000000000000000 0 4 [0000000000000006]: ALLOC, EXEC [12] .plt PROGBITS PROGBITS 0000000000400460 0000000000000460 0 0000000000000050 0000000000000010 0 16 [0000000000000006]: ALLOC, EXEC [13] .text PROGBITS PROGBITS 00000000004004b0 00000000000004b0 0 00000000000001b2 0000000000000000 0 16 [0000000000000006]: ALLOC, EXEC [14] .fini PROGBITS PROGBITS 0000000000400664 0000000000000664 0 0000000000000009 0000000000000000 0 4 [0000000000000006]: ALLOC, EXEC [15] .rodata PROGBITS PROGBITS 0000000000400670 0000000000000670 0 0000000000000029 0000000000000000 0 8 [0000000000000002]: ALLOC [16] .eh_frame_hdr PROGBITS PROGBITS 000000000040069c 000000000000069c 0 0000000000000034 0000000000000000 0 4 [0000000000000002]: ALLOC [17] .eh_frame PROGBITS PROGBITS 00000000004006d0 00000000000006d0 0 00000000000000f4 0000000000000000 0 8 [0000000000000002]: ALLOC [18] .init_array INIT_ARRAY INIT_ARRAY 0000000000600e10 0000000000000e10 0 0000000000000008 0000000000000000 0 8 [0000000000000003]: WRITE, ALLOC [19] .fini_array FINI_ARRAY FINI_ARRAY 0000000000600e18 0000000000000e18 0 0000000000000008 0000000000000000 0 8 [0000000000000003]: WRITE, ALLOC [20] .jcr PROGBITS PROGBITS 0000000000600e20 0000000000000e20 0 0000000000000008 0000000000000000 0 8 [0000000000000003]: WRITE, ALLOC [21] .dynamic DYNAMIC DYNAMIC 0000000000600e28 0000000000000e28 6 00000000000001d0 0000000000000010 0 8 [0000000000000003]: WRITE, ALLOC [22] .got PROGBITS PROGBITS 0000000000600ff8 0000000000000ff8 0 0000000000000008 0000000000000008 0 8 [0000000000000003]: WRITE, ALLOC [23] .got.plt PROGBITS PROGBITS 0000000000601000 0000000000001000 0 0000000000000038 0000000000000008 0 8 [0000000000000003]: WRITE, ALLOC [24] .data PROGBITS PROGBITS 0000000000601038 0000000000001038 0 0000000000000008 0000000000000000 0 4 [0000000000000003]: WRITE, ALLOC [25] .bss NOBITS NOBITS 0000000000601040 0000000000001040 0 0000000000000008 0000000000000000 0 1 [0000000000000003]: WRITE, ALLOC [26] .comment PROGBITS PROGBITS 0000000000000000 0000000000001040 0 000000000000002d 0000000000000001 0 1 [0000000000000030]: MERGE, STRINGS [27] .shstrtab STRTAB STRTAB 0000000000000000 000000000000106d 0 0000000000000108 0000000000000000 0 1 [0000000000000000]: [28] .symtab SYMTAB SYMTAB 0000000000000000 0000000000001178 29 0000000000000648 0000000000000018 45 8 [0000000000000000]: [29] .strtab STRTAB STRTAB 0000000000000000 00000000000017c0 0 0000000000000255 0000000000000000 0 1 [0000000000000000]: and the readelf -l a.out returns: Elf file type is EXEC (Executable file) Entry point 0x4004b0 There are 9 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040 0x00000000000001f8 0x00000000000001f8 R E 8 INTERP 0x0000000000000238 0x0000000000400238 0x0000000000400238 0x000000000000001c 0x000000000000001c R 1 [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 0x00000000000007c4 0x00000000000007c4 R E 200000 LOAD 0x0000000000000e10 0x0000000000600e10 0x0000000000600e10 0x0000000000000230 0x0000000000000238 RW 200000 DYNAMIC 0x0000000000000e28 0x0000000000600e28 0x0000000000600e28 0x00000000000001d0 0x00000000000001d0 RW 8 NOTE 0x0000000000000254 0x0000000000400254 0x0000000000400254 0x0000000000000044 0x0000000000000044 R 4 GNU_EH_FRAME 0x000000000000069c 0x000000000040069c 0x000000000040069c 0x0000000000000034 0x0000000000000034 R 4 GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 RW 10 GNU_RELRO 0x0000000000000e10 0x0000000000600e10 0x0000000000600e10 0x00000000000001f0 0x00000000000001f0 R 1 Section to Segment mapping: Segment Sections... 00 01 .interp 02 .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame 03 .init_array .fini_array .jcr .dynamic .got .got.plt .data .bss 04 .dynamic 05 .note.ABI-tag .note.gnu.build-id 06 .eh_frame_hdr 07 08 .init_array .fini_array .jcr .dynamic .got In one instance of the program when run through gdb, /proc/self/maps returned: 00400000-00401000 r-xp 00000000 00:30f 2262070116 .../a.out 00600000-00601000 r--p 00000000 00:30f 2262070116 .../a.out 00601000-00602000 rw-p 00001000 00:30f 2262070116 .../a.out 7ffff7a18000-7ffff7bd0000 r-xp 00000000 fd:00 137613 /usr/lib64/libc-2.17.so 7ffff7bd0000-7ffff7dd0000 ---p 001b8000 fd:00 137613 /usr/lib64/libc-2.17.so 7ffff7dd0000-7ffff7dd4000 r--p 001b8000 fd:00 137613 /usr/lib64/libc-2.17.so 7ffff7dd4000-7ffff7dd6000 rw-p 001bc000 fd:00 137613 /usr/lib64/libc-2.17.so 7ffff7dd6000-7ffff7ddb000 rw-p 00000000 00:00 0 7ffff7ddb000-7ffff7dfc000 r-xp 00000000 fd:00 137605 /usr/lib64/ld-2.17.so 7ffff7fbd000-7ffff7fc0000 rw-p 00000000 00:00 0 7ffff7ff7000-7ffff7ffa000 rw-p 00000000 00:00 0 7ffff7ffa000-7ffff7ffc000 r-xp 00000000 00:00 0 [vdso] 7ffff7ffc000-7ffff7ffd000 r--p 00021000 fd:00 137605 /usr/lib64/ld-2.17.so 7ffff7ffd000-7ffff7ffe000 rw-p 00022000 fd:00 137605 /usr/lib64/ld-2.17.so 7ffff7ffe000-7ffff7fff000 rw-p 00000000 00:00 0 7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0 [stack] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] Having that in mind, what I would expect the memory region between 0x601000-0x602000 to be writable. But when I run the program with 24 characters or more, it crashed with v=0x601000. When I changed v to 0x601020 then the program crashed after I entered 0x1000-0x20 characters. How is that behavior explained? Isn't the memory protection enforced on page granularity? Here it looks like the memory region between 0x601018-0x601020 is somehow read-only. I guess the problem is inside the .got.plt section (loaded at 0x601000 with size 0x38) but what is it exactly? Edit: The output of ld --verbose | fgrep -A 3 -B 3 -i relro is: .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) } .dynamic : { *(.dynamic) } .got : { *(.got) *(.igot) } . = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .); .got.plt : { *(.got.plt) *(.igot.plt) } .data : This probably tells us that RELRO has something to do with that, but still, shouldn't the memory be protected in page-size granularity?
I have found the problem. By filling that region with junk I had overwritten the printf's got entry, which with its final invocation caused the segmentation. So if we modify the code to: #include <stdio.h> int gv=10; int main(){ char *v=(char*)0x601000; printf("gv=%p\n", &gv); scanf("%s", v); //printf("You gave=%s\n", v); } there should be no problem with filling v with 0x1000 characters (watch out \0) The RELRO reference of the first post is unrelated.
Enforced memory protection granularity (x86-64)
1,613,647,156,000
I was wondering how prelinking works. If I prelink my whole system and than delete glibc, will the system 'get up' after restart?
Well of course it won't, because you won't have a C library anymore. All prelink does is to try and calculate an optimal load address for each library so that no program will have overlapping libraries, then update the libraries so that they default to loading at that address. Then when a program is run the libraries it uses are unlikely to need to be relocated as they can probably be loaded at their default address.
How does prelink work
1,613,647,156,000
(This is a general question and not a complaint -- there is probably a good explanation for this.) For a compiled executable, why is path to the interpreter hard-coded into the binary as opposed to letting the operating system decide? I.e shouldn't the interpreter be derivable from the executable's format (e.g ELF) and architecture (x86-64). The interpreter path can be seen when running file /path/to/some-executable: some-executable: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=acd1829414c2843215bd10ed75a0fe486fce288e, not stripped To ensure the interpreter path string really exists in the binary, then strings -t x /path/to/some-executable | head shows it to be at byte 0x270: 270 /lib64/ld-linux-x86-64.so.2, inspecting the file with readelf -l /path/to/some-executable shows the same offset for the interpreter.
The attributes available in the ELF header (other than the pointer to the dynamic linker itself) aren’t sufficient to determine the appropriate dynamic linker. The dynamic linker is also tied to the C library against which the compiler was built, and thus for example a 64-bit x86 binary on Linux built using the GNU C library will probably fail if loaded by the musl dynamic linker: Binary compatibility is much more limited, but it will steadily increase with new versions of musl. At present, some glibc-linked shared libraries can be loaded with musl, but all but the simplest glibc-linked applications will fail if musl is dropped-in in place of /lib/ld-linux.so.2. The choice of dynamic linker also governs how shared libraries are discovered, so it isn’t even really possible to only specify a dynamic linker by name without a path, and rely on a linker-style algorithm to find the appropriate linker. It would be possible to use another approach, but it would have to be implemented in the kernel, so it’s much easier just to hard-code it in each binary.
Why is path to the interpreter hardcoded in ELF executables?
1,613,647,156,000
I am trying to dump the full paths of the shared libraries that are imported by an ELF file (/usr/bin/ls) Using readelf --dyn-syms /usr/bin/ls I get the name of the libraries, but not where they are located on the filesystem: 101: 0000000000000000 0 FUNC GLOBAL DEFAULT UND [...]@LIBSELINUX_1.0 (4) Using objdump -T /usr/bin/ls I get even more information (including function names): 0000000000000000 DF *UND* 0000000000000000 (LIBSELINUX_1.0) getfilecon This is useful information, but how can I extract the location of the library on disk? I could run the file and see what it opens via lsof, but is there any way to do this without running the file?
This is what ldd is for: $ ldd /bin/ls linux-vdso.so.1 (0x00007ffd67705000) libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f25aaab6000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f25aa8f1000) libpcre2-8.so.0 => /usr/lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f25aa859000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f25aa853000) /lib64/ld-linux-x86-64.so.2 (0x00007f25aab52000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f25aa831000) This is liable to include more than the libraries shown by readelf, since it will process transitive dependencies as well.
ELF: Dump paths to .so files imported by binary
1,613,647,156,000
Mac OS X uses Mach-o executable format and FreeBSD Unix uses ELF executable format. OS X uses FreeBSD Unix, correct me if I'm wrong. Then why does the Executable format in OS X differ from that of FreeBSD Unix?
Very short answer: OSX combines a Mach kernel with a BSD Unix toolset and libraries. The Mach heritage (via NeXTSTEP) lead to the use of Mach-O as the executable format. See this answer for more details: https://unix.stackexchange.com/a/713/24313
Executable Format in OS X vs Executable Format in FreeBSD
1,613,647,156,000
My intent is to place the text section at a specific location in memory (0x00100000). SECTIONS { . = 0x00100000; .text : { *(.text*) } } Although the linker does do this (note the 0x01000000 Addr field): $ readelf -S file.elf There are 12 section headers, starting at offset 0x104edc: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00100000 100000 000e66 00 AX 0 0 4 [ 2] .eh_frame PROGBITS 00100e68 100e68 000628 00 A 0 0 4 ... it also places ~1MB of zeros before the .text section in the ELF file (note the .text section's offset is 1MB). Shown another way: $ hexdump -C file.elf 00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF............| 00000010 02 00 03 00 01 00 00 00 0c 00 10 00 34 00 00 00 |............4...| 00000020 dc 4e 10 00 00 00 00 00 34 00 20 00 02 00 28 00 |.N......4. ...(.| 00000030 0c 00 0b 00 01 00 00 00 00 00 00 00 00 00 00 00 |................| 00000040 00 00 00 00 90 14 10 00 96 04 4f 00 07 00 00 00 |..........O.....| 00000050 00 00 20 00 51 e5 74 64 00 00 00 00 00 00 00 00 |.. .Q.td........| 00000060 00 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 |................| 00000070 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00100000 02 b0 ad 1b 03 00 00 00 fb 4f 52 e4 8b 25 90 04 |.........OR..%..| 00100010 4f 00 50 53 e8 88 00 00 00 fa f4 eb fc 55 89 e5 |O.PS.........U..| 00100020 83 ec 10 c7 45 f8 00 80 0b 00 c7 45 fc 00 00 00 |....E......E....| 00100030 00 eb 24 8b 45 fc 8d 14 00 8b 45 f8 01 d0 8b 4d |..$.E.....E....M| How can this be prevented? Am I improperly using the location counter ("dot" notation) syntax?
It turns out that telling the linker to emulate elf_i386 produced the output that I was looking for, though I do not understand why. Namely, invoke the linker with: $ ld -melf_i386 [...] Files produced with and without -melf_i386 appear to be mostly similar: with.elf: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped, with debug_info without.elf: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped, with debug_info Except their sizes are vastly different: $ ls -l *.elf -rwxr-xr-x 1 user user 10948 May 24 11:56 with.elf -rwxr-xr-x 1 user user 1055428 May 24 11:56 without.elf As far as I can tell, the output files are otherwise exactly the same: $ readelf -S with.elf There are 12 section headers, starting at offset 0x28e4: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00100000 001000 000205 00 AX 0 0 4 [ 2] .eh_frame PROGBITS 00100208 001208 0000b8 00 A 0 0 4 [ 3] .bss NOBITS 001002c0 0012c0 3ef000 00 WA 0 0 4 [ 4] .debug_info PROGBITS 00000000 0012c0 0007bf 00 0 0 1 [ 5] .debug_abbrev PROGBITS 00000000 001a7f 0002c9 00 0 0 1 [ 6] .debug_aranges PROGBITS 00000000 001d48 000060 00 0 0 1 [ 7] .debug_line PROGBITS 00000000 001da8 00023c 00 0 0 1 [ 8] .debug_str PROGBITS 00000000 001fe4 0004bd 01 MS 0 0 1 [ 9] .symtab SYMTAB 00000000 0024a4 000280 10 10 22 4 [10] .strtab STRTAB 00000000 002724 00014e 00 0 0 1 [11] .shstrtab STRTAB 00000000 002872 000070 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), p (processor specific) Just note the "offset" field is slightly different $ readelf -S without.elf There are 12 section headers, starting at offset 0x1018e4: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00100000 100000 000205 00 AX 0 0 4 [ 2] .eh_frame PROGBITS 00100208 100208 0000b8 00 A 0 0 4 [ 3] .bss NOBITS 001002c0 1002c0 3ef000 00 WA 0 0 4 [ 4] .debug_info PROGBITS 00000000 1002c0 0007bf 00 0 0 1 [ 5] .debug_abbrev PROGBITS 00000000 100a7f 0002c9 00 0 0 1 [ 6] .debug_aranges PROGBITS 00000000 100d48 000060 00 0 0 1 [ 7] .debug_line PROGBITS 00000000 100da8 00023c 00 0 0 1 [ 8] .debug_str PROGBITS 00000000 100fe4 0004bd 01 MS 0 0 1 [ 9] .symtab SYMTAB 00000000 1014a4 000280 10 10 22 4 [10] .strtab STRTAB 00000000 101724 00014e 00 0 0 1 [11] .shstrtab STRTAB 00000000 101872 000070 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), p (processor specific)
GNU linker producing useless spacing between sections in ELF file
1,613,647,156,000
I've noticed that strip removes ELF sections, such as .symtab and .strtab, but is there a way to force it to remove the .shstrtab section as well? I already tried the -R option but it didn't work. Strip just exits as if nothing happened. The current strip version is 2.30
If you are using the standard ELF tools, the functionality you asked for is in the mcs program that is a hard link to strip.. Use: mcs -d -n .shstrtab <object-file-name> See: http://schillix.sourceforge.net/man/man1/mcs.1.html
Remove .shstrtab with strip
1,613,647,156,000
On my MIPS box I'm trying to run a program. I use a cross compiler for mips. When I run my program, I'm getting Illegal instruction I pulled of one binary from it, called cputest. It basically prints “hello world” with some delay. Here is what readelf tells about it: readelf -a ./cputest.mips ELF Header: Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, big endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: MIPS R3000 Version: 0x1 Entry point address: 0x4004e0 Start of program headers: 52 (bytes into file) Start of section headers: 1956 (bytes into file) Flags: 0x1007, noreorder, pic, cpic, o32, mips1 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 8 Size of section headers: 40 (bytes) Number of section headers: 20 Section header string table index: 19 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 00400134 000134 000014 00 A 0 0 1 [ 2] .reginfo MIPS_REGINFO 00400148 000148 000018 18 A 0 0 4 [ 3] .dynamic DYNAMIC 00400160 000160 0000c8 08 A 6 0 4 [ 4] .hash HASH 00400228 000228 000058 04 A 5 0 4 [ 5] .dynsym DYNSYM 00400280 000280 000110 10 A 6 1 4 [ 6] .dynstr STRTAB 00400390 000390 0000d0 00 A 0 0 1 [ 7] .init PROGBITS 00400460 000460 000028 00 AX 0 0 4 [ 8] .text PROGBITS 00400490 000490 0000b0 00 AX 0 0 16 [ 9] .MIPS.stubs PROGBITS 00400540 000540 000040 00 AX 0 0 4 [10] .fini PROGBITS 00400580 000580 000028 00 AX 0 0 4 [11] .rodata PROGBITS 004005a8 0005a8 000010 01 AMS 0 0 4 [12] .data PROGBITS 004105c0 0005c0 000010 00 WA 0 0 16 [13] .rld_map PROGBITS 004105d0 0005d0 000004 00 WA 0 0 4 [14] .got PROGBITS 004105e0 0005e0 000020 04 WAp 0 0 16 [15] .pdr PROGBITS 00000000 000600 0000c0 00 0 0 4 [16] .comment PROGBITS 00000000 0006c0 000033 01 MS 0 0 1 [17] .gnu.attributes LOOS+ffffff5 00000000 0006f3 000010 00 0 0 1 [18] .mdebug.abi32 PROGBITS 00000010 000703 000000 00 0 0 1 [19] .shstrtab STRTAB 00000000 000703 0000a1 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) There are no section groups in this file. Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000034 0x00400034 0x00400034 0x00100 0x00100 R E 0x4 INTERP 0x000134 0x00400134 0x00400134 0x00014 0x00014 R 0x1 [Requesting program interpreter: /lib/ld-uClibc.so.0] REGINFO 0x000148 0x00400148 0x00400148 0x00018 0x00018 R 0x4 LOAD 0x000000 0x00400000 0x00400000 0x005b8 0x005b8 R E 0x10000 LOAD 0x0005c0 0x004105c0 0x004105c0 0x00040 0x00040 RW 0x10000 DYNAMIC 0x000160 0x00400160 0x00400160 0x000c8 0x000c8 RWE 0x4 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4 NULL 0x000000 0x00000000 0x00000000 0x00000 0x00000 0x4 Section to Segment mapping: Segment Sections... 00 01 .interp 02 .reginfo 03 .interp .reginfo .dynamic .hash .dynsym .dynstr .init .text .MIPS.stubs .fini .rodata 04 .data .rld_map .got 05 .dynamic 06 07 Dynamic section at offset 0x160 contains 20 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libc.so.0] 0x0000000f (RPATH) Library rpath: [/home/xia/Builds/H208N_V1.0_Dev/csp/release/tools/uclibc/lib] 0x0000000c (INIT) 0x400460 0x0000000d (FINI) 0x400580 0x00000004 (HASH) 0x400228 0x00000005 (STRTAB) 0x400390 0x00000006 (SYMTAB) 0x400280 0x0000000a (STRSZ) 208 (bytes) 0x0000000b (SYMENT) 16 (bytes) 0x70000016 (MIPS_RLD_MAP) 0x4105d0 0x00000015 (DEBUG) 0x0 0x00000003 (PLTGOT) 0x4105e0 0x70000001 (MIPS_RLD_VERSION) 1 0x70000005 (MIPS_FLAGS) NOTPOT 0x70000006 (MIPS_BASE_ADDRESS) 0x400000 0x7000000a (MIPS_LOCAL_GOTNO) 2 0x70000011 (MIPS_SYMTABNO) 17 0x70000012 (MIPS_UNREFEXTNO) 19 0x70000013 (MIPS_GOTSYM) 0xb 0x00000000 (NULL) 0x0 There are no relocations in this file. The decoding of unwind sections for machine type MIPS R3000 is not currently supported. Symbol table '.dynsym' contains 17 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 004105c0 0 NOTYPE GLOBAL DEFAULT 12 _fdata 2: 00000001 0 SECTION GLOBAL DEFAULT ABS _DYNAMIC_LINKING 3: 004185d0 0 NOTYPE GLOBAL DEFAULT ABS _gp 4: 00400490 0 NOTYPE GLOBAL DEFAULT 8 _ftext 5: 004105d0 0 OBJECT GLOBAL DEFAULT 13 __RLD_MAP 6: 00410600 0 NOTYPE GLOBAL DEFAULT ABS __bss_start 7: 00410600 0 NOTYPE GLOBAL DEFAULT ABS _edata 8: 004105e0 0 OBJECT GLOBAL DEFAULT ABS _GLOBAL_OFFSET_TABLE_ 9: 00410600 0 NOTYPE GLOBAL DEFAULT ABS _end 10: 00410600 0 NOTYPE GLOBAL DEFAULT ABS _fbss 11: 00400580 28 FUNC GLOBAL DEFAULT 10 _fini 12: 00400490 72 FUNC GLOBAL DEFAULT 8 main 13: 00400560 0 FUNC GLOBAL DEFAULT UND __uClibc_main 14: 00400460 28 FUNC GLOBAL DEFAULT 7 _init 15: 00400550 0 FUNC GLOBAL DEFAULT UND sleep 16: 00400540 0 FUNC GLOBAL DEFAULT UND printf Histogram for bucket list length (total of 3 buckets): Length Number % of total Coverage 0 0 ( 0.0%) 1 0 ( 0.0%) 0.0% 2 0 ( 0.0%) 0.0% 3 0 ( 0.0%) 0.0% 4 0 ( 0.0%) 0.0% 5 2 ( 66.7%) 62.5% 6 1 ( 33.3%) 100.0% No version information found in this file. Attribute Section: gnu File Attributes Tag_GNU_MIPS_ABI_FP: Soft float Primary GOT: Canonical gp value: 004185d0 Reserved entries: Address Access Initial Purpose 004105e0 -32752(gp) 00000000 Lazy resolver 004105e4 -32748(gp) 80000000 Module pointer (GNU extension) Global entries: Address Access Initial Sym.Val. Type Ndx Name 004105e8 -32744(gp) 00400580 00400580 FUNC 10 _fini 004105ec -32740(gp) 00400490 00400490 FUNC 8 main 004105f0 -32736(gp) 00400560 00400560 FUNC UND __uClibc_main 004105f4 -32732(gp) 00400460 00400460 FUNC 7 _init 004105f8 -32728(gp) 00400550 00400550 FUNC UND sleep 004105fc -32724(gp) 00400540 00400540 FUNC UND printf When I cross compile my program (which just prints “hello world”) without the -static flag and try to run it, here is what happens: # ls hello.mips # ./hello.mips /bin/sh: ./hello.mips: Permission denied # chmod +x hello.mips # ./hello.mips /bin/sh: ./hello.mips: not found # ls -la drwxrwxrwx 2 zhangxia root 0 Aug 8 00:01 . drwxr-xr-x 3 zhangxia root 0 Aug 7 22:46 .. -rwsrwsrwx 1 888 root 5743 Aug 8 00:01 hello.mips Why can't I find it when it's there? So I compile it with the -static flag and here is the readelf output (because of size limits here I will put just a part) readelf -a hello.static ELF Header: Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, big endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: MIPS R3000 Version: 0x1 Entry point address: 0x400280 Start of program headers: 52 (bytes into file) Start of section headers: 647608 (bytes into file) Flags: 0x1007, noreorder, pic, cpic, o32, mips1 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 6 Size of section headers: 40 (bytes) Number of section headers: 33 Section header string table index: 30 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .note.ABI-tag NOTE 004000f4 0000f4 000020 00 A 0 0 4 [ 2] .reginfo MIPS_REGINFO 00400114 000114 000018 18 A 0 0 4 [ 3] .note.gnu.build-i NOTE 0040012c 00012c 000024 00 A 0 0 4 [ 4] .rel.dyn REL 00400150 000150 000098 08 A 0 0 4 [ 5] .init PROGBITS 004001e8 0001e8 000098 00 AX 0 0 4 [ 6] .text PROGBITS 00400280 000280 07b5a0 00 AX 0 0 16 [ 7] __libc_freeres_fn PROGBITS 0047b820 07b820 0013a8 00 AX 0 0 4 [ 8] .fini PROGBITS 0047cbc8 07cbc8 000054 00 AX 0 0 4 [ 9] .rodata PROGBITS 0047cc20 07cc20 015a00 00 A 0 0 16 [10] .eh_frame PROGBITS 004a2620 092620 0019a4 00 WA 0 0 4 [11] .gcc_except_table PROGBITS 004a3fc4 093fc4 00014e 00 WA 0 0 1 [12] .tdata PROGBITS 004a4114 094114 000010 00 WAT 0 0 4 [13] .tbss NOBITS 004a4124 094124 000018 00 WAT 0 0 4 [14] .ctors PROGBITS 004a4124 094124 000008 00 WA 0 0 4 [15] .dtors PROGBITS 004a412c 09412c 00000c 00 WA 0 0 4 [16] .jcr PROGBITS 004a4138 094138 000004 00 WA 0 0 4 [17] .data.rel.ro PROGBITS 004a413c 09413c 00259c 00 WA 0 0 4 [18] .data PROGBITS 004a66e0 0966e0 0007c0 00 WA 0 0 16 [19] __libc_subfreeres PROGBITS 004a6ea0 096ea0 000030 00 WA 0 0 4 [20] __libc_atexit PROGBITS 004a6ed0 096ed0 000004 00 WA 0 0 4 [21] .got PROGBITS 004a6ee0 096ee0 000a48 04 WAp 0 0 16 [22] .sdata PROGBITS 004a7928 097928 000004 00 WAp 0 0 4 [23] .sbss NOBITS 004a7930 09792c 0000fc 00 WAp 0 0 8 [24] .bss NOBITS 004a7a30 09792c 001c10 00 WA 0 0 16 [25] __libc_freeres_pt NOBITS 004a9640 09792c 000018 00 WA 0 0 4 [26] .pdr PROGBITS 00000000 09792c 006700 00 0 0 4 [27] .comment PROGBITS 00000000 09e02c 000039 01 MS 0 0 1 [28] .gnu.attributes LOOS+ffffff5 00000000 09e065 000010 00 0 0 1 [29] .mdebug.abi32 PROGBITS 00001320 09e075 000000 00 0 0 1 [30] .shstrtab STRTAB 00000000 09e075 000140 00 0 0 1 [31] .symtab SYMTAB 00000000 09e6e0 006d70 10 32 655 4 [32] .strtab STRTAB 00000000 0a5450 0065f4 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) There are no section groups in this file. Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align REGINFO 0x000114 0x00400114 0x00400114 0x00018 0x00018 R 0x4 LOAD 0x000000 0x00400000 0x00400000 0x92620 0x92620 R E 0x10000 LOAD 0x092620 0x004a2620 0x004a2620 0x0530c 0x07038 RW 0x10000 NOTE 0x0000f4 0x004000f4 0x004000f4 0x00020 0x00020 R 0x4 NOTE 0x00012c 0x0040012c 0x0040012c 0x00024 0x00024 R 0x4 TLS 0x094114 0x004a4114 0x004a4114 0x00010 0x00028 R 0x4 Section to Segment mapping: Segment Sections... 00 .reginfo 01 .note.ABI-tag .reginfo .note.gnu.build-id .rel.dyn .init .text __libc_freeres_fn .fini .rodata 02 .eh_frame .gcc_except_table .tdata .ctors .dtors .jcr .data.rel.ro .data __libc_subfreeres __libc_atexit .got .sdata .sbss .bss __libc_freeres_ptrs 03 .note.ABI-tag 04 .note.gnu.build-id 05 .tdata .tbss There is no dynamic section in this file. Relocation section '.rel.dyn' at offset 0x150 contains 19 entries: Offset Info Type Sym.Value Sym. Name 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE 00000000 00000000 R_MIPS_NONE The decoding of unwind sections for machine type MIPS R3000 is not currently supported. Symbol table '.symtab' contains 1751 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 004000f4 0 SECTION LOCAL DEFAULT 1 2: 00400114 0 SECTION LOCAL DEFAULT 2 1747: 004a5d58 36 OBJECT GLOBAL DEFAULT 17 _nl_C_LC_IDENTIFICATION 1748: 004a9580 76 OBJECT GLOBAL DEFAULT 24 _dl_ns 1749: 00450f20 3016 FUNC GLOBAL DEFAULT 6 _nl_load_locale_from_arch 1750: 004380e0 248 FUNC WEAK DEFAULT 6 wctrans No version information found in this file. Displaying notes found at file offset 0x000000f4 with length 0x00000020: Owner Data size Description GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag) OS: Linux, ABI: 2.6.18 Displaying notes found at file offset 0x0000012c with length 0x00000024: Owner Data size Description GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) Build ID: a56a4b258e108ec9affb61c4a8ba46527052bca9 Attribute Section: gnu File Attributes Tag_GNU_MIPS_ABI_FP: Hard float (double precision) Both binaries (static and dynamic) runs just fine in quemu and on my second MIPS box. Any thoughts? Could “Illegal instruction” be due to different ld-uClibc, libc names/versions? @Stephen-Kitt Here it is # ldd ./hello.mips /bin/sh: ldd: not found cat proc/version Linux version 2.6.30.9 (xia@njzd) (gcc version 4.4.6 (Realtek RSDK-1.5.6p2) ) #2 Wed Apr 29 18:57:54 CST 2015 # cat proc/cpuinfo system type: RTL8672 processor: 0 cpu model : 56322 BogoMIPS: 619.31 tlb_entries : 64 mips16 implemented : yes Im running Ubuntu14.04 basicly mips-gcc -o hello.mips hello.c mips-gcc -static -o hello.static hello.c mips gcc is from Debian rep $ mips-linux-gnu-gcc -v Using built-in specs. Target: mips-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/mips-linux-gnu/include/c++/4.4.5 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --disable-libssp --enable-targets=all --enable-checking=release --program-prefix=mips-linux-gnu- --includedir=/usr/mips-linux-gnu/include --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=mips-linux-gnu --with-headers=/usr/mips-linux-gnu/include --with-libs=/usr/mips-linux-gnu/lib Thread model: posix gcc version 4.4.5 (Debian 4.4.5-8) I obtained it from here http://www.emdebian.org/debian/
# cat proc/cpuinfo system type: RTL8672 processor: 0 cpu model: 56322 An RTL8672 is not a full MIPS implementation, but a Lexra. You will need a customized toolchain that knows how to handle this. Something like this, or for a binary-only toolchain, look for rsdk; e.g., this.
“Illegal instruction” on a static MIPS binary
1,613,647,156,000
I'm a bit confused. I just read this: http://www.es.freebsd.org/doc/handbook/binary-formats.html, which basically says that freeBSD uses the elf binary format. But when I compile my code I using cc, I get a file called a.out. So what's going on here? Can I somehow specify in which format cc should build my code? Does freeBSD just support both formats? Is the resulting executable actually in elf format, but is it just called a.out for some reason:P?
The a.out file is still leftover from when compilers were using the a.out format. If you check the file with file a.out you will see it is actually in ELF format. To specify the name of the output file, use cc -o exec_name code.c.
How to compile to a specific executable format?
1,613,647,156,000
The coredumpctl utility displays a stack trace of the program when the coredump has been created. For example, on a firefox coredump: Stack trace of thread 14469: #0 0x00007f0ac652d3bd pthread_cond_wait@@GLIBC_2.3.2 (libpthread.so.0) #1 0x0000560f2ab95488 _ZN7mozilla6detail21ConditionVariableImpl4waitERNS0_9MutexImplE (firefox) #2 0x0000560f2ab95646 _ZN7mozilla6detail21ConditionVariableImpl8wait_forERNS0_9MutexImplERKNS_16BaseTimeDurationINS_27TimeDurati> #3 0x00007f0aba9799f9 n/a (libxul.so) #4 0x00007f0aba96eb9a n/a (libxul.so) #5 0x00007f0ac652708c start_thread (libpthread.so.0) #6 0x00007f0ac5abce7f __clone (libc.so.6) Considering that this is C code, and thus it is compiled, the symbols are not directly embedded in the binary file: so how is this possible? And also, how is this done in practice by readelf? (My guess, this is related to the symbol table embedded in the ELF file)
As you correctly guess, the symbols come from the symbol information embedded in the ELF files. Some symbol information is needed to be able to do dynamic linking, even if the full symbol table is not present. As far as the actual stacktrace is concerned, when a function is called the place for the cpu to return to is saved. For cpus like the x86 it is pushed on a stack. For RISC machines it is typically put into a register. If the function wants to call any other functions (i.e. it is not a leaf function) then this register is pushed onto a stack. The stacktrace code finds these addresses on the stack, looks up the nearest address in the symbols which is before it and reports it. Some stacktrace code prints both the symbol name and how far away it is, which can give you more confidence in how accurate it is. For example if the symbol is only 40 bytes before the return address then one has much more confidence that it is in that code, compared to it being 40,000 bytes before. In the latter case one might suspect that the return address points into a different function but that function doesn't have an entry in the symbol table. Lots of things can make this inaccurate. If a compiler inlines say function a into function b, then you might be in function a but the stacktrace will report you are in b. If the compiler does "Tail Call Optimization" where function a ends with something like return b(); and function c calls function a, you might expect the trace to show c->a->b, but you will only see c->b. This can be confusing if you look at the source for c and you see it never calls b directly.
How are stack traces reconstructed from a coredump?
1,613,647,156,000
I have an old PC with a program called atomTV, for viewing, and producing movies from molecular trajectory files. I only have a binary, and the platform it ran on was 64-bit MIPS architecture, where I was running IRIX. I have spoke with the creator, and he says he lost the source. My IRIX PC has died recently, but I still want to use this program. What can be done? The files are xyz, dcd, pdb and that type of thing. Preferably, I would like to know some way to run the program in a modern Unix/Linux environment. I have access to all the old files from the OS if that matters. When I tried to run the program in Linux, I got wrong ELF type errors.
I think the best bet is for you to acquire another SGI machine, unfortunately. There are several open source MIPS emulators but their functionality does vary. Available emulators include: GXemul Qemu Update: Newer releases of MAME are now able to run certain releases of IRIX, emulating an Indy. Instructions are available on the IRIX Network Wiki.
how can I run old programs from a MIPS?
1,613,647,156,000
While examining the /proc/<PID>/maps file for an aarch64 process running on an Android (8), I notice this section: 726048e000-7260564000 r-xp 00000000 103:00 5402 /system/lib64/libc++.so 7260564000-7260565000 ---p 00000000 00:00 0 7260565000-726056d000 r--p 000d6000 103:00 5402 /system/lib64/libc++.so 726056d000-726056e000 rw-p 000de000 103:00 5402 /system/lib64/libc++.so 726056e000-7260571000 rw-p 00000000 00:00 0 [anon:.bss] 72605b3000-72605b5000 r-xp 00000000 103:00 5641 /system/lib64/libpackagelistparser.so Here's the program header table for libc++.so: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000040 0x0000000000009040 0x0000000000009040 0x0001c0 0x0001c0 R 0x8 LOAD 0x000000 0x0000000000009000 0x0000000000009000 0x0d58fc 0x0d58fc R E 0x1000 LOAD 0x0d68e0 0x00000000000e08e0 0x00000000000e08e0 0x007770 0x00aea8 RW 0x1000 DYNAMIC 0x0dbb40 0x00000000000e5b40 0x00000000000e5b40 0x000220 0x000220 RW 0x8 NOTE 0x000200 0x0000000000009200 0x0000000000009200 0x000038 0x000038 R 0x4 GNU_EH_FRAME 0x0d3058 0x00000000000dc058 0x00000000000dc058 0x0028a4 0x0028a4 R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0 GNU_RELRO 0x0d68e0 0x00000000000e08e0 0x00000000000e08e0 0x007720 0x007720 RW 0x10 Taking the address 0xe08e0 of the second LOAD segment and adding the base of 0x726048e000, I come up with 0x726056e8e0. However, as seen in maps file above, there's no segment mapped right at that address. Instead, it overlaps with the [anon:.bss] segment. It's not even fully contained in the segment as, with a size of 0xaea8, its ending address would be 0x7260579788.
The last column of the program header table printed by readelf is the p_align member of the header, which defines an alignment requirement for the defined segment. From Linux man page elf(5): This member holds the value to which the segments are aligned in memory and in the file. Loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page size. Values of zero and one mean no alignment is required. Otherwise, p_align should be a positive, integral power of two, and p_vaddr should equal p_offset, modulo p_align. Because of the alignment value 0x1000, the initialized, read-only, data segment will be included in a memory mapping with offset 0x0d6000 (0x0d68e0 rounded down) and size 0x008000 (0x007770 rounded up), which is exactly what the maps file shows (the fourth field is the file offset and the mapping length can be calculated by substracting the end and start addresses. 0x726056d000 - 0x7260565000 = 0x8000). The two following mappings have the same alignment, and by their protection flags you can guess they correspond to the initialized data segment (.data) and the uninitialized data segment (.bss).
LOAD segment not loaded
1,613,647,156,000
I am trying to install a binary file, and I get the output as "Cannot install binary". When I did file .bin, the output is: c64plus-imglib_2_02_00_00_Linux-x86_Setup.bin: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, stripped On my ARM machine uname -a: returns Linux overo 3.5.7 #1 PREEMPT Thu Jan 9 16:37:38 CET 2014 armv7l GNU/Linux Is there a method to install an Intel binary on an ARM processor?
You cannot. A program in binary form can only be executed in a machine with a compatible ISA (Instruction Set Architecture, see Wikipedia article). Intel maintains backward ISA compatibility in each processor generation as a newer ISA is always a superset of older ISA, and a program created for i386 will run on Pentium. However this is not the case between radically different ISAs, like x86-64 and ARM. Additionally, your installer might be in x86-64 ISA, but the library you are trying to install is compiled in TI 'C64x ISA, a modern architecture from Texas Instruments used at their higher-end DSPs. So, even you use an Intel PC to install the libraries, you cannot copy them to your ARM board and use them, since they are made for that TI architecture. To make things worse, even if you had the sources of that library, it would be useless for you, since they would most likely be highly optimized for that architecture, using inline calls to assembly code to take advantage of special instructions and exotic hardware resources that only these DSP's may have. You can try to see if a free and open source image library has the code you are seeking. Begin with ImageMagick, but you are warned that these big and complex libraries might be a bit difficult to understand.
How to install an Intel binary file on ARM?
1,613,647,156,000
Recently I noticed something in several ELF files which looks for me a bit suspicious under Linux. Taking for example "/bin/ls" file and running readelf on it I can see following: There are 27 section headers, starting at offset 0x213b8: Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 0000000000000318 000318 00001c 00 A 0 0 1 [ 2] .note.gnu.property NOTE 0000000000000338 000338 000050 00 A 0 0 8 [ 3] .note.gnu.build-id NOTE 0000000000000388 000388 000024 00 A 0 0 4 [ 4] .note.ABI-tag NOTE 00000000000003ac 0003ac 000020 00 A 0 0 4 [ 5] .gnu.hash GNU_HASH 00000000000003d0 0003d0 00005c 00 A 6 0 8 [ 6] .dynsym DYNSYM 0000000000000430 000430 000bb8 18 A 7 1 8 [ 7] .dynstr STRTAB 0000000000000fe8 000fe8 0005dd 00 A 0 0 1 [ 8] .gnu.version VERSYM 00000000000015c6 0015c6 0000fa 02 A 6 0 2 [ 9] .gnu.version_r VERNEED 00000000000016c0 0016c0 0000d0 00 A 7 1 8 [10] .rela.dyn RELA 0000000000001790 001790 001ea8 18 A 6 0 8 [11] .init PROGBITS 0000000000004000 004000 00001b 00 AX 0 0 4 [12] .text PROGBITS 0000000000004020 004020 0133d3 00 AX 0 0 16 [13] .fini PROGBITS 00000000000173f4 0173f4 00000d 00 AX 0 0 4 [14] .rodata PROGBITS 0000000000018000 018000 00514f 00 A 0 0 32 [15] .eh_frame_hdr PROGBITS 000000000001d150 01d150 0005bc 00 A 0 0 4 [16] .eh_frame PROGBITS 000000000001d710 01d710 0021a0 00 A 0 0 8 [17] .init_array INIT_ARRAY 0000000000020f70 01ff70 000008 08 WA 0 0 8 [18] .fini_array FINI_ARRAY 0000000000020f78 01ff78 000008 08 WA 0 0 8 [19] .data.rel.ro PROGBITS 0000000000020f80 01ff80 000af8 00 WA 0 0 32 [20] .dynamic DYNAMIC 0000000000021a78 020a78 0001c0 10 WA 7 0 8 [21] .got PROGBITS 0000000000021c38 020c38 0003b0 08 WA 0 0 8 [22] .data PROGBITS 0000000000022000 021000 000278 00 WA 0 0 32 [23] .bss NOBITS 0000000000022280 021278 001298 00 WA 0 0 32 [24] .comment PROGBITS 0000000000000000 021278 00001b 01 MS 0 0 1 [25] .gnu_debuglink PROGBITS 0000000000000000 021294 000010 00 0 0 4 [26] .shstrtab STRTAB 0000000000000000 0212a4 00010f 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), D (mbind), l (large), p (processor specific) Taking a look at offset for section headers [23] and [24] we can see that these two sections have the same offset value of 021278. Is it possible that these 2 sections share the same offset in file? I'm not sure. Any bug here? I noticed that also in other ELF files there are other sections that share the same offset like .bss section. Anyone could explain why there is such conflict in offsets?
They share the same offset because the first of the two sections in the file is empty. BSS is used to reserve space at runtime, but that space is initialised to a known default (all zero) and isn’t stored in the binary. Sections have offsets in the address space (the “address” column) and in the file (the “offset” column). The two don’t have to match. In the example you show, 0x1298 bytes will be reserved in the program’s address space when it’s loaded (that’s what the “A” flag means).
Why the same offset of two sections in ELF?
1,613,647,156,000
Consider the following truncated output from running objdump -T (Prints dynamic symbol table entries) on the GNU ls utility. /usr/bin/ls: file format elf64-x86-64 DYNAMIC SYMBOL TABLE: 0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.3) __ctype_toupper_loc 0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) getenv 0000000000000000 DO *UND* 0000000000000000 (GLIBC_2.2.5) __progname 0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) sigprocmask 0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.3.4) __snprintf_chk 0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) raise 0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.34) __libc_start_main 0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) abort 0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) __errno_location 0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) strncmp 0000000000000000 w D *UND* 0000000000000000 Base _ITM_deregisterTMCloneTable What does Base mean in the last line 6th column? For example, It is apparent that (GLIBC_2.2.5) is the glibc version for strncmp function. However, in which external libraries are the Base functions defined? Any pointers in understanding this would be helpful.
Base means that there is no version associated with the symbol, i.e. the libraries which provide the symbols don’t provide multiple versions (or in the case of symbols in ls itself, ls contains a single version). The libraries used by ls can be seen using ldd /bin/ls. See What do the multiple GLIBC versions mean in the output of ldd? for details.
What does Base in objdump dynamic symbol table mean?
1,613,647,156,000
I'm currently doing a nm like program, to print the symbols of an ELF file with their addresses and their type. The typical output is something like : $ nm ./my_exec 0000000000003d28 d _DYNAMIC 0000000000003f28 d _GLOBAL_OFFSET_TABLE_ 0000000000002000 R _IO_stdin_used w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable The first column is the symbol address, the second is the symbol type and the third, the symbol name. The man indicates the meaning for each character, upper-case is a global symbol, lower-case is local symbol etc... But I don't understand how it choose which character to use. I'm using the Gelf library and I didn't see a field from where I could determine the character.
nm chooses the character mostly based on the section in which the symbol appears. ELF is specified in the System V ABI; pages 4-22 and following describe the symbol table, which include two fields, st_info and st_shndx, and these determine the character shown by nm. The symbol binding (ELF32_ST_BIND(st_info)) determines whether the symbol is local (lowercase in nm), global (uppercase), or weak (v, w). sh_shndx points to the section containing the symbol, and many of nm’s characters reflect this, either as an explicit section (b, d...), or as a value with special meaning (e.g. u for SHN_UNDEF, undefined symbols). So you won’t find a single value which directly corresponds to the character shown by nm, but the above should give you enough information to interpret the values described in the ABI specification.
How do `nm` choose the character to print for each symbol type?
1,613,647,156,000
If the Linux kernel by itself is an ELF file, where can I find its ELF file?
On many systems you can find a compressed kernel in /boot, typically named vmlinuz-$(uname -r). The ELF executable contained therein can be extracted using the extract-vmlinux script, available in the kernel source code: extract-vmlinux /boot/vmlinuz-$(uname -r) > vmlinux The result is an ELF file: $ file vmlinux vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=b28d236fad2fb7d0eb9bbe6eac766fb04406da3f, stripped (on x86-64). If you’re building the kernel, make vmlinux will produce the ELF executable.
Where is the linux kernel elf file located?
1,613,647,156,000
In "Uninformed Research -- informative information for the uninformed." 2003 mentions a tool called elfsign and elfverify. This is a tool to checksum and sign an ELF binary. I can't find that tool in Debian. Does it still exist and is it maintained?
That tool seems to be written by the same author of the paper skape ([email protected]). It's withheld from Debian for licensing reasons -- currently being under "The Clarified Artistic License". The code can be found on his site, http://www.hick.org/code/skape/elfsign/
What happened to elfsign and elfverify?
1,613,647,156,000
I'm maintaining a C-program, that uses Oracle client libraries. The libraries expect the ORACLE_HOME environment variable to be set, and fail to work without it -- in many cases. In our situation, the value of the variable is always derived from the location of the shared libraries themselves anyway -- and I'd like to implement setting it from the C-code (using putenv(3)). But, for that, I need to know, from where a particular shared library used by the program was loaded. So, if ldd, when applied to the executable file, outputs: libc.so.7 => /lib/libc.so.7 (0x1021000) libmeow.so.1 => /opt/meow/lib/libmeow.so.1 How can the running process itself find out, that libmeow.so, which it is using, is loaded from /opt/meow/lib? The answer needn't be universally-portable -- something, that'd work for just Linux and BSD will suffice.
For Linux you can read and search through pseudo file /proc/<pid>/maps, where <pid> would be self from a program looking at itself. It has lines for each memory mapped item, which should include each shared library, eg 7f63c2c23000-7f63c2dd0000 r-xp 00000000 08:01 136321 /usr/lib64/libc-2.26.so See man proc for details. There is also a C api for a program to walk through the list of shared objects it is using. See man dl_iterate_phdr. It provides an example of its use. For your use case it is as simple as this: #define _GNU_SOURCE #include <link.h> #include <stdlib.h> #include <stdio.h> static int callback(struct dl_phdr_info *info, size_t size, void *data){ if(info->dlpi_name[0]!='\0')printf("%s\n", info->dlpi_name); return 0; } int main(int argc, char *argv[]) { dl_iterate_phdr(callback, NULL); exit(EXIT_SUCCESS); }
Figuring out location of a loaded shared library
1,613,647,156,000
I was reading the Rust Unstable Book, and I saw a new feature for emit-stack-sizes, The rustc flag -Z emit-stack-sizes makes LLVM emit stack size metadata. It goes on to say NOTE: This LLVM feature only supports the ELF object format as of LLVM 8.0. Using this flag with targets that use other object formats (e.g. macOS and Windows) will result in it being ignored. The LLVM Feature it seems to be using is the EmitStackSizeSection option. What's the purpose of knowing the stack size? Does tooling use this? Is this an official feature of ELF and if so does the kernel make use of this? This seems to get recorded in the ELF metadata under the sections .stack_sizes, .rel.stack_sizes, and .rela.stack_sizes
This somewhat outlined here in the original RFC, "[eRFC] add -Z emit-stack-sizes" The end goal is to enable whole program analysis of stack usage to prove absence of stack overflows at compile time. Such property is important in systems that lack a MMU / MPU and where stack overflows can corrupt memory. And in systems that have protection against stack overflows such proof can be used to opt out of runtime checks (e.g. stack probes or the MPU). And further in this blog entry, "Implementing a static stack usage analysis tool". The tooling for this, with rust, is available here https://github.com/japaric/cargo-call-stack
What purpose does ELF's stack-size metadata have?
1,613,647,156,000
I'm trying to locate where the libc program segments are in a program's memory, by reading the program headers. On Centos 6, when I use readelf on the libc.so.6 file, the VirtAddr contains the correct address where the program segment is loaded in the process's memory: [user@centos6 src]$ readelf -l /lib64/libc.so.6 --wide Elf file type is DYN (Shared object file) Entry point 0x3032c1ee30 There are 10 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000040 0x0000003032c00040 0x0000003032c00040 0x000230 0x000230 R E 0x8 INTERP 0x15aab0 0x0000003032d5aab0 0x0000003032d5aab0 0x00001c 0x00001c R 0x10 [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] LOAD 0x000000 0x0000003032c00000 0x0000003032c00000 0x18a00c 0x18a00c R E 0x200000 LOAD 0x18a700 0x0000003032f8a700 0x0000003032f8a700 0x004f58 0x009228 RW 0x200000 DYNAMIC 0x18db40 0x0000003032f8db40 0x0000003032f8db40 0x0001f0 0x0001f0 RW 0x8 NOTE 0x000270 0x0000003032c00270 0x0000003032c00270 0x000044 0x000044 R 0x4 TLS 0x18a700 0x0000003032f8a700 0x0000003032f8a700 0x000010 0x000068 R 0x8 GNU_EH_FRAME 0x15aacc 0x0000003032d5aacc 0x0000003032d5aacc 0x0065ec 0x0065ec R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x8 GNU_RELRO 0x18a700 0x0000003032f8a700 0x0000003032f8a700 0x003900 0x003900 R 0x1 So in this case, the DYNAMIC segment is located at 0x0000003032f8db40 But on Centos 7, the VirtAddr contains an offset instead, and I have to add the libc base address to this offset to find where the segment is in memory: [user@centos7 src]$ readelf -l /usr/lib64/libc.so.6 --wide Elf file type is DYN (Shared object file) Entry point 0x22660 There are 10 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x000230 0x000230 R E 0x8 INTERP 0x18eb00 0x000000000018eb00 0x000000000018eb00 0x00001c 0x00001c R 0x10 [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x1c3170 0x1c3170 R E 0x200000 LOAD 0x1c36f0 0x00000000003c36f0 0x00000000003c36f0 0x0051b0 0x009b10 RW 0x200000 DYNAMIC 0x1c6b60 0x00000000003c6b60 0x00000000003c6b60 0x0001f0 0x0001f0 RW 0x8 NOTE 0x000270 0x0000000000000270 0x0000000000000270 0x000044 0x000044 R 0x4 TLS 0x1c36f0 0x00000000003c36f0 0x00000000003c36f0 0x000010 0x0000a0 R 0x10 GNU_EH_FRAME 0x18eb1c 0x000000000018eb1c 0x000000000018eb1c 0x006aec 0x006aec R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 GNU_RELRO 0x1c36f0 0x00000000003c36f0 0x00000000003c36f0 0x003910 0x003910 R 0x1 In this case, the DYNAMIC segment would be located at 0x00000000003c6b60 + libc base address. I'm guessing this is probably due to ASLR on Centos 7, which causes the libc library to be loaded at a different address each time. On Centos 6, it seems like the libc is always loaded at the same address. Is there a way to determine, just from reading the ELF header, whether I need to add the libc base address to the VirtAddr to get the actual location of the program segment in memory?
I think I figured it out, you need to check all of the PT_LOAD segments and find the one with the lowest p_vaddr (I'll call it lowest_pt_load). Then to work out the memory location it is: libc_base + segment.p_addr - lowest_pt_load.p_vaddr What was happening in the Centos 6 case was that lowest_pt_load was equal to libc base address, causing them to cancel out. Source: https://docs.oracle.com/cd/E19683-01/816-1386/6m7qcoblk/index.html#chapter6-83432 Base Address Executable and shared object files have a base address, which is the lowest virtual address associated with the memory image of the program's object file. One use of the base address is to relocate the memory image of the program during dynamic linking. An executable or shared object file's base address is calculated during execution from three values: the memory load address, the maximum page size, and the lowest virtual address of a program's loadable segment. The virtual addresses in the program headers might not represent the actual virtual addresses of the program's memory image. See "Program Loading (Processor-Specific)". To compute the base address, you determine the memory address associated with the lowest p_vaddr value for a PT_LOAD segment. You then obtain the base address by truncating the memory address to the nearest multiple of the maximum page size. Depending on the kind of file being loaded into memory, the memory address might not match the p_vaddr values.
How to tell whether the p_vaddr in ELF program header is the real memory address or is just an offset from the shared library base address?
1,382,410,950,000
I'm trying to send unix mail (heirloom-mailx) via bcc. $ mail -V 12.5 6/20/10 My MTA is exim, which sends via Gmail SMTP. I can execute the following: echo -e "body" | mail -s 'subject' -b [email protected],[email protected] [email protected] All addresses receive the email, however the bcc is not hidden. i.e. in the email to [email protected], I still see: To: [email protected] Bcc: [email protected],[email protected] How can I make mail send bcc properly?
heirloom-mailx hardcodes the options to pass to /usr/sbin/sendmail, and unfortunately the ones it passes don't make Bcc: headers work right in exim. That isn't really fixable, without patching and recompiling it. (You need to have it add -t to the arguments, and then either not pass the list of email addresses or alternatively set extract_addresses_remove_arguments = false in your exim config). There is an easier solution: just have it send via SMTP. You do this by setting the smtp option, and since you've got a local MTA running, you should be able to set it to localhost. You can test like this: $ mail -S smtp=localhost -s 'test message' -b [email protected] [email protected] la la la . If that works, you can put the smtp option in /etc/nail.rc (system-wide) or ~/.mailrc (per-user). Note that nail.rc, with an n, is not a typo.
How can I bcc with mailx?
1,382,410,950,000
I have configured the Debian workstations at our department to use Exim 4 for mail delivery. Also I have created an alias such that I receive all the root emails. The Exim 4 configuration (via Ansible and debconf) has those settings: exim4_dc_eximconfig_configtype: internet exim4_dc_readhost: … exim4_dc_smarthost: … exim4_dc_use_split_config: 'true' exim4_dc_hide_mailname: 'true' exim4_dc_mailname_in_oh: 'true' On each of the machines, I can use mailx to send an email to root and it will show up in my inbox just fine. Also some executions of the cron jobs are properly sent to me. However, most cron jobs fail to deliver their emails and instead I get the following email: This message was created automatically by mail delivery software. A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: ueding@… (generated from root@echo) Reporting-MTA: dns; echo Action: failed Final-Recipient: rfc822;ueding@… Status: 5.0.0 Return-path: <root@echo> Received: from root by echo with local (Exim 4.89) (envelope-from <root@echo>) id 1f7Jqz-0007jU-7y for root@echo; Sat, 14 Apr 2018 14:00:25 +0200 From: root@echo (Cron Daemon) To: root@echo Subject: Cron <root@echo> ansible-pull -U [email protected]:…/….git --private-key /root/.ssh/ansible_pull localhost.yml MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit X-Cron-Env: <SHELL=/bin/sh> X-Cron-Env: <HOME=/root> X-Cron-Env: <PATH=/usr/bin:/bin> X-Cron-Env: <LOGNAME=root> Message-Id: <E1f7Jqz-0007jU-7y@echo> Date: Sat, 14 Apr 2018 14:00:25 +0200 X-Exim-DSN-Information: Due to administrative limits only headers are returned I really do not understand why this is happening. Either all email delivery fails, or almost all succeed. How can the email from cron fail on most workstations but succeed on others, while the delivery failure emails always get through? The system log regarding exim on the machine, echo, is really sparse: # journalctl -u exim4.service -- Logs begin at Tue 2018-03-06 18:35:11 CET, end at Sat 2018-04-14 17:13:08 CEST. -- Apr 02 18:00:30 echo systemd[1]: Starting LSB: exim Mail Transport Agent... Apr 02 18:01:23 echo exim4[27433]: Starting MTA: exim4. Apr 02 18:01:23 echo systemd[1]: Started LSB: exim Mail Transport Agent. Looking into /var/log/exim4/mainlog serves the explanation on a silver platter: 2018-04-14 14:00:25 1f7Jqz-0007jU-7y <= root@echo U=root P=local S=7948 2018-04-14 14:00:25 1f7Jqz-0007jU-7y ** ueding@… <root@echo> R=dnslookup T=remote_smtp: message is too big (transport limit = 1) 2018-04-14 14:00:25 1f7Jqz-0007jW-BM <= <> R=1f7Jqz-0007jU-7y U=Debian-exim P=local S=1856 2018-04-14 14:00:25 1f7Jqz-0007jU-7y Completed 2018-04-14 14:00:26 1f7Jqz-0007jW-BM => ueding@… <root@echo> R=dnslookup T=remote_smtp H=… […] X=TLS1.0:RSA_AES_256_CBC_SHA1:256 CV=yes DN="C=DE,ST=…,L=…,O=…,OU=…,CN=…" C="250 2.0.0 Ok: queued as 6FCA1155FC32" 2018-04-14 14:00:26 1f7Jqz-0007jW-BM Completed The error likely is “message is too big (transport limit = 1)”. But that still does not make so much sense since I have 30 identically configured workstations and for some of them the messages get through several days in a row. The length of the message should be the same for each machine (except the length of the hostname), and the two machines which currently get their emails through have longer names.
I think you've hit this reported bug, exim4: bogus reject response on overlong lines. It actually refers to lines that are too long, not the message itself. Try piping your message through fmt -s before passing it to exim4.
Mail delivery notices are correctly delivered, actual mail isn't
1,382,410,950,000
I am moving servers, both of them running Debian (oldstable and stable). Both are running Exim4. When I switch the DNS entries over to the new server, I'd like the old server to still forward incoming mail to my new server for processing, so that users do not see any outage. How can I do this?
Just replace all routers by one manualroute that points directly to the new MX: begin routers redir: driver = manualroute domains = * transport = remote_smtp route_list = * 12.34.56.78 Here 12.34.56.78 - is an IP-address of your new MX where all messages should go.
How to configure Exim to forward all incoming mail to new server?
1,382,410,950,000
dpkg-reconfigure exim4-config asks for a domain name to "qualify" email addresses of local users such as root. Let's say I've set this setting to qualified.example.com - this causes all email sent to simply root to go to [email protected]. I instead want all email to root to be sent to [email protected], but I want the qualified domain name setting left set to qualified.example.com for other reasons. I've added this line to /etc/aliases root: [email protected] And I've also put [email protected] in /root/.forward I've run newaliases and restarted exim, but no matter what I do, mail to root continues to always try to send to [email protected], which doesn't even exist. How can I force email to root to go to [email protected]? This is on Ubuntu Server 14.04 My /etc/exim4/update-exim4.conf.conf looks like this: dc_eximconfig_configtype='internet' dc_other_hostnames='' dc_local_interfaces='127.0.0.1' dc_readhost='' dc_relay_domains='' dc_minimaldns='false' dc_relay_nets='' dc_smarthost='' CFILEMODE='644' dc_use_split_config='false' dc_hide_mailname='' dc_mailname_in_oh='true' dc_localdelivery='mail_spool' When I ran dpkg-reconfigure exim4-config I answered the qualified domain question like so: The 'mail name' is the domain name used to 'qualify' mail addresses without a domain name. This name will also be used by other programs. It should be the single, fully qualified domain name (FQDN). Thus, if a mail address on the local host is [email protected], the correct value for this option would be example.org. This name won't appear on From: lines of outgoing messages if rewriting is enabled. System mail name: qualified.example.com_________ Although that setting doesn't appear in /etc/exim4/update-exim4.conf.conf. Should it? I've noticed that the same issue happens on my Debian servers too. I must be completely misunderstanding something about Exim and/or the /etc/aliases file, because they all seem to ignore my /etc/aliases root: [email protected] entry and they always send root's mail to [email protected] no matter what I try. It also seems odd that a simple forwarding rule is so dependent on the mail servers main configuration?
Your host doesn't sufficiently know that it is supposed to be qualified.example.com. A local delivery to root is rewritten as [email protected], which is (wrongly) considered to be elsewhere, so an off-host delivery is attempted. You need to complete the process telling exim4 that your local host really is qualified.example.com. Then, when it delivers to root, rewritten as [email protected] it will consider this as local delivery. It will then check the /etc/aliases file and perform off-host delivery to [email protected] per your instructions. Let's assume your host's real DNS name is myhost.contoso.com. Rerun dpkg-reconfigure exim4-config and include these settings: System mail name: myhost.contoso.com Other destinations for which [local] mail is accepted: myhost : qualified.example.com Domains to relay mail for: {empty} Machines to relay mail for: {empty} Then run update-exim4.conf and invoke-rc.d exim4 restart
Exim: Email to root ignores /etc/aliases and /root/.forward - always used qualifies domain name
1,382,410,950,000
550 relay not permitted That's the error message when email sent by Exim4 from my Debian laptop bounces. What's weird is that only the first email bounces. Second and subsequent emails pass through the relay and on to their destinations just fine. If I reboot my laptop, though, the first email after reboot bounces again. The relay is plaintext password protected after STARTTLS on port 587. The X.509 certificate is a real one, not a snakeoil. I administer both the relay server and the laptop. The relay server too runs Exim4 on Debian, if it matters. Postfix is not involved. I suppose that one could work around the problem by configuring the laptop to send a dummy email (or maybe even just an SMTP EHLO?) each time it boots, but the behavior worked around just seems odd. I'm stumped. If you know what I should next investigate to solve this, would you advise me?
Your email timeout could well be due to your daemon trying IPv6 first. The IPv6 stack implementation by default has priority over the IPv4 stack so when programs/daemons try to communicate they will try first to use the IPv6 address, when the destination has both public IPv4 and IPv6 address. Even if you do not have public IPv6, you have IPv6 localhost and link local addresses. It would be not the first time, and probably not the last time, that I do catch Internet daemons trying first the link local address as source IP address to communicate to another address, and only after timing out, if they still have time/tries allotted, might fall back to sending the data to the IPv4 destination. (In the past, I already had DNS and email problems due to this in an ISP I used to run.) So for exim, you can disable IPv6 at application/daemon level, using the directive disable_ipv6=true in /etc/exim4/exim4.conf.template or /etc/exim4/update-exim4.conf.conf depending on whether you are using the non-split or the split configuration scheme. From Exim Internet Mailer-Chapter 14 - Main configuration disable_ipv6 Use: main Type: boolean Default: false If this option is set true, even if the Exim binary has IPv6 support, no IPv6 activities take place. AAAA records are never looked up, and any IPv6 addresses that are listed in local_interfaces, data for the manualroute router, etc. are ignored. If IP literals are enabled, the ipliteral router declines to handle IPv6 literal addresses. An alternative approach might be also binding it only to IPv4 addresses, however the disadvantage is having to hardcode the IPv4 address(es) in the configuration: local_interfaces = <; 127.0.0.1 ; \ 192.168.23.65 As for the system itself, as you are not actively using IPv6: add as the last line to give priority by default to IPv4, to the file /etc/gai.conf precedence ::ffff:0:0/96 100 Add to /etc/sysctl.conf to disable by default the IPv6 stack (setting supported from kernel 3 onwards): net.ipv6.conf.all.disable_ipv6=1 The sysctl will be applied at boot time. To activate it before booting, do: sudo sysctl -p Whilst they call it an IPv6 deactivation, the module is still loaded, and while the interfaces do not have IPv6 addresses anymore, you can still see applications connected to their IPv6 sockets. You can also pass to the kernel an option to disable IPv6, and the IPv6 kernel module won't be loaded. Editing /etc/default/grub: GRUB_CMDLINE_LINUX="ipv6.disable=1" And then to apply it, if you have grub (your grub partition may vary or you might not have it; I do not have it in my ARM servers, and have to edit other file for the kernel options): sudo update-grub sudo grub-install /dev/sda You may have to configure one or other daemon to disable IPv6 at the application level (from the top of my head, xinetd, if you have it installed).
The first email bounces; the second and subsequent emails go through
1,382,410,950,000
I have over the last days tried to setup Exim4 to handle all mails sent from a web application. It seems to be working, but I haven't found out how to hardcode the hostname which will be sent with EHLO? (I don't want to set /etc/hostname) Have found the variable MAIN_HARDCODE_PRIMARY_HOSTNAME mentioned in the config but havn't found a way to set it. Is this variable the simplest way to set the hostname or is there a better way to do it? Below is the complete install/config.. Am I missing something? Exim version 4.92 Debian Buster 10 Install apt-get install exim4-daemon-light Configure Exim4 dpkg-reconfigure exim4-config Type: internet site FQDN: smtp.mydomain.com SMTP listener: (empty) Mail destinations: (empty) Domain relay: (empty) Machine relay: (empty) DNS queries minimal: No Delivery method: Maildir Split conf files: No Enable TLS and generate certs printf "MAIN_TLS_ENABLE = true\n" >> /etc/exim4/exim4.conf.localmacros /usr/share/doc/exim4-base/examples/exim-gencert check reverse DNS (IP -> smtp.mydomain.com) https://mxtoolbox.com/ReverseLookup.aspx Get IPv6 ip -6 addr | grep inet6 | awk -F '[ \t]+|/' '{print $3}' | grep -v ^::1 | grep -v ^fe80 /etc/hosts [ipv4] smtp.mydomain.com [ipv6] smtp.mydomain.com uncomment in '/etc/exim4/exim4.conf.template' # plain_server: # driver = plaintext # public_name = PLAIN # server_condition = "${if crypteq{$3}{${extract{1}{:}{${lookup{$2}lsearch{CON$ # server_set_id = $2 # server_prompts = : # .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS # server_advertise_condition = ${if eq{$tls_cipher}{}{}{*}} # .endif add user/pass -> '/etc/exim4/passwd' /usr/share/doc/exim4-base/examples/exim-adduser DKIM/SPF I have setup DKIM keys on the server and DKIM/SPF on DNS and both works
Set REMOTE_SMTP_HELO_DATA = whatever.you.want in /etc/exim4/exim4.conf.localmacros. It's supported by the Debian package since 4.69-10. From /usr/share/doc/exim4/changelog.Debian.gz: Allow setting outgoing smtp helo/ehlo by setting REMOTE_SMTP_HELO_DATA macro directly. Previously this was just supposed to be used as a helper macro for REMOTE_SMTP_HELO_FROM_DNS. REMOTE_SMTP_HELO_FROM_DNS overrides a manual REMOTE_SMTP_HELO_DATA data setting. Closes: #514113 This macro is used by the Debian configuration template to populate the helo_data SMTP transport option.
Complete setup of Exim4 as SMTP to reach most inboxes as possible (correct configuration)
1,382,410,950,000
I'd like to manage all email incoming to *@example.com with a Python script running on my server, which will do various jobs. I've already done a DNS MX record for example.com, directing it my server: mx.example.com MX mailforwarder.example.com mailforwarder.example.com A 1.2.3.4 I've done lots of trials and errors with both postfix and exim, and nothing was working, so I removed all of them: apt-get remove postfix and apt-get remove exim4, so I'm ready to start with a fresh install of one of them (which one would allow the shortest solution for this specific task?) What are the main steps to direct all incoming email *@example.com to a Python script? (including: telling the MTA to accept emails coming from outside of the server, from whole internet, etc.)
procmail is considered problematical by Philip Guenther (and is quite possibly useless in this case, as .forward files or equivalent can send the mails directly to your program, skipping the thus needless complexity of procmail). Executive summary: delete the procmail port; the code is not safe and should not be used as a basis for any further work. As people may know, I was the upstream maintainer of procmail back in the late 1990's though 2001. So some other solution may be advisable; this depends on the Mail Transport Agent (MTA). Another option would be to use the MTA to deliver to a local file or IMAP, then have your program parse that file or IMAP. This has the bonus of continuing to accept email and saving it somewhere; what happens when your program is buggy or otherwise fails to run? Less of a problem than during live mail delivery... Exim Probably either copy the Sendmail .forward method or figure out how to do this properly in Eximese. (I aborted as it was taking to much time to dig through the Exim docs.) There is elspy if you want to do at-SMTP-time scanning in a MILTER fashion... Postfix https://serverfault.com/questions/258469/how-to-configure-postfix-to-pipe-all-incoming-email-to-a-script#258491 Gosh that seems long and complicated. Sendmail Set a mailertable entry to forward all mails for the domain (and .domain for subdomains, if necessary) to a local user, here jdoe example.com local:jdoe .example.com local:jdoe and then setup a .forward file for that user to run the necessary code $ cat ~jdoe/.forward "|/etc/smrsh/process" $ which could be as simple as $ cat /etc/smrsh/process #!/bin/sh cat >> /home/jdoe/allmails $ because the emails are fed in on standard input (this might be bad if multiple instances of this process run at once; presumably your actual code handles such race conditions or is otherwise idempotent...right?). This method may also work for any other MTA that copies Sendmail's forward syntax, assuming you can get the MTA to redirect all mails to a particular user. This assumes mailertable support is enabled, confFORWARD_PATH is set, that Sendmail is allowed to run the code (see smrsh(8) though note that some vendors may change the directory without updating the documentation (running strings /the/path/to/smrsh | fgrep / may help)) and that something like selinux isn't also breaking things. Another option for Sendmail is to use a MILTER such as MIMEDefang and perform whatever business logic is necessary there. (Various other MTA support MILTER, or have something like it.) Simple Mail Transfer Protocol daemon (OpenBSD) From a look at smtpd.conf(5) (updated for OpenBSD 6.4 changes) action "mymda" mda "/path/to/your/command" user jdoe match from any for domain example.com action "mymda"
Redirect all incoming email to a Python script
1,382,410,950,000
I updated my /etc/spamassassin/local.cf spamassassin file to update some score rules. However, even after restarting spamassassin (via service), the new score are not shown in spam emails. In fact, nothing in that file seem to influence how spamassassin work. I use exim as my MTA but that should not matter. All packages were installed via apt-get and are at the latest version for 14.04. For example, I have this: score HTML_MESSAGE 2.0 define in /etc/spamassassin/local.cf. I restarted both exim and spamassassin. spamassassing --lint shows that there are no errors int hat file. Then got yet another spam with this: 0.0 HTML_MESSAGE BODY: HTML included in message In the X-Spam-Report field. I ran spamassassin -D < spam and the order of loading of cfg files seems to be wrong: Jun 8 13:34:07.300 [21668] dbg: config: read file /etc/spamassassin/local.cf ... Jun 8 13:34:07.600 [21668] dbg: config: read file /var/lib/spamassassin/3.004000/updates_spamassassin_org/50_scores.cf ... Jun 8 13:34:07.787 [21668] dbg: config: read file /var/lib/spamassassin/3.004000/updates_spamassassin_org/73_sandbox_manual_scores.cf Jun 8 13:34:07.788 [21668] dbg: config: fixed relative path: /var/lib/spamassas sin/3.004000/updates_spamassassin_org/local.cf ... What is going on? Based on a comment from Centimane: I tried strace -f -e trace=file spamassassin -D < spam with the same result: Spamassassin is reading system files after the local.cf file. Thus, trashing any score changes. From comments, here is the local.cf file, which is more or less the vanilla one. # This is the right place to customize your installation of SpamAssassin. # # See 'perldoc Mail::SpamAssassin::Conf' for details of what can be # tweaked. # # Only a small subset of options are listed below # ########################################################################### # Add *****SPAM***** to the Subject header of spam e-mails # rewrite_header Subject *****SPAM***** add_header spam Flag _YESNOCAPS_ add_header all Checker-Version SpamAssassin _VERSION_ (_SUBVERSION_) on _HOSTNAME_ add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTS_ autolearn=_AUTOLEARN_ bayes=_BAYES_ add_header all Report _SUMMARY_ # Save spam messages as a message/rfc822 MIME attachment instead of # modifying the original message (0: off, 2: use text/plain instead) # # report_safe 1 # Set which networks or hosts are considered 'trusted' by your mail # server (i.e. not spammers) # # trusted_networks 212.17.35. # Set file-locking method (flock is not safe over NFS, but is faster) # # lock_method flock # Set the threshold at which a message is considered spam (default: 5.0) # required_score 5.0 # Use Bayesian classifier (default: 1) # use_bayes 1 bayes_path /var/lib/spamassassin/bayes/bayes bayes_file_mode 0777 # Bayesian classifier auto-learning (default: 1) # bayes_auto_learn 1 # Set headers which may provide inappropriate cues to the Bayesian # classifier # bayes_ignore_header X-Bogosity bayes_ignore_header X-Spam-Flag bayes_ignore_header X-Spam-Status # Some shortcircuiting, if the plugin is enabled # ifplugin Mail::SpamAssassin::Plugin::Shortcircuit # # default: strongly-whitelisted mails are *really* whitelisted now, if the # shortcircuiting plugin is active, causing early exit to save CPU load. # Uncomment to turn this on # shortcircuit USER_IN_WHITELIST on shortcircuit USER_IN_DEF_WHITELIST on shortcircuit USER_IN_ALL_SPAM_TO on shortcircuit SUBJECT_IN_WHITELIST on # the opposite; blacklisted mails can also save CPU # shortcircuit USER_IN_BLACKLIST on shortcircuit USER_IN_BLACKLIST_TO on shortcircuit SUBJECT_IN_BLACKLIST on # if you have taken the time to correctly specify your "trusted_networks", # this is another good way to save CPU # # shortcircuit ALL_TRUSTED on # and a well-trained bayes DB can save running rules, too # shortcircuit BAYES_99 spam shortcircuit BAYES_00 ham blacklist_from wokfrance.com blacklist_from brother-mailer.com blacklist_from *.sd-soft.net blacklist_from woifrance.com blacklist_from adimacocl.net blacklist_from bletspuranawyat.net blacklist_from sd-soft.net blacklist_from m1web-track.com blacklist_from winntoniecline.net blacklist_from kafod.org blacklist_from *.kafod.org blacklist_from [email protected] blacklist_from *.bhlive.co.uk blacklist_from *.regionasm.net blacklist_from regionasm.net ## Tweaks. score AC_BR_BONANZA 1.0 score ADMITS_SPAM 10.0 score A_HREF_TO_REMOVE 2.0 score DEAR_FRIEND 4.0 score FREEMAIL_FORGED_FROMDOMAIN 4.0 score FREEMAIL_FROM 1.0 score FROM_LOCAL_HEX 9.0 score HTML_MESSAGE 2.0 score RCVD_IN_MSPIKE_BL 2.0 score RCVD_IN_SORBS_WEB 2.0 score RCVD_IN_XBL 3.0 score RDNS_NONE 2.0 score SCVD_IN_DNSWL_BLOCKED 3.0 score T_DKIM_INVALID 1.0 score T_FREEMAIL_DOC_PDF 3.0 score T_REMOTE_IMAGE 3.0 score URIBL_BLOCKED 3.0 score URIBL_DBL_SPAM 3.0 score URIBL_JP_SURBL 3.0 score URIBL_WS_SURBL 3.0 endif # Mail::SpamAssassin::Plugin::Shortcircuit And the whole output of spamassassin -D is too big for this. However, the relevant lines are above. If you want more information, tell me what to look for and I will add it.
The problem is that you are setting the HTML_MESSAGE score inside the Shortcircuit plugin. But that plugin comes disabled by default. Try to set the score in the last line of the file, after the Shortcircuit endif instruction: # Some shortcircuiting, if the plugin is enabled # ifplugin Mail::SpamAssassin::Plugin::Shortcircuit # [...] endif # Mail::SpamAssassin::Plugin::Shortcircuit score HTML_MESSAGE 2.0 If you prefer to enable the Shortcuit plugin, you need to uncomment it from the /etc/spamassassin/v320.pre file: # Shortcircuit - stop evaluation early if high-accuracy rules fire # loadplugin Mail::SpamAssassin::Plugin::Shortcircuit
spamassassin does not honour local.cf
1,382,410,950,000
I'm trying to configure spam filter on VPS Debian Squeeze, exim4-heavy + spamassassin and dovecot. Exim version 4.72, SpamAssassin version 3.3.1, Perl version 5.10.1 And I have an irritating problem with spamassassin: messages has no X-Spam headers. Exim4 config: ### main/02_exim4-config_options spamd_address = 127.0.0.1 783 ### acl/40_exim4-config_check_data warn spam = nobody:true add_header = X-Spam-Score: $spam_score accept /etc/spamassassin/local.cf ( defaults omitted ) report_contact [email protected] add_header spam Flag _YESNOCAPS_ add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTS_ autolearn=_AUTOLEARN_ version=_VERSION_ add_header all Level _STARS(*)_ required_score 4.5 All messages have X-Spam-Score header added by exim, but no one has X-Spam- headers which should be added by spamd. I have received some spam email and tried gtube.txt, but no additional headers was added Headers of the spam ( score greater than 4.5, but no X-Spam-Flag ) X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Windows Live Mail 14.0.8117.416 X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8117.416 X-Spam-Score: 8.8 What did I miss?
the problem you are facing is, that things work a little bit differently than how you expect them to run. this is not how it works: exim receives an email exim passes the email to spamd spamd checks the email for spam and adds necessary headers spamd passes the (modified) email back to exim exim delivers the email instead it works like this: exim reveices an email exim passes the email to spamd spamd checks the email for spam spamd reports the spam-status back to exim (not the email) exim does whatever it deems appropriate to the email (add some headers, discard it, ignore the results of spamd) exim delivers the email luckily exim can add quite a few things to the email, based on what spamd reports. e.g. i use: warn message = X-Spam-Score: $spam_score spam = nobody:true warn message = X-Spam-Level: $spam_bar spam = nobody:true warn message = X-Spam-Tests: $spam_report spam = nobody:true which will add something like the following to the email-headers: X-Spam-Score: 8.9 X-Spam-Level: ++++++++ X-Spam-Tests: DEAR_FRIEND=2.604,FREEMAIL_REPLYTO=1,FREEMAIL_REPLYTO_END_DIGIT=0.25,LOTS_OF_MONEY=0.001,MONEY_FRAUD_3=3.699,RCVD_IN_BL_SPAMCOP_NET=1.246,... a little bit of information can be found here the reason for your confusion is, that spamd could also modify the email by itself (e.g. this is used when you run spamd after exim). it's only that exim-damon-heavy handles it the way i described it.
missed X-Spam- headers for all messages in exim4 + spamassassin
1,382,410,950,000
I know that you can change the from address in *nix mail by specifying command-line options. However, is there a way to set it globally, so that it is respected by forwarding? I tried modifying the $REPLYTO environment variable, but this did not help. Background I have set up my Raspbian mail to forward by configuring /etc/aliases. However, for external email recipients, the sender is [email protected], where pi is the Linux login name. I want to find a way to specify the username manually, to match my email account, [email protected]. My exim4 configuration is specified here. N.B. there is an option to specify the sender domain ("Visible domain name for local users: bar.com"), but not a way to specify the username for each account.
It sounds like you want Exim's address rewriting. In the rewriting section of your Exim config file, you will probably want something along the lines of this: [email protected] [email protected] Ffr You may need to adjust the flags ("Ffr") to the specific behavior you want. More generally, see: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-address_rewriting.html Raspbian Specifically, in Raspbian, edit /etc/exim4/exim4.conf.template, adding the following in the REWRITE CONFIGURATION section. [email protected] [email protected] Ffr If you prefer all outgoing email to be from [email protected], regardless of original sender, use this line instead. * [email protected] Ffr Next, run sudo update-exim4.conf, then check to make sure it worked with exim -brw [email protected]. This should print out a list of the headers after the rewrite rules have been applied.
How can I change the from address in *nix mail globally?
1,382,410,950,000
I am on Debian squeeze and I'd like to forward my root emails to my real email. I setup exim to use gmail so when I write mail [email protected] it sends to my email. However, now I'd like to email root and have it forward my emails to my real email address. mail root does not send an email to root. If I create a different user and use the root email to that person it works. But that person or root emailing root does not. Did I break root emails? How do i fix this? I am using exim4, which was the default.
In order to forward root's e-mails to another e-mail address, you could change the line related to root in the file /etc/aliases. For instance: root: [email protected] To forward e-mails of a UNIX user (let say myuser) to another e-mail address ([email protected]), had the file .forward in the home folder of myuser. This file should contain one line with the e-mail to which you would like to forward the e-mails to. Regarding your problem with the command mail root, you should maybe have a look at the exim4 log files, located in /var/log/exim4. They may give you some clues about the problem.
How do I email root?
1,382,410,950,000
OS: GNU/Linux Debian 9.2 64-bit I disabled IPv6 on one of my servers. And now I'm getting this in mail: exim paniclog ... IPv6 socket creation failed: Address family not supported by protocol How do I get rid of it?
First of, man needs to disable IPv6 in exim4. In the following file: /etc/exim4/update-exim4.conf.conf Make sure this line is there, if not, add it, or change it: disable_ipv6='true' But I tried only this solution and the mail is still coming, so digging further... In the same file, make sure this line is set to true: dc_minimaldns='true' Now edit this file: /etc/hosts Let's suppose, this line defines your server name: 127.0.1.1 server-name Change it as follows: 127.0.1.1 server-name.localhost server-name Now, verify, that this command: hostname --fqdn Returns: server-name.localhost If so, you can update your Exim4 configuration: update-exim4.conf And restart the Exim4 service: systemctl restart exim4.service
IPv6 socket creation failed: Address family not supported by protocol
1,382,410,950,000
I have a machine hosted in datacenter with 3 network interfaces. Interface network ip address eth0 192.168.1.0/24 192.168.1.10 eth1 192.168.2.0/24 192.168.2.10 eth2 192.168.3.0/24 192.168.3.10 My default gateway is set to 192.168.2.1, where I can access some services provided by datacenter (repositories, ntp and so on). Network 192.168.1.0/24 has a gateway at 192.168.1.1 through which I can access outside world, where dragons live. When I need to go out of my server I simply add a static route. I kind of like this setting as I know where my server is connecting. Now, I have a mail client (exim4) which needs to send mails... to anyone. So ideally it needs to have a default gw set to 192.168.1.1. Is there a way to route only traffic for this particular service or should I simply change my network configuration on the server? I'm on debian 8 if that makes any difference.
You can set the firewall (iptables) to route to a specific gateway depending on one of 3 characteristics: destination port, source port or owner (may not work, see below) First you will add a custom routing table for your special application (gateway 192.168.1.1), create a rule that redirect all packages with the mask 1 to this table, and create a iptables rule that masque the source address in case the package was redirected: ip route add 192.168.1.0/24 dev eth0 table 1 ip route add 0/0 via 192.168.1.1 table 1 ip rule add fwmark 1 table 1 iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 192.168.1.10 For the package marking you have 3 options: Redirect by destination port, charging PORT with the server port used by exim: iptables -t mangle -A OUTPUT -p tcp --dport PORT -j MARK --set-mark 4 Redirect by source port, charging PORT with the port used locally by exim, if it does use only one source port: iptables -t mangle -A OUTPUT -p tcp --sport PORT -j MARK --set-mark 4 Redirect by Owner, changing OWNER with the PID from the Exim process (see iptables -m owner --help for other options): iptables -t mangle -A OUTPUT -m owner --pid-owner OWNER -j MARK --set-mark 4 Redirecting by Owner considerations www.frozentux.net: The pid, sid and command matching is broken in SMP kernels since they use different process lists for each processor. It might be fixed in the future however So depending on your kernel this feature is unavailable or broken (will not work properly)
Change default gateway for specific program?
1,382,410,950,000
I'm trying to create an exim filter to block spam messages containing " 85% OFF" in the subject line. That's a blank space, then any two digits, then the percent sign, a blank space and the word OFF in all caps. This is what I wrote: # Exim filter if $header_subject: contains " \\d{2}% OFF" then fail text "no spam please" seen finish endif However, that doesn't seem to work and lets matching messages through, although it passes the regex101 testing. What am I missing? What's the correct syntax?
I temporarily replaced my .forward file with yours and confirmed that it doesn't work. There are two problems. contains performs a substring match, and does not understand regular expressions. For regexes you want matches rather than contains. The \d PCRE-style character class appears to be broken as does the {N} syntax! I tried all kinds of combinations. The only syntax which worked was [0-9][0-9]. Even [0-9]{2} didn't work, and neither did [0-9]\\{2\\}, nor \\d\\d. (I'm running version 4.72.) Edit: Here is the reason: Quotes do not have to be used on regexes in Exim filter files, except when regexes contain whitspace. However, backslashes must be doubled up even in unquoted regexes. In quoted regexes, they must be doubled up again: $header_subject: matches "\\\\d{2}% OFF". Count `em: four backslashes. Test your script with /usr/sbin/exim -bF <scriptfile> -f <sender>. A test message must be supplied on standard input (e.g. redirected from a file). For testing Subject: processing, it can contain just that header line and nothing else. The capital F in -bF is to enable processing of your fail command which is disabled if you use -bf.
regex usage in exim filtering
1,382,410,950,000
I have a fresh Debian installation with LAMP. There is a PHP script that sends email messages to arbitrary addresses using the mail function, but it does not work - the messages don't get delivered. I have been searching the internet for quite a while and found out that there already is a SMTP server installed by default on Debian - the exim4 package. So I tried the following things so far. Launch the dpkg-reconfigure exim4-config command and choose the internet site; mail is sent and received directly using SMTP option. Follow the wizard and set the default options. Edit the /etc/php5/apache2/php.ini file and add the sendmail_path = /usr/sbin/sendmail -t line on the appropriate spot. None of those things have helped. When I try to send emails to my testing GMail address, it is not delivered, even though the address otherwise works fine. The following lines appear in my /var/log/exim4/mainlog file everytime I try to send an email. 2013-08-16 10:46:51 1VAFgI-0006FP-UU <= [email protected] U=www-data P=local S=423 2013-08-16 10:46:51 1VAFgI-0006FP-UU => [email protected] R=dnslookup T=remote_smtp H=aspmx.l.google.com [2a00:1450:4001:c02::1b] X=TLS1.2:RSA_ARCFOUR_SHA1:128 DN="C=US,ST=California,L=Mountain View,O=Google Inc,CN=mx.google.com" 2013-08-16 10:46:51 1VAFgI-0006FP-UU Completed
You need to configure exim4 to relay as a smarthost. There are a (lengthy) set of instructions here at the Debian wiki: GmailAndExim4, but it's really easy to get up and running. Your PHP sendmail_path is good to go.
PHP + Exim4 on Debian - mail does not get delivered
1,382,410,950,000
I am trying to substitute a hard-coded path in my Exim configuration file with a value taken from an environment variable, however I am getting an error I do not understand. "${env" is not a known operator (or a } is missing in a variable reference) This is the condition causing the error condition = ${if !exists{${env{MAILPATH}{$value} fail }/$local_part} } If I change the condition to this, then it works fine: condition = ${if !exists{/srv/mail/$local_part} } I cannot see the syntax error on the ${env line, so could someone please point out what silly mistake I have made?
After chasing this myself for some time, I found that the ${env operator only seems to have been added in the relatively recent exim4 version 4.86. Compare here (4.85) and here (4.86). Unfortunately the latest version of exim4 available on debian jessie was 4.84, causing me similar pain until I found this.
Exim condition failure "${env is not a known operator"
1,382,410,950,000
Using Exim - root user can send email from command line, but non root users can not. $ mail -s "test" [email protected] </dev/null Null message body; hope that's ok [xxx@master1 /usr/home/xxx]$ 2015-03-31 17:06:34 [58856] cwd=/usr/home/xxx 3 args: send-mail -i [email protected] Seeing this in /var/log/messages: Mar 31 17:07:11 master1 exim[59400]: 2015-03-31 17:07:11 [59400] 1Ycxl1-000FS4-0T failed to write to main log: length=134 result=-1 errno=9 (Bad file descriptor) Mar 31 17:07:11 master1 exim[59400]: write failed on panic log: length=125 result=-1 errno=9 (Bad file descriptor) Mar 31 17:07:11 master1 exim[59409]: 2015-03-31 17:07:11 [59409] 1Ycxl1-000FSD-1F failed to write to main log: length=134 result=-1 errno=9 (Bad file descriptor) Mar 31 17:07:11 master1 exim[59409]: write failed on panic log: length=125 result=-1 errno=9 (Bad file descriptor) exim is a symlink - both symlink and actual binary permissions look like: [xxx@master1 ~]$ ls -l `which exim` lrwsr-xr-x 1 root wheel 13 Aug 5 2013 /usr/local/sbin/exim -> exim-4.80.1-2 [xxx@master1 ~]$ ls -l /usr/local/sbin/exim-4.80.1-2 -rwsr-xr-x 1 root wheel 983184 Aug 5 2013 /usr/local/sbin/exim-4.80.1-2 Have tried adding user xxx as trusted_users in exim config - made no difference
Others have suggested to resolve this with chmod 4755 /usr/sbin/exim In this case both mail and mutt is invoking sendmail. Problem resolved with: chmod 4755 /usr/sbin/sendmail Now messages are sent successfully, and /var/log/exim/mainlog is written to and reflect as such.
non-root users unable to send mail from command line using exim
1,382,410,950,000
Managed to get my hands on this: #!/bin/bash ######### Edit here ########## [email protected] # Set this to your email id to receive alerts on mail queue _limit=100 # Set the limit here ############################## clear; _result="/tmp/eximqueue.txt" _queue="`exim -bpc`" if [ "$_queue" -ge "$_limit" ]; then echo "Current queue is: $_queue" > $_result echo "Summary of Mail queue" >> $_result echo "`exim -bp | exiqsumm`" >> $_result mail -s "Number of mails on `hostname` : $_queue" $_mail_user < $_result cat $_result fi rm -f $_result Works like a charm. Now I just have one question for someone slightly more advanced than me. Assuming the queue has exploded with spam, above message will just be in the back of the queue - so we would want to force it to be sent before anything else essentially. From my understanding, we can use the following to force delivery of one message: /usr/sbin/exim -M email-id Anyone here know how I could extract the email-id from the scripts mail function and then run the above command with it? Something along the lines of: _message_id = "'exiqgrep -f root@hostname'" /usr/sbin/exim -M "$_message_id"
Try exiqgrep -f 'root@hostname' -i | xargs exim -M You can also look at more powerful tool exipick.
Bash script to extract message id and force send
1,382,410,950,000
Last week my email provider (mout.web.de) got listed on spamcop. So I cannot send emails to recipients whose mailserver uses spamcop. An obvious solotion, which popped up in the forums, is to switch to another (paid) email provider. Since I have a local mailserver (exim) running anyways, I wonder whether I can set it up in way so it delivers mail directly rather than sending it to a smarthost, as it does now. If spamcop then detects spam originating from my IP, I am willing to take the blame. However I do not own my own domain (just a dynamic dns listing) and I am worried that this could be a showstopper. I also vaguely recall, that years ago a friend of mine tried to deliver mails directly and ran into problems, beause some mailservers would refuse to accept mail from him (the exact details slipped my memory). So Is running my own mailserver (without smarthost) a vital alternative to switching to a different email provider? Will I have to register my own domain? Are there any other showstoppers? Is there anything an email provider can do, which I cannot do on my linux box?
In general this is possible, that's what email providers do. You surely need your own domain. Many ISPs have blocks in place so you're forced to go over your ISPs server. Even if your ISP does not block port 25, mail from your IP range will very likely be marked as spam if you run it from a home connection. Email is a complicated and critical piece of the infrastructure which takes some effort to secure. Furthermore, you will have to put additional effort into making it reliable (redundancy, failover, etc.) Conclusion Although it's possible to set it up on your own, renting a server in a data centre or paying an email provider if you want a reliable operating mail setup without a high risk of being marked as spammer is often the better solution.
Is it possible to run a private mailserver?
1,382,410,950,000
To catch mail send to any recipient I have added the following router directive in my exim4 configuration: local_catchall: debug_print = "R: catchall for $local_part@$domain" driver = redirect domains = +local_domains allow_fail allow_defer data = johanna How can I exclude some recipient addresses like it is possible with sender addresses per: acl_check_data: strong textdeny senders = /etc/deny_senders
Use the condition router option and a single-key query like condition = ${lookup {$local_part@$domain} lsearch {/etc/deny_recips} {0} {1}} You could use the acl_smtp_rcpt instead, but note that it's for SMTP input only, extend if necessary: deny recipients = /etc/deny_recips
Exim4: How to block a list of recipient addresses
1,382,410,950,000
I'm trying to forward the emails from my Debian server to my usual email address. I'm probably missing something important, as I can't find a good solution online looking for the following error message: dnslookup defer (-1): host lookup did not complete I found this answer but it did not help me: https://serverfault.com/questions/370489/exim-cannot-send-to-remote-mail-servers I have a user Debian-exim: uid=101(Debian-exim) gid=103(Debian-exim) groups=103(Debian-exim) I don't think that port 25 is filtered on my network. Anyway, I think that it is a DNS issue for now. I am not sure if the following server here is still working and can't find another address to test with: telnet 209.85.225.27 25 Trying 209.85.225.27... telnet: Unable to connect to remote host: Connection timed out This works: echo "This is a test." | mail -s Testing user@localhost This does not: echo "This is a test." | mail -s Testing [email protected] echo "This is a test." | mail -s Testing [email protected] In /var/log/exim4/mainlog I got: 1YDDm0-0007mZ-BS <= [email protected] U=user P=local S=464 1YDDm0-0007mZ-BS == [email protected] R=dnslookup defer (-1): host lookup did not complete 1YDE1X-0007v5-EG <= [email protected] U=user P=local S=456 And in /etc/resolv.conf: domain home search home nameserver 192.168.1.1 And finally (The interesting part seems to be at the very end): sudo exim -bt -d-resolver [email protected] [sudo] password for user: Exim version 4.80 uid=0 gid=0 pid=31872 D=fbb95cfd Berkeley DB: Berkeley DB 5.1.29: (October 25, 2011) Support for: crypteq iconv() IPv6 GnuTLS move_frozen_messages DKIM Lookups (built-in): lsearch wildlsearch nwildlsearch iplsearch cdb dbm dbmjz dbmnz dnsdb dsearch nis nis0 passwd Authenticators: cram_md5 plaintext Routers: accept dnslookup ipliteral manualroute queryprogram redirect Transports: appendfile/maildir/mailstore autoreply lmtp pipe smtp Fixed never_users: 0 Size of off_t: 8 Compiler: GCC [4.6.3] Library version: GnuTLS: Compile: 2.12.20 Runtime: 2.12.20 Library version: PCRE: Compile: 8.30 Runtime: 8.30 2012-02-04 Total 13 lookups WHITELIST_D_MACROS: "OUTGOING" TRUSTED_CONFIG_LIST: "/etc/exim4/trusted_configs" changed uid/gid: forcing real = effective uid=0 gid=0 pid=31872 auxiliary group list: <none> seeking password data for user "uucp": cache not available getpwnam() succeeded uid=10 gid=10 changed uid/gid: calling tls_validate_require_cipher uid=101 gid=103 pid=31873 auxiliary group list: <none> tls_validate_require_cipher child 31873 ended: status=0x0 configuration file is /var/lib/exim4/config.autogenerated log selectors = 00000ffc 00612001 trusted user admin user seeking password data for user "mail": cache not available getpwnam() succeeded uid=8 gid=8 user name "root" extracted from gecos field "root" originator: uid=0 gid=0 login=root name=root sender address = [email protected] Address testing: uid=0 gid=103 euid=0 egid=103 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Testing [email protected] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Considering [email protected] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> routing [email protected] --------> hubbed_hosts router <-------- local_part=my domain=mail.eu checking domains expansion of "${if exists{/etc/exim4/hubbed_hosts}{partial-lsearch;/etc/exim4/hubbed_hosts}fail}" forced failure: assume not in this list hubbed_hosts router skipped: domains mismatch --------> dnslookup_relay_to_domains router <-------- local_part=my domain=mail.eu checking domains mail.eu in "@:localhost:example.dynu.com"? no (end of list) mail.eu in "empty"? no (end of list) mail.eu in "! +local_domains : +relay_to_domains"? no (end of list) dnslookup_relay_to_domains router skipped: domains mismatch --------> dnslookup router <-------- local_part=my domain=mail.eu checking domains cached no match for +local_domains cached lookup data = NULL mail.eu in "! +local_domains"? yes (end of list) R: dnslookup for [email protected] calling dnslookup router dnslookup router called for [email protected] domain = mail.eu DNS lookup of mail.eu (MX) gave TRY_AGAIN mail.eu in dns_again_means_nonexist? no (option unset) returning DNS_AGAIN dnslookup router: defer for [email protected] message: host lookup did not complete [email protected] cannot be resolved at this time: host lookup did not complete search_tidyup called >>>>>>>>>>>>>>>> Exim pid=31872 terminating with rc=1 >>>>>>>>>>>>>>>> Could someone help me out here? Thanks a lot!
The standard dnslookup router of exim uses an algorithm to decide how to resolve an email address (this is detailed in the Exim manual on the chapter detailing dnslookup router). Looking at the results from dig, this seems fine: $ dig mail.eu mx ; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> mail.eu mx ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5467 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 4 ;; QUESTION SECTION: ;mail.eu. IN MX ;; ANSWER SECTION: mail.eu. 86400 IN MX 10 in1-smtp.messagingengine.com. mail.eu. 86400 IN MX 20 in2-smtp.messagingengine.com. ;; ADDITIONAL SECTION: in1-smtp.messagingengine.com. 72474 IN A 66.111.4.70 in1-smtp.messagingengine.com. 72474 IN A 66.111.4.73 in1-smtp.messagingengine.com. 72474 IN A 66.111.4.72 in1-smtp.messagingengine.com. 72474 IN A 66.111.4.71 ;; Query time: 33 msec ;; SERVER: 192.168.0.1#53(192.168.0.1) ;; WHEN: Mon Jan 19 16:51:24 2015 ;; MSG SIZE rcvd: 158 This means that your local resolver (192.168.1.1) is either returning a TRY_AGAIN response for the SRV request (have you got SRV enabled in your exim configuration) OR has "negatively cached" a failed result (was your DSL down at the time it happened?). I would suggest testing around your resolver by using an open DNS server (such as Google's), by adding: nameserver 8.8.8.8 before your nameserver 192.168.1.1 statement in your resolv.conf and then try running you exim -bt [email protected] test again to rule out this resolvers response. If using Google's DNS cache server solves the issue, then a restart of your DNS resolver (the device at 192.168.1.1) to see if that solves the ongoing issue (don't forget to comment out the Google cache entry before re-testing!) There are other options detailed in that chapter if you continue to get errors even when using Google's DNS cache servers (or if you prefer NOT to use an external DNS resolver). Note that by adding the nameserver line all DNS lookups will be passed to Google for resolving. This will add a small delay to DNS requests as well as passing on all DNS requests your host will make to Google - not everyone's idea of a "Good Thing"™.
Exim4 DNS issues
1,382,410,950,000
I am using /etc/aliases to direct group emails to multiple accounts, for example: postmaster: john abuse: john www: paul team: john, paul, ringo, george One of the lines is getting quite long due to the number of users it forwards to. Is it possible to wrap the line? I am using Exim as the MTA.
Edit: My original answer was that it is not possible, but after a very helpful comment from @Freddy it might work: Doing a quick test on a Debian 11 system: ~# cat /etc/aliases testgroup: test1, test2, test3 ~# newaliases ~# sendmail testgroup testmail4 ^d ~# su test3 ~$ mail "/var/mail/test3": 2 messages 2 new >N 1 root Wed Feb 1 13:22 12/421 N 2 root Wed Feb 1 13:25 12/421 ? 2 Return-path: <root@4d79c2bfcbb5> Envelope-to: testgroup@4d79c2bfcbb5 Delivery-date: Wed, 01 Feb 2023 13:25:05 +0000 Received: from root by 4d79c2bfcbb5 with local (Exim 4.94.2) (envelope-from <root@4d79c2bfcbb5>) id 1pND6m-0000xM-2Y for testgroup@4d79c2bfcbb5; Wed, 01 Feb 2023 13:25:04 +0000 Message-Id: <E1pND6m-0000xM-2Y@4d79c2bfcbb5> From: root <root@4d79c2bfcbb5> Date: Wed, 01 Feb 2023 13:25:04 +0000 testmail4 ? So it is possible to wrap the line, but the line should start with a white space. (A tab worked also for me)
Can lines be wrapped in /etc/aliases?
1,382,410,950,000
I'm using Debian stretch (9.4). I have an office365 account. Using Evolution, I can successfully download mail via POP3, and also send mail using the Evolution "Sending E-mail" preferences: Server: smtp.office365.com Port: 587 Server requires authentication TICKED Encryption method: STARTTLS after connecting Authentication: Login Username: <myid@mydomain> and Evolution prompted me for my office365 password the first time I used it, and it's been fine since. So that's great. However: I also have some crontab scripts which occasionally send email programmatically via sendmail -t as described here. The exim4-config package was configured for "mail sent by smarthost; no local mail" and the outgoing smarthost to smtp.office365.com::587. I also have /etc/exim4/passwd.client containing a smtp.office365.com:<myid@mydomain>:<mypassword> line. Until around a month ago (I think they stopped working sometime in the first week of June), those scripts were sending email via smtp.office365.com absolutely fine. However, since then, for each email attempted to be sent /var/log/exim4/mainlog now shows a bunch of error messages along the lines of: 2018-06-12 22:04:37 XXXXXX-XXXXXX-XX <= <> R=XXXXXX-XXXXXX-XX U=Debian-exim P=local S=2270 2018-06-12 22:04:42 XXXXXX-XXXXXX-XX H=outlook.ms-acdc.office.com [40.100.174.194] TLS error on connection (recv): The TLS connection was non-properly terminated. 2018-06-12 22:04:42 XXXXXX-XXXXXX-XX H=outlook.ms-acdc.office.com [40.100.174.194] TLS error on connection (send): The specified session has been invalidated for some reason. 2018-06-12 22:04:42 XXXXXX-XXXXXX-XX ** <myid@mydomain> R=hub_user_smarthost T=remote_smtp_smarthost H=outlook.ms-acdc.office.com [40.100.174.194] X=TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256 CV=no DN="C=US,ST=Washington,L=Redmond,O=Microsoft Corporation,CN=outlook.com": SMTP error from remote mail server after pipelined MAIL FROM:<> SIZE=3347: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [LO2P265CA0067.GBRP265.PROD.OUTLOOK.COM] 2018-06-12 22:04:42 XXXXXX-XXXXXX-XX Frozen (delivery error message) It's not clear to me whether something has changed at microsoft's end or my end (my machine is vanilla Debian stable amd64; I can't remember if there were any relevant security updates might have been applied around the time things stopped working). I suspect Microsoft might have tightened up authentication in some way, and I need to change something in the exim4 configuration to deal with it (I'll reiterate that Evolution has been sending mail through the same smtp.office365.com:587 channel without issue the whole time). I'm puzzled and grateful for any suggestions how to get the sendmail -t method working again.
I have restored my system's sendmail -t functionality: Studying the section for /etc/exim4/passwd.client in man exim4_passwd_client led me to realize that just because my outgoing mail is sent via smtp.office365.com, listing that DNS name in passwd.client may not actually be sufficient... there's some reverse DNS lookup involved in the process. Doing ping smtp.office365.com actually gets responses from something called outlook.ms-acdc.office.com. So I updated my /etc/exim4/passwd.client file to contain a line *.office.com:<myid@mydomain>:<mypassword> and now everything is working again. (I note previously I did actually also have a line *.office365.com in the passwd.client file; my guess is that in early June something changed in MS' setup affecting whether exim4 thought it was connecting to an SMTP server under the office365.com or office.com domains). Of course the question now is how long it'll be until Microsoft decide on yet another rebrand of the service formerly known as Hotmail and all the DNS names change again :^) Update 2021-06-10: Over the last week, my sendmail using scripts seem to have become unreliable (not a complete failure; sometimes something gets through anyway). ping smtp.office365.com now gets responses from lhr-mvp.trafficmanager.net; adding a *.trafficmanager.net:<myid@mydomain>:<mypassword> line to the /etc/exim4/passwd.client file seems to have fixed the issue, I think. Apparently trafficmanager.net is part of Azure infrastructure; I guess Microsoft are migrating to that. Script-sent emails which worked may have been sent at times when the new configuration was rolled back for some reason.
How do I correctly configure exim4 on Debian so I can use `sendmail -t` to send mail via my office365 account?
1,382,410,950,000
On my development machine, I have a special kind of SMTP server running on non-standard port which is used for testing purposes. On my virtual machine I'm trying to push a message to that SMTP server by using Exim4's sendmail app: selenium-node$ sendmail -t To: [email protected]:2525 From: [email protected] Subject: Test message Quick brown fox jumps over the lazy dog selenium-node$ However, it looks that default SMTP server on my-development-machine.testingnetwork.local:25 receives my message instead. Is there a clean and natural way to do what I'm trying for? Modifying some configs on my-selenium-node.testingnetwork.local is no problem.
SMTP always goes to TCP/25 unless the mail delivery agent (here, sendmail as implemented by Exim) is specifically configured to send the mail to some custom port. There is no means to set the port like there is in URL from the mail user agent that talks to the mail delivery agent. Options thus are limited to reconfiguring Exim to send to a different port or to use some other mail sending program to direct the mail elsewhere, such as ssmtp with configuration in ssmtp.conf along the lines of mailhub=my-development-machine.testingnetwork.local:2525 and then piping the message to ssmtp. Another option would be to use a SMTP client module in some programming language; these may support sending to arbitrary TCP ports.
Dealing with non-standard SMTP ports with sendmail -t
1,382,410,950,000
I am trying to configure Exim to reject any $local_part that match a pattern. For example, I know that none of the local_parts for any of the myriad of domains I host will ever contains numbers. So, I know if someone send an email to [email protected], I know it is spam and can safely reject it. What would be the best ACL for this?
ACL line could be the next: deny condition = ${lookup{$localpart}nwildlsearch{/path/to/the/black.list}{yes}{no}} While black.list contains PCRE regexes one per line like that: ^.*[0-9].* ^.*[!@#$%^&*()_+].* ^.*sales.*
exim reject all local_part matching a pattern
1,382,410,950,000
My domain getting lot of spam mail like [email protected], [email protected]. We don't have such user's but we getting mails like that.Also getting lot of bounce mails, How to control spam like this in exim mail server.
If you use postmaster option require verify = recipient This statement requires the recipient address to be verified; if verification fails, the address is rejected. See Default Configuration You can also set some good acl rules to delay or block the host which sends the spam: deny message = Max $rcpt_fail_count failed recipients allowed condition = ${if >{$rcpt_fail_count}{10} {1}} ! verify = recipient delay = ${eval: $rcpt_fail_count * 10}s log_message = $rcpt_fail_count failed recipient attempts See FAQ
Incoming Spam Mail in exim mail server
1,382,410,950,000
I have had a few problem with exim4 and various phone mail clients (Windows Phone in particular) that seem to result from bad mail clients together with GnuTLS. I'd like to recompile exim4-daemon-heavy to use OpenSSL to see if that helps anything. Now, I've gotten used to debian's packaging system and am unsure on how to do this. I've downloaded the exim4 source using apt-get source exim4. I then edited the file Debian/rules to uncomment OpenSSL = 1. Then I tried make, but was told that I need to copy the template src/EDITME to Local/Makefile and edit it to my taste. My taste would be a drop-in replacement for the existing and running exim4-daemon-heavy, just using OpenSSL. And here I am stumped as there are quite a lot of options there and I don't like to break my email setup more than neccessary. So... what can I do to make this test?
Although the answer is in my comment/duplicate, lets do a summary of the commands you need for: Building exim4-daemon-heavy in Debian-like distros mkdir exim4 && cd exim4 apt-get source exim4 sudo apt-get build-dep exim4 cd exim4-4.82 ### This could be different for you ##Modify your option here in the `debian/rules` file ~/src/exim4/exim4-4.82$ dpkg-buildpackage -rfakeroot -us -uc This will give you the .deb files in the parent folder. The build-dep action to apt-get installs the BUILD DEPendencies for the given package.
How to recompile exim4-daemon-heavy? [duplicate]
1,382,410,950,000
I have just installed Debian Squeeze x64 and tried sending myself a test email from it using the normal "mail" command. When I sent it I got this error from Exim: 2013-06-08 08:12:46 Exim configuration error in line 173 of /var/lib/exim4/config.autogenerated: user uucp was not found Can't send mail: sendmail process failed with error code 1 After a bit of research into this it sounds like all Debian systems should have the "uucp" user, but can I just run "useradd uucp" or does it need setting up to own certain directories and stuff?
On my Ubuntu system I have a user uucp and it must have been created early because of its usernumber. grep uucp /etc/passwd gives: uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh and /var/spool/uucp does not exist. grep uucp /etc/group gives: uucp:x:10: and grep uucp /etc/shadow gives: uucp:*:15426:0:99999:7::: So you should try to create a new user with: adduser --system --home /var/spool/uucp --no-create-home --shell /bin/sh --group uucp This will give you a user with a 'low' uid, where useradd uucp would not.
Debian installation has no uucp user - how to create
1,382,410,950,000
I have a Debian Jessie (Version 8.1) server that serves multiple domain names. Each has their own folder configured under /var/www/. Each domain name has a unique conf (example.com.conf) file under /etc/apache2/sites-enabled which is linked to a matching conf file under /etc/apache2/sites-available. Each conf file has: <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/example_com_dir ServerName example.com ServerAlias *.example.com </VirtualHost> I wanted to be able to accept all emails sent to each of the domains (any email sent to any [email protected]) and forward it to my Gmail. I successfully installed EXIM4 on it, and configured using dpkg-reconfigure exim4-config as follows: mail sent by smarthost; no local mail System mail name: myDomainName.TLD IP-addresses to listen on for incoming SMTP connections: 127.0.0.1 ; ::1 Other destinations for which mail is accepted: <BLANK> Visible domain name for local users: <BLANK> IP address or host name of the outgoing smarthost: smtp.gmail.com::587 Keep number of DNS-queries minimal (Dial-on-Demand)? No Split configuration into small files? No Root and postmaster mail recipient: <BLANK> Then I completed all the other steps in this tutorial: https://www.vultr.com/docs/setup-exim-to-send-email-using-gmail-in-debian. Inside /etc/hosts I have: 127.0.0.1 localhost 127.0.1.1 install.install install # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters Inside /etc/hostname I have one line: example.com Inside /etc/email-addresses I have: root: [email protected] info: [email protected] *: [email protected] When I run echo 'Test Message.' | mail -s 'Test Message' [email protected] I do get an email in my Gmail. Also, if a run any script from cron.d and it outputs any prints, I do get those as email notifications. So I know outgoing emails work. But when I send an email from [email protected] to [email protected] I do not get any notification in [email protected]. Question #1: I want to be able to get all incoming emails and forward them to somewhere else. For example, I want to send from [email protected] to my domain [email protected] and have the server send it to [email protected]. What do I have to configure in order to do so? How can that be configured for a server serving multiple domains? Question #2: I know it might be opinion based, but what are some of the free, user friendly, with web GUI access email servers that I can configure on Debian Jessie (8.1)?
Reconfigure your config by running # dpkg-reconfigure exim4-config General type of mail configuration: internet site Other destinations for which mail is accepted: example.com IP-addresses to listen on for incoming SMTP connections: fill in your IP address Those should be the most important items to change. Remove any smarthost if it's still asked. Now it should accept incoming SMTP connections (if you entered the IP address correctly), and send email on via the aliases you're already created.
How to configure EXIM4 to relay emails?
1,382,410,950,000
I recently installed a new SSL certificate and then also decided to tighten security a bit by make the private key less readable. This caused a problem with exim. The certificate is now 640 with user root and group ssl. The user Debian-exim is in this group. I can access the private key file just fine from the shell: #sudo -u Debian-exim cat key -----BEGIN RSA PRIVATE KEY----- ... -----END RSA PRIVATE KEY----- However, the log file of exim says otherwise: 2012-04-21 00:00:00 <Message-id> unable to open private key file for reading: /.../key 2012-04-21 00:00:00 <Message-id> == some@email <some@email> R=dnslookup T=remote_smtp defer (-1): smtp transport process returned non-zero status 0x0100: exit code 1 2012-04-21 00:00:00 <Message-id> Frozen Using auditd I checked the filesystem access: time->Sat Apr 21 00:00:00 2012 type=PATH msg=audit(1335027881.290:6): item=0 name="/.../key" inode=1794200 dev=09:01 mode=0100640 ouid=0 ogid=105 rdev=00:00 type=CWD msg=audit(1335027881.290:6): cwd="/var/spool/exim4" type=SYSCALL msg=audit(1335027881.290:6): arch=c000003e syscall=2 success=no exit=-13 a0=16184f8 a1=0 a2=0 a3=0 items=1 ppid=11831 pid=11847 auid=4294967295 uid=100 gid=102 euid=100 suid=100 fsuid=100 egid=102 sgid=102 fsgid=102 tty=pts1 ses=4294967295 comm="exim4" exe="/usr/sbin/exim4" key="sslkey" Which shows that it indeed fails (though I don't know why). In comparison an as-identical-as-possible successfull calle (file group is changed to Debian-exim as opposed to ssl) time->Sat Apr 21 00:00:00 2012 type=PATH msg=audit(1335028586.882:34): item=0 name="/.../key" inode=1794200 dev=09:01 mode=0100640 ouid=0 ogid=102 rdev=00:00 type=CWD msg=audit(1335028586.882:34): cwd="/var/spool/exim4" type=SYSCALL msg=audit(1335028586.882:34): arch=c000003e syscall=2 success=yes exit=11 a0=24f74f8 a1=0 a2=0 a3=0 items=1 ppid=13958 pid=13961 auid=4294967295 uid=100 gid=102 euid=100 suid=100 fsuid=100 egid=102 sgid=102 fsgid=102 tty=(none) ses=4294967295 comm="exim4" exe="/usr/sbin/exim4" key="sslkey" I have no idea what goes wrong. Why can the exim daemon access the "key" file when the file group is Debian-exim (primary group of Debian-exim user) but not when the file group is ssl (a secondary group of Debian-exim user)?
The groups that a user is in are granted by the login process. When a daemon switches to a user and group after launch, it typically only switches to this user and group (with setgid followed by setuid), and doesn't take on any other group implied by /etc/passwd (primary group) and /etc/group (supplementary group). I haven't checked that exim behaves this way, but if it doesn't, it's unusual. You can check what groups the exim process is running as by running grep '^Groups:' /proc/1234/status where 1234 is the PID of an exim process. You need to make the key file readable by either the Debian-exim user or the Debian-exim group. Make sure ACLs are turned on, then add Debian-exim to the ACL of the key file and any non-public directory leading to it: setfacl -m group:Debian-exim:r /path/to/key setfacl -m group:Debian-exim:x /path/to
Daemon file access denied while it shouldn't