>
ssh-agent protects itself from being accessed by the same user account (via the debugging APIs) by being setgid to group sshI don't think this is correct. ssh-agent typically will be run under your user/group; it shouldn't have the necessary privileges to setgid to ssh. Further, I have ssh-agent running on a machine, and it is still my gid. Last, that machine doesn't even have an "ssh" group.
Rather, I think ssh-agent likely protects itself from being debugged (ptrace'd) by ptrace'ing itself. My understanding is that a process can only be ptraced by one process at a time, and by ptrace'ing yourself, you deny the ability for anything else to attach to you.
For example, my uid & gid:
» printf '%s,%s\n' "$(id -u)" "$(id -g)"
1000,1000
ssh-agent running as those:
» ps -eo pid,uid,gid,args | grep ssh-agent
16438 1000 1000 ssh-agent
but not debuggable:
» strace -p 16438
strace: attach: ptrace(PTRACE_SEIZE, 16438): Operation not permitted
Perhaps this is just my machine however, and if I did have a `ssh` group,
and I were a member of it, it would setgid to it. I don't think that's foolproof, however: something running under your uid could kill ssh-agent, and restart it under a debugger, skip or elide the setgid() and ptrace() calls, then continue to allow it to execute normally, and now be attached as a debugger.
I'm also not sure if ptrace()'ing yourself prevents you from reading out the process's memory from /proc.
Edit: so, on Linux, it seems this is what it does[1]:
prctl(PR_SET_DUMPABLE, 0)
That makes the process "undumpable", which means it won't leave behind core files, /proc/pid is root:root, and it can't be ptrace()'d. I still think the caveat about starting it under a debugger applies, but that certainly makes it less trivial.
[1]: https://github.com/openssh/openssh-portable/blob/5ee3fb5affd...