Skip to content

Commit b90959c

Browse files
paulfloydMark Wielaard
authored andcommitted
Bug 504265 - FreeBSD: missing syscall wrappers for fchroot and setcred
(cherry picked from commit 4f3f688)
1 parent 8a55301 commit b90959c

15 files changed

Lines changed: 211 additions & 2 deletions

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The following bugs have been fixed or resolved on this branch.
99
503641 close_range syscalls started failing with 3.25.0
1010
503914 mount syscall param filesystemtype may be NULL
1111
504177 FILE DESCRIPTORS banner shows when closing some inherited fds
12+
504265 FreeBSD: missing syscall wrappers for fchroot and setcred
1213

1314
To see details of a given bug, visit
1415
https://bugs.kde.org/show_bug.cgi?id=XXXXXX

configure.ac

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5006,7 +5006,9 @@ AC_CHECK_FUNCS([ \
50065006
fdatasync \
50075007
getrandom \
50085008
getrlimitusage \
5009-
timer_delete
5009+
timer_delete \
5010+
fchroot \
5011+
setcred
50105012
])
50115013

50125014
# AC_CHECK_LIB adds any library found to the variable LIBS, and links these
@@ -5064,6 +5066,10 @@ AM_CONDITIONAL([HAVE_GETRLIMITUSAGE],
50645066
[test x$ac_cv_func_getrlimitusage = xyes])
50655067
AM_CONDITIONAL([HAVE_TIMER_DELETE],
50665068
[test x$ac_cv_func_timer_delete = xyes])
5069+
AM_CONDITIONAL([HAVE_FCHROOT],
5070+
[test x$ac_cv_func_fchroot = xyes])
5071+
AM_CONDITIONAL([HAVE_SETCRED],
5072+
[test x$ac_cv_func_setcred = xyes])
50675073

50685074
if test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
50695075
-o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \

coregrind/m_syswrap/priv_syswrap-freebsd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,10 @@ DECL_TEMPLATE(freebsd, sys_timerfd_settime) // 587
538538

539539
// __FreeBSD_version 1400507 and 1500012
540540
DECL_TEMPLATE(freebsd, sys_kcmp) // 588
541+
541542
DECL_TEMPLATE(freebsd, sys_getrlimitusage) // 589
543+
DECL_TEMPLATE(freebsd, sys_fchroot) // 590
544+
DECL_TEMPLATE(freebsd, sys_setcred) // 591
542545

543546
DECL_TEMPLATE(freebsd, sys_fake_sigreturn)
544547

coregrind/m_syswrap/syswrap-freebsd.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7001,6 +7001,28 @@ POST(sys_getrlimitusage)
70017001
}
70027002
}
70037003

7004+
// SYS_fchroot 590
7005+
// int fchroot(int fd);
7006+
PRE(sys_fchroot)
7007+
{
7008+
PRINT("sys_fchroot(%ld)", ARG1);
7009+
PRE_REG_READ1(int, "fchroot", int, fd);
7010+
7011+
/* Be strict. */
7012+
if (!ML_(fd_allowed)(ARG1, "fchroot", tid, False))
7013+
SET_STATUS_Failure(VKI_EBADF);
7014+
}
7015+
7016+
// SYS_setcred
7017+
// int setcred(u_int flags, const struct setcred *wcred, size_t size);
7018+
PRE(sys_setcred)
7019+
{
7020+
PRINT("sys_setcred(%ld, %#" FMT_REGWORD "x, %lu)", ARG1, ARG2, ARG3);
7021+
PRE_REG_READ3(int, "setcred", u_int, flags, const struct setcred*, wcred, size_t, size);
7022+
PRE_MEM_READ("setcred(wcred)", ARG2, sizeof(struct vki_setcred));
7023+
}
7024+
7025+
70047026
#undef PRE
70057027
#undef POST
70067028

@@ -7694,6 +7716,9 @@ const SyscallTableEntry ML_(syscall_table)[] = {
76947716
BSDX_(__NR_kcmp, sys_kcmp), // 588
76957717
BSDXY(__NR_getrlimitusage, sys_getrlimitusage), // 589
76967718

7719+
BSDX_(__NR_fchroot, sys_fchroot), // 590
7720+
BSDX_(__NR_setcred, sys_setcred), // 591
7721+
76977722
BSDX_(__NR_fake_sigreturn, sys_fake_sigreturn), // 1000, fake sigreturn
76987723

76997724
};

include/vki/vki-freebsd.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,6 +3257,23 @@ union vki_ccb {
32573257

32583258
#define VKI_CAMIOCOMMAND _VKI_IOWR(VKI_CAM_VERSION, 2, union vki_ccb)
32593259

3260+
//----------------------------------------------------------------------
3261+
// From cam/scsi/scsi_all.h
3262+
//----------------------------------------------------------------------
3263+
struct vki_setcred {
3264+
vki_uid_t sc_uid; /* effective user id */
3265+
vki_uid_t sc_ruid; /* real user id */
3266+
vki_uid_t sc_svuid; /* saved user id */
3267+
vki_gid_t sc_gid; /* effective group id */
3268+
vki_gid_t sc_rgid; /* real group id */
3269+
vki_gid_t sc_svgid; /* saved group id */
3270+
vki_u_int sc_pad; /* see 32-bit compat structure */
3271+
vki_u_int sc_supp_groups_nb; /* number of supplementary groups */
3272+
vki_gid_t *sc_supp_groups; /* supplementary groups */
3273+
struct vki_mac *sc_label; /* MAC label */
3274+
};
3275+
3276+
32603277

32613278
/*--------------------------------------------------------------------*/
32623279
/*--- end ---*/

include/vki/vki-scnums-freebsd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@
627627
#define __NR_kcmp 588
628628

629629
#define __NR_getrlimitusage 589
630+
#define __NR_fchroot 590
631+
#define __NR_setcred 591
630632

631633
#define __NR_fake_sigreturn 1000
632634

memcheck/tests/freebsd/Makefile.am

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ EXTRA_DIST = \
5353
extattr.stderr.exp \
5454
fbsd278566.vgtest \
5555
fbsd278566.stderr.exp \
56+
fchroot.vgtest \
57+
fchroot.stderr.exp \
5658
fexecve.vgtest \
5759
fexecve.stderr.exp \
5860
file_locking_wait6.vgtest \
@@ -109,6 +111,8 @@ EXTRA_DIST = \
109111
sctp2.vgtest \
110112
sctp2.stderr.exp \
111113
sctp2.stdout.exp \
114+
setcred.vgtest \
115+
setcred.stderr.exp \
112116
setproctitle.vgtest \
113117
setproctitle.stderr.exp \
114118
setproctitle.stdout.exp \
@@ -176,6 +180,11 @@ if HAVE_AIO_READV
176180
check_PROGRAMS += aiov
177181
endif
178182

183+
if HAVE_FCHROOT
184+
check_PROGRAMS += fchroot
185+
fchroot_SOURCES = fchroot.cpp
186+
endif
187+
179188
if HAVE_GETRLIMITUSAGE
180189
check_PROGRAMS += getrlimitusage
181190
endif
@@ -203,6 +212,12 @@ if FREEBSD_KQUEUEX_SYSCALL
203212
check_PROGRAMS += kqueuex
204213
endif
205214

215+
if HAVE_SETCRED
216+
check_PROGRAMS += setcred
217+
setcred_SOURCES = setcred.cpp
218+
setcred_CXXFLAGS = ${AM_CXXFLAGS} @FLAG_W_NO_UNINITIALIZED@
219+
endif
220+
206221
if FREEBSD_TIMERFD_SYSCALL
207222
check_PROGRAMS += timerfd
208223
timerfd_LDFLAGS = -lm

memcheck/tests/freebsd/fchroot.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <unistd.h>
2+
#include <fcntl.h>
3+
4+
int main()
5+
{
6+
int fd1;
7+
int* fd2{new int};
8+
9+
fd1 = open("..", O_DIRECTORY | O_RDONLY);
10+
// will fail unless run as root
11+
fchroot(fd1);
12+
13+
fchroot(*fd2);
14+
15+
delete fd2;
16+
}
17+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Syscall param fchroot(fd) contains uninitialised byte(s)
2+
at 0x........: fchroot (in /...libc...)
3+
by 0x........: main (fchroot.cpp:13)
4+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
prereq: test -e ./fchroot
2+
prog: fchroot
3+
vgopts: -q

0 commit comments

Comments
 (0)