If you need to check which version of the GNU C library (glibc) is used on you Linux system, whether it’s to check whether you are affected by the GHOST vulnerability or you need to install a software requiring at least a certain version but not checking it on build/installation, the easiest way is to use ldd which comes with glibc and should in most cases have the same version:
> ldd --version
ldd (GNU libc) 2.11.1
If you know you might have patched the system to use a different version of ldd and know that its version doesn’t match the glibc version, you have two additional ways to find out the glibc version:
- Check the version of the installed glibc rpm package
- Check the version of the used libc.so file
First using rpm:
> rpm -q glibc
glibc-2.11.1-0.17.4
The second way is a little bit more difficult. You first have to find which libc.so file is being used by a known program e.g. netstat:
> ldd `which netstat`
linux-vdso.so.1 => (0x00007ffff7ffb000)
libc.so.6 => /lib64/libc.so.6 (0x00007ffff7a80000)
/lib64/ld-linux-x86-64.so.2 (0x00007ffff7dde000)
You can also find the libc.so file used with the following command:
> cat `gcc -print-file-name=libc.so`
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
So we now know that /lib64/libc.so.6 is being used and we just need to get it’s version:
> /lib64/libc.so.6 --version
GNU C Library stable release version 2.11.1 (20100118), by Roland McGrath et al.
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Configured for x86_64-suse-linux.
Compiled by GNU CC version 4.3.4 [gcc-4_3-branch revision 152973].
Compiled on a Linux 2.6.32 system on 2010-05-06.
Available extensions:
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
Native POSIX Threads Library by Ulrich Drepper et al
BIND-8.2.3-T5B
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
If you want to determine the glibc version from C program and not from a shell script, you can just use something like this:
#include <stdio.h>
#include <stdlib.h>
#include <gnu/libc-version.h>
int main(int argc, char *argv[]) {
printf("glibc version: %s\n", gnu_get_libc_version());
}
You can then compile it and execute it like this to get the glibc version:
> gcc glibc_version.c -o glibc_version
> ./glibc_version
glibc version: 2.11.1
Of course, if your C file is not called glibc_version.c, you’ll have to use the name you’ve actually used in the gcc arguments.
Since your current shell is probably also using glibc, you can also find out which libc library it has loaded by using the following command:
> lsof -p $$ | grep libc
bash 9177 root mem REG 8,2 1661454 827401 /lib64/libc-2.11.1.so
Of course there may be systems where the file name itself doesn’t give you the glibc version but just as shown above with /lib64/libc.so.6 you can call the so file with the –version to get its version information e.g.:
lsof -p $$ | grep libc | awk ' { print $NF" --version"; } ' | sh
GNU C Library stable release version 2.11.1 (20100118), by Roland McGrath et al.
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Configured for x86_64-suse-linux.
Compiled by GNU CC version 4.3.4 [gcc-4_3-branch revision 152973].
Compiled on a Linux 2.6.32 system on 2010-05-06.
Available extensions:
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
Native POSIX Threads Library by Ulrich Drepper et al
BIND-8.2.3-T5B
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.