Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All changes to fakechroot we carry in Debian for glibc >= 2.37 #104

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ ACX_CHECK_C_ATTRIBUTE_VISIBILITY
# Checks for libraries.
AC_CHECK_LIB([dl], [dlsym])

AH_TEMPLATE([NEW_GLIBC], [glibc >= 2.33])
AC_MSG_CHECKING([for glibc 2.33+])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/stat.h>
]], [[
#ifdef __GLIBC__
#if !__GLIBC_PREREQ(2,33)
#error glibc<2.33
#endif
#else
#error not glibc
#endif
]])],[
AC_DEFINE(NEW_GLIBC,1)
AC_MSG_RESULT([yes])
],[
AC_DEFINE(NEW_GLIBC,0)
AC_MSG_RESULT([no])
])

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
Expand Down Expand Up @@ -138,11 +158,14 @@ ACX_CHECK_FTS_NAME_TYPE
# Checks for library functions.
AC_CHECK_FUNCS(m4_normalize([
__chk_fail
__fstatat64_time64
__fxstat64
__fxstatat
__fxstatat64
__getcwd_chk
__getwd_chk
__lstat64_time64
__lutimes64
__lxstat
__lxstat64
__open
Expand All @@ -155,7 +178,11 @@ AC_CHECK_FUNCS(m4_normalize([
__realpath_chk
__readlink_chk
__readlinkat_chk
__stat64_time64
__statfs
__utime64
__utimensat64
__utimes64
__xmknod
__xmknodat
__xstat
Expand Down Expand Up @@ -198,6 +225,8 @@ AC_CHECK_FUNCS(m4_normalize([
freopen64
fstat
fstat64
fstatat
fstatat64
fts_children
fts_open
fts_read
Expand Down
33 changes: 33 additions & 0 deletions scripts/ldd.fakechroot.pl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,38 @@ sub objdump {
}
}

# mips64el, ppc64el and s390x do not list the linker itself
# if it's missing, obtain it from the .interp section
#
# mips64el: /lib64/ld.so.1
# ppc64el: /lib64/ld64.so.2
# s390x: /lib/ld64.so.1
sub elfinterp {
my $file = shift;
my $res = '';
local *PIPE;
open PIPE, "objdump -sj .interp '$file' 2>/dev/null |";
while (my $line = <PIPE>) {
if ( $line !~ /^ [a-f0-9]+ ([a-f0-9][a-f0-9][a-f0-9 ]{6} [a-f0-9 ]{8} [a-f0-9 ]{8} [a-f0-9 ]{8}) /) {
next;
}
$line = $1;
$line =~ s/ //g;
$line =~ s/(..)/chr(hex($1))/eg;
$res .= $line;
}
close PIPE;

# remove trailing NUL byte
$res =~ s/\000$//;

# only add if it is missing
if ( $res && !exists $Libs{$res} ) {
push @Libs, $res;
$Libs{$res} = '';
}
}


sub load_ldsoconf {
my ($file) = @_;
Expand Down Expand Up @@ -191,6 +223,7 @@ sub load_ldsoconf {
}

objdump($file);
elfinterp($file_in_chroot);

if ($Dynamic == 0) {
print "\tnot a dynamic executable\n";
Expand Down
10 changes: 10 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
pkglib_LTLIBRARIES = libfakechroot.la
libfakechroot_la_SOURCES = \
__fstatat64_time64.c \
__fxstatat.c \
__fxstatat64.c \
__getcwd_chk.c \
__getwd_chk.c \
__lstat64_time64.c \
__lutimes64.c \
__lxstat.c \
__lxstat64.c \
__lxstat64.h \
Expand All @@ -18,7 +21,11 @@ libfakechroot_la_SOURCES = \
__readlinkat_chk.c \
__realpath_chk.c \
__realpath_chk.h \
__stat64_time64.c \
__statfs.c \
__utime64.c \
__utimensat64.c \
__utimes64.c \
__xmknod.c \
__xmknodat.c \
__xstat.c \
Expand Down Expand Up @@ -61,6 +68,8 @@ libfakechroot_la_SOURCES = \
fopen64.c \
freopen.c \
freopen64.c \
fstatat.c \
fstatat64.c \
fts.c \
fts64.c \
ftw.c \
Expand Down Expand Up @@ -118,6 +127,7 @@ libfakechroot_la_SOURCES = \
openat64.c \
opendir.c \
opendir.h \
passwd.c \
pathconf.c \
popen.c \
posix_spawn.c \
Expand Down
44 changes: 44 additions & 0 deletions src/__fstatat64_time64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
libfakechroot -- fake chroot environment
Copyright (c) 2010, 2021 Piotr Roszatycki <dexter@debian.org>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


#include <config.h>

#ifdef HAVE___FSTATAT64_TIME64

#define _ATFILE_SOURCE
#define _POSIX_C_SOURCE 200809L
#include <sys/stat.h>
#include <limits.h>
#include "libfakechroot.h"

struct __stat64_t64;

wrapper(__fstatat64_time64, int, (int dirfd, const char *pathname, struct __stat64_t64 *buf, int flags))
{
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
debug("__fstatat64_time64(%d, \"%s\", &buf, %d)", dirfd, pathname, flags);
expand_chroot_path_at(dirfd, pathname);
return nextcall(__fstatat64_time64)(dirfd, pathname, buf, flags);
}

#else
typedef int empty_translation_unit;
#endif
49 changes: 49 additions & 0 deletions src/__lstat64_time64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
libfakechroot -- fake chroot environment
Copyright (c) 2010, 2021 Piotr Roszatycki <dexter@debian.org>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


#include <config.h>

#ifdef HAVE___LSTAT64_TIME64

#define _ATFILE_SOURCE
#define _POSIX_C_SOURCE 200809L
#include <sys/stat.h>
#include <limits.h>
#include "libfakechroot.h"

struct __stat64_t64;

wrapper(__lstat64_time64, int, (const char *filename, struct __stat64_t64 *buf))
{
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
char resolved[FAKECHROOT_PATH_MAX];
debug("__lstat64_time64(\"%s\", &buf)", filename);
if (rel2abs(filename, resolved) == NULL) {
return -1;
}
filename = resolved;
expand_chroot_path(filename);
return nextcall(__lstat64_time64)(filename, buf);
}

#else
typedef int empty_translation_unit;
#endif
42 changes: 42 additions & 0 deletions src/__lutimes64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
libfakechroot -- fake chroot environment
Copyright (c) 2010, 2013 Piotr Roszatycki <dexter@debian.org>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


#include <config.h>

#ifdef HAVE___LUTIMES64

#define _ATFILE_SOURCE
#define _POSIX_C_SOURCE 200809L

#include <sys/time.h>
#include "libfakechroot.h"

wrapper(__lutimes64, int, (const char * filename, UTIMES_TYPE_ARG2(tv)))
{
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
debug("__lutimes64(\"%s\", &tv)", filename);
expand_chroot_path(filename);
return nextcall(__lutimes64)(filename, tv);
}

#else
typedef int empty_translation_unit;
#endif
8 changes: 7 additions & 1 deletion src/__readlink_chk.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define _FORTIFY_SOURCE 2
#include <stddef.h>
#include <unistd.h>
#include <stdio.h>
#include "libfakechroot.h"


Expand All @@ -41,7 +42,12 @@ wrapper(__readlink_chk, ssize_t, (const char * path, char * buf, size_t bufsiz,
debug("__readlink_chk(\"%s\", &buf, %zd, %zd)", path, bufsiz, buflen);
expand_chroot_path(path);

if ((linksize = nextcall(__readlink_chk)(path, tmp, FAKECHROOT_PATH_MAX-1, buflen)) == -1) {
if (__builtin_expect(!!(bufsiz > buflen), 0)) {
printf("readlink: prevented write past end of buffer\n");
exit(-1);
}

if ((linksize = nextcall(__readlink_chk)(path, tmp, FAKECHROOT_PATH_MAX-1, FAKECHROOT_PATH_MAX-1)) == -1) {
return -1;
}
tmp[linksize] = '\0';
Expand Down
8 changes: 7 additions & 1 deletion src/__readlinkat_chk.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define _FORTIFY_SOURCE 2
#include <stddef.h>
#include <unistd.h>
#include <stdio.h>
#include "libfakechroot.h"


Expand All @@ -42,7 +43,12 @@ wrapper(__readlinkat_chk, ssize_t, (int dirfd, const char * path, char * buf, si
debug("__readlinkat_chk(%d, \"%s\", &buf, %zd, %zd)", dirfd, path, bufsiz, buflen);
expand_chroot_path_at(dirfd, path);

if ((linksize = nextcall(__readlinkat_chk)(dirfd, path, tmp, FAKECHROOT_PATH_MAX-1, buflen)) == -1) {
if (__builtin_expect(!!(bufsiz > buflen), 0)) {
printf("readlinkat: prevented write past end of buffer\n");
exit(-1);
}

if ((linksize = nextcall(__readlinkat_chk)(dirfd, path, tmp, FAKECHROOT_PATH_MAX-1, FAKECHROOT_PATH_MAX-1)) == -1) {
return -1;
}
tmp[linksize] = '\0';
Expand Down
47 changes: 47 additions & 0 deletions src/__stat64_time64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
libfakechroot -- fake chroot environment
Copyright (c) 2010-2015 Piotr Roszatycki <dexter@debian.org>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


#include <config.h>

#ifdef HAVE___STAT64_TIME64

#define _BSD_SOURCE
#define _LARGEFILE64_SOURCE
#define _DEFAULT_SOURCE
#include <sys/stat.h>
#include <limits.h>
#include <stdlib.h>

#include "libfakechroot.h"

struct __stat64_t64;

wrapper(__stat64_time64, int, (const char * file_name, struct __stat64_t64 * buf))
{
char fakechroot_abspath[FAKECHROOT_PATH_MAX];
char fakechroot_buf[FAKECHROOT_PATH_MAX];
debug("__stat64_time64(\"%s\", &buf)", file_name);
expand_chroot_path(file_name);
return nextcall(__stat64_time64)(file_name, buf);
}

#else
typedef int empty_translation_unit;
#endif
Loading