From: Ole Bjorn Hessen <obh@telenor.net>
To: linux-c-programming@vger.kernel.org
Subject: strace -p <pid> EPERM after root process changed uid/gid to non-root user
Date: Fri, 28 Sep 2012 18:11:12 +0200 [thread overview]
Message-ID: <v5626yi0v3.fsf@shell02.nsc.no> (raw)
Hi,
I have a program that starts as root and changes uid/gid to a non-root
user on linux. I'd like to run strace -p on that process as non-root
but I do only get ptrace(PTRACE_ATTACH, ...): Operation not
permitted. I can send kill to that program though as that non-root user.
Anybody care to explain what magic is neccessary for a root program to
reduce priv level so that an unpriv process can strace -p that program:
Attach is a small program that changes uid from root to "news".
Try to strace that program in another window:
## in window 1
echo '
#include <sys/types.h>
#include <unistd.h>
#define UID 9
int main(char **argv, int argc) {
setresgid(UID, UID, UID);
gid_t list[2];
list[0] = UID;
list[1] = 0;
setgroups(1, list);
setresuid(UID, UID, UID);
while (1) {
sleep(1);
write(1, "hello\n", 6);
}
return 1;
}
' > /tmp/ffo.c
gcc -o /tmp/ffo /tmp/ffo.c
super sh
/tmp/ffo
## in window 2
su news
strace -p $(ps -ef | grep ffo | grep -v grep | awk '{print $2}')
attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted
## kill is ok though
kill $(ps -ef | grep ffo | grep -v grep | awk '{print $2}')
--
Kind regards,
Ole Bjorn Hessen.
Telenor
----------
next reply other threads:[~2012-09-28 16:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-28 16:11 Ole Bjorn Hessen [this message]
2012-10-08 10:43 ` strace -p <pid> EPERM after root process changed uid/gid to non-root user Ole Bjorn Hessen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=v5626yi0v3.fsf@shell02.nsc.no \
--to=obh@telenor.net \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).