Using SystemTap to trace the system calls of setuid programs on LinuxSuppose that you have a setuid program that is failing mysteriously
and you want to see what it's doing. With normal programs you can use
(Yes, On a Solaris system you could use DTrace for this. SystemTap is the rough Linux equivalent and, although much less polished and not as well documented, it does work. Here is the crude SystemTap script that I used:
probe syscall.* {
en = execname();
ui = uid();
eui = euid();
if (en == "<redacted>") {
printf("%s(%d): %s(%s)", en, pid(), name, argstr);
if (ui != eui) {
printf(" as %d/%d ", ui, eui);
} else {
printf(" as %d ", ui);
}
}
}
probe syscall.*.return {
en = execname();
if (en == "<redacted>") {
printf("= %s\n", retstr);
}
}
This produces output with system call arguments and return values helpfully decoded for you; it looks like:
(In some ways this is nicer than DTrace. But the lack of documentation
on what sort of information you can get about system calls and so on
really hurts; I had to read the source for the syscall tapset in order
to find out about Note that, despite the presence of the PID in the output, this isn't
really useful for tracing if more than one instance of the program is
running at once. That would take more SystemTap magic than I know so far
(or worse output and some postprocessing). Also, since One of the things that the documentation isn't very clear about is that
the All in all, I would have to score my first real exposure to SystemTap as a reasonably pleasant experience. Although there were a bunch of frustrating bits, it did work, it gave me what I wanted to know, and it wasn't particularly difficult to do or to work out how to do it (and it didn't take particularly long). (One comment.)
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |