summaryrefslogtreecommitdiffstats
path: root/sys/compat/linux/linux_uid16.c
diff options
context:
space:
mode:
authornetchild <netchild@FreeBSD.org>2012-05-05 19:42:38 +0000
committernetchild <netchild@FreeBSD.org>2012-05-05 19:42:38 +0000
commit9895b5ca9df1f0d045ee00e77007e80d4c202ca4 (patch)
tree2c944ca220ef9f94f80b967133cbd2ab53caa81c /sys/compat/linux/linux_uid16.c
parent096ede817a595e57dafce2910385344f389c8dbd (diff)
downloadFreeBSD-src-9895b5ca9df1f0d045ee00e77007e80d4c202ca4.zip
FreeBSD-src-9895b5ca9df1f0d045ee00e77007e80d4c202ca4.tar.gz
- >500 static DTrace probes for the linuxulator
- DTrace scripts to check for errors, performance, ... they serve mostly as examples of what you can do with the static probe;s with moderate load the scripts may be overwhelmed, excessive lock-tracing may influence program behavior (see the last design decission) Design decissions: - use "linuxulator" as the provider for the native bitsize; add the bitsize for the non-native emulation (e.g. "linuxuator32" on amd64) - Add probes only for locks which are acquired in one function and released in another function. Locks which are aquired and released in the same function should be easy to pair in the code, inter-function locking is more easy to verify in DTrace. - Probes for locks should be fired after locking and before releasing to prevent races (to provide data/function stability in DTrace, see the man-page of "dtrace -v ..." and the corresponding DTrace docs).
Diffstat (limited to 'sys/compat/linux/linux_uid16.c')
-rw-r--r--sys/compat/linux/linux_uid16.c189
1 files changed, 161 insertions, 28 deletions
diff --git a/sys/compat/linux/linux_uid16.c b/sys/compat/linux/linux_uid16.c
index 31950ff..b66fb5c 100644
--- a/sys/compat/linux/linux_uid16.c
+++ b/sys/compat/linux/linux_uid16.c
@@ -28,14 +28,17 @@
__FBSDID("$FreeBSD$");
#include "opt_compat.h"
+#include "opt_kdtrace.h"
#include <sys/fcntl.h>
#include <sys/param.h>
+#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/proc.h>
+#include <sys/sdt.h>
#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
#include <sys/systm.h>
@@ -48,8 +51,53 @@ __FBSDID("$FreeBSD$");
#include <machine/../linux/linux_proto.h>
#endif
+#include <compat/linux/linux_dtrace.h>
#include <compat/linux/linux_util.h>
+/* DTrace init */
+LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
+
+/**
+ * DTrace probes in this module.
+ */
+LIN_SDT_PROBE_DEFINE3(uid16, linux_chown16, entry, "char *", "l_uid16_t",
+ "l_gid16_t");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_chown16, conv_path, "char *");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_chown16, return, "int");
+LIN_SDT_PROBE_DEFINE3(uid16, linux_lchown16, entry, "char *", "l_uid16_t",
+ "l_gid16_t");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_lchown16, conv_path, "char *");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_lchown16, return, "int");
+LIN_SDT_PROBE_DEFINE2(uid16, linux_setgroups16, entry, "l_uint", "l_gid16_t *");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setgroups16, copyin_error, "int");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setgroups16, priv_check_cred_error, "int");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setgroups16, return, "int");
+LIN_SDT_PROBE_DEFINE2(uid16, linux_getgroups16, entry, "l_uint", "l_gid16_t *");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_getgroups16, copyout_error, "int");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_getgroups16, return, "int");
+LIN_SDT_PROBE_DEFINE0(uid16, linux_getgid16, entry);
+LIN_SDT_PROBE_DEFINE1(uid16, linux_getgid16, return, "int");
+LIN_SDT_PROBE_DEFINE0(uid16, linux_getuid16, entry);
+LIN_SDT_PROBE_DEFINE1(uid16, linux_getuid16, return, "int");
+LIN_SDT_PROBE_DEFINE0(uid16, linux_getegid16, entry);
+LIN_SDT_PROBE_DEFINE1(uid16, linux_getegid16, return, "int");
+LIN_SDT_PROBE_DEFINE0(uid16, linux_geteuid16, entry);
+LIN_SDT_PROBE_DEFINE1(uid16, linux_geteuid16, return, "int");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setgid16, entry, "l_gid16_t");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setgid16, return, "int");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setuid16, entry, "l_uid16_t");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setuid16, return, "int");
+LIN_SDT_PROBE_DEFINE2(uid16, linux_setregid16, entry, "l_git16_t", "l_git16_t");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setregid16, return, "int");
+LIN_SDT_PROBE_DEFINE2(uid16, linux_setreuid16, entry, "l_uid16_t", "l_uid16_t");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setreuid16, return, "int");
+LIN_SDT_PROBE_DEFINE3(uid16, linux_setresgid16, entry, "l_gid16_t", "l_gid16_t",
+ "l_gid16_t");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setresgid16, return, "int");
+LIN_SDT_PROBE_DEFINE3(uid16, linux_setresuid16, entry, "l_uid16_t", "l_uid16_t",
+ "l_uid16_t");
+LIN_SDT_PROBE_DEFINE1(uid16, linux_setresuid16, return, "int");
+
DUMMY(setfsuid16);
DUMMY(setfsgid16);
DUMMY(getresuid16);
@@ -65,13 +113,20 @@ linux_chown16(struct thread *td, struct linux_chown16_args *args)
LCONVPATHEXIST(td, args->path, &path);
-#ifdef DEBUG
- if (ldebug(chown16))
- printf(ARGS(chown16, "%s, %d, %d"), path, args->uid, args->gid);
-#endif
+ /*
+ * The DTrace probes have to be after the LCONVPATHEXIST, as
+ * LCONVPATHEXIST may return on its own and we do not want to
+ * have a stray entry without the corresponding return.
+ */
+ LIN_SDT_PROBE3(uid16, linux_chown16, entry, args->path, args->uid,
+ args->gid);
+ LIN_SDT_PROBE1(uid16, linux_chown16, conv_path, path);
+
error = kern_chown(td, path, UIO_SYSSPACE, CAST_NOCHG(args->uid),
CAST_NOCHG(args->gid));
LFREEPATH(path);
+
+ LIN_SDT_PROBE1(uid16, linux_chown16, return, error);
return (error);
}
@@ -83,14 +138,20 @@ linux_lchown16(struct thread *td, struct linux_lchown16_args *args)
LCONVPATHEXIST(td, args->path, &path);
-#ifdef DEBUG
- if (ldebug(lchown16))
- printf(ARGS(lchown16, "%s, %d, %d"), path, args->uid,
- args->gid);
-#endif
+ /*
+ * The DTrace probes have to be after the LCONVPATHEXIST, as
+ * LCONVPATHEXIST may return on its own and we do not want to
+ * have a stray entry without the corresponding return.
+ */
+ LIN_SDT_PROBE3(uid16, linux_lchown16, entry, args->path, args->uid,
+ args->gid);
+ LIN_SDT_PROBE1(uid16, linux_lchown16, conv_path, path);
+
error = kern_lchown(td, path, UIO_SYSSPACE, CAST_NOCHG(args->uid),
CAST_NOCHG(args->gid));
LFREEPATH(path);
+
+ LIN_SDT_PROBE1(uid16, linux_lchown16, return, error);
return (error);
}
@@ -103,17 +164,19 @@ linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args)
int ngrp, error;
struct proc *p;
-#ifdef DEBUG
- if (ldebug(setgroups16))
- printf(ARGS(setgroups16, "%d, *"), args->gidsetsize);
-#endif
+ LIN_SDT_PROBE2(uid16, linux_setgroups16, entry, args->gidsetsize,
+ args->gidset);
ngrp = args->gidsetsize;
- if (ngrp < 0 || ngrp >= ngroups_max + 1)
+ if (ngrp < 0 || ngrp >= ngroups_max + 1) {
+ LIN_SDT_PROBE1(uid16, linux_setgroups16, return, EINVAL);
return (EINVAL);
+ }
linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_TEMP, M_WAITOK);
error = copyin(args->gidset, linux_gidset, ngrp * sizeof(l_gid16_t));
if (error) {
+ LIN_SDT_PROBE1(uid16, linux_setgroups16, copyin_error, error);
+ LIN_SDT_PROBE1(uid16, linux_setgroups16, return, error);
free(linux_gidset, M_TEMP);
return (error);
}
@@ -131,6 +194,9 @@ linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args)
if ((error = priv_check_cred(oldcred, PRIV_CRED_SETGROUPS, 0)) != 0) {
PROC_UNLOCK(p);
crfree(newcred);
+
+ LIN_SDT_PROBE1(uid16, linux_setgroups16, priv_check_cred_error,
+ error);
goto out;
}
@@ -154,6 +220,8 @@ linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args)
error = 0;
out:
free(linux_gidset, M_TEMP);
+
+ LIN_SDT_PROBE1(uid16, linux_setgroups16, return, error);
return (error);
}
@@ -165,10 +233,8 @@ linux_getgroups16(struct thread *td, struct linux_getgroups16_args *args)
gid_t *bsd_gidset;
int bsd_gidsetsz, ngrp, error;
-#ifdef DEBUG
- if (ldebug(getgroups16))
- printf(ARGS(getgroups16, "%d, *"), args->gidsetsize);
-#endif
+ LIN_SDT_PROBE2(uid16, linux_getgroups16, entry, args->gidsetsize,
+ args->gidset);
cred = td->td_ucred;
bsd_gidset = cred->cr_groups;
@@ -182,11 +248,15 @@ linux_getgroups16(struct thread *td, struct linux_getgroups16_args *args)
if ((ngrp = args->gidsetsize) == 0) {
td->td_retval[0] = bsd_gidsetsz;
+
+ LIN_SDT_PROBE1(uid16, linux_getgroups16, return, 0);
return (0);
}
- if (ngrp < bsd_gidsetsz)
+ if (ngrp < bsd_gidsetsz) {
+ LIN_SDT_PROBE1(uid16, linux_getgroups16, return, EINVAL);
return (EINVAL);
+ }
ngrp = 0;
linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset),
@@ -198,10 +268,15 @@ linux_getgroups16(struct thread *td, struct linux_getgroups16_args *args)
error = copyout(linux_gidset, args->gidset, ngrp * sizeof(l_gid16_t));
free(linux_gidset, M_TEMP);
- if (error)
+ if (error) {
+ LIN_SDT_PROBE1(uid16, linux_getgroups16, copyout_error, error);
+ LIN_SDT_PROBE1(uid16, linux_getgroups16, return, error);
return (error);
+ }
td->td_retval[0] = ngrp;
+
+ LIN_SDT_PROBE1(uid16, linux_getgroups16, return, 0);
return (0);
}
@@ -219,7 +294,11 @@ int
linux_getgid16(struct thread *td, struct linux_getgid16_args *args)
{
+ LIN_SDT_PROBE0(uid16, linux_getgid16, entry);
+
td->td_retval[0] = td->td_ucred->cr_rgid;
+
+ LIN_SDT_PROBE1(uid16, linux_getgid16, return, 0);
return (0);
}
@@ -227,7 +306,11 @@ int
linux_getuid16(struct thread *td, struct linux_getuid16_args *args)
{
+ LIN_SDT_PROBE0(uid16, linux_getuid16, entry);
+
td->td_retval[0] = td->td_ucred->cr_ruid;
+
+ LIN_SDT_PROBE1(uid16, linux_getuid16, return, 0);
return (0);
}
@@ -235,74 +318,124 @@ int
linux_getegid16(struct thread *td, struct linux_getegid16_args *args)
{
struct getegid_args bsd;
+ int error;
+
+ LIN_SDT_PROBE0(uid16, linux_getegid16, entry);
+
+ error = sys_getegid(td, &bsd);
- return (sys_getegid(td, &bsd));
+ LIN_SDT_PROBE1(uid16, linux_getegid16, return, error);
+ return (error);
}
int
linux_geteuid16(struct thread *td, struct linux_geteuid16_args *args)
{
struct geteuid_args bsd;
+ int error;
+
+ LIN_SDT_PROBE0(uid16, linux_geteuid16, entry);
+
+ error = sys_geteuid(td, &bsd);
- return (sys_geteuid(td, &bsd));
+ LIN_SDT_PROBE1(uid16, linux_geteuid16, return, error);
+ return (error);
}
int
linux_setgid16(struct thread *td, struct linux_setgid16_args *args)
{
struct setgid_args bsd;
+ int error;
+
+ LIN_SDT_PROBE1(uid16, linux_setgid16, entry, args->gid);
bsd.gid = args->gid;
- return (sys_setgid(td, &bsd));
+ error = sys_setgid(td, &bsd);
+
+ LIN_SDT_PROBE1(uid16, linux_setgid16, return, error);
+ return (error);
}
int
linux_setuid16(struct thread *td, struct linux_setuid16_args *args)
{
struct setuid_args bsd;
+ int error;
+
+ LIN_SDT_PROBE1(uid16, linux_setuid16, entry, args->uid);
bsd.uid = args->uid;
- return (sys_setuid(td, &bsd));
+ error = sys_setuid(td, &bsd);
+
+ LIN_SDT_PROBE1(uid16, linux_setuid16, return, error);
+ return (error);
}
int
linux_setregid16(struct thread *td, struct linux_setregid16_args *args)
{
struct setregid_args bsd;
+ int error;
+
+ LIN_SDT_PROBE2(uid16, linux_setregid16, entry, args->rgid, args->egid);
bsd.rgid = CAST_NOCHG(args->rgid);
bsd.egid = CAST_NOCHG(args->egid);
- return (sys_setregid(td, &bsd));
+ error = sys_setregid(td, &bsd);
+
+ LIN_SDT_PROBE1(uid16, linux_setregid16, return, error);
+ return (error);
}
int
linux_setreuid16(struct thread *td, struct linux_setreuid16_args *args)
{
struct setreuid_args bsd;
+ int error;
+
+ LIN_SDT_PROBE2(uid16, linux_setreuid16, entry, args->ruid, args->euid);
bsd.ruid = CAST_NOCHG(args->ruid);
bsd.euid = CAST_NOCHG(args->euid);
- return (sys_setreuid(td, &bsd));
+ error = sys_setreuid(td, &bsd);
+
+ LIN_SDT_PROBE1(uid16, linux_setreuid16, return, error);
+ return (error);
}
int
linux_setresgid16(struct thread *td, struct linux_setresgid16_args *args)
{
struct setresgid_args bsd;
+ int error;
+
+ LIN_SDT_PROBE3(uid16, linux_setresgid16, entry, args->rgid, args->egid,
+ args->sgid);
bsd.rgid = CAST_NOCHG(args->rgid);
bsd.egid = CAST_NOCHG(args->egid);
bsd.sgid = CAST_NOCHG(args->sgid);
- return (sys_setresgid(td, &bsd));
+ error = sys_setresgid(td, &bsd);
+
+ LIN_SDT_PROBE1(uid16, linux_setresgid16, return, error);
+ return (error);
}
int
linux_setresuid16(struct thread *td, struct linux_setresuid16_args *args)
{
struct setresuid_args bsd;
+ int error;
+
+ LIN_SDT_PROBE3(uid16, linux_setresuid16, entry, args->ruid, args->euid,
+ args->suid);
bsd.ruid = CAST_NOCHG(args->ruid);
bsd.euid = CAST_NOCHG(args->euid);
bsd.suid = CAST_NOCHG(args->suid);
- return (sys_setresuid(td, &bsd));
+ error = sys_setresuid(td, &bsd);
+
+ LIN_SDT_PROBE1(uid16, linux_setresuid16, return, error);
+ return (error);
}
OpenPOWER on IntegriCloud