Disallow ptrace on greeter and kwin_wayland process on FreeBSD [... for the future]

Authored by tcberner on Apr 15 2016, 5:02 PM.



Similar to[[ https://phabricator.kde.org/D1216 | D1216 ]] add procctl call to disable ptrace on FreeBSD.

We cannot do the procfs-lookup to check whether the process is already being run inside gdb -- however, on FreeBSD, we could use the P_TRACED flag of the process to figure this out:

sys/proc.h:#define P_TRACED 0x00800 /* Debugged process being traced. */

And the code would look something similar to

pid_t pid = getpid();
struct procstat *prstat = procstat_open_sysctl();
struct kinfo_proc *procinfo;
unsigned int cnt;
procinfo = procstat_getprocs(prstat, KERN_PROC_PID, pid, &cnt);
long p_flags = procinfo->ki_flag;
int p_traced = p_flags & P_TRACED; 
if (p_traced != P_TRACED) {
    procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode);

But as wayland is [far] in the future on FreeBSD, and that check above is a bit lengthy, I think it is enough if we add it once it is needed.

Diff Detail

R108 KWin
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
tcberner updated this revision to Diff 3368.Apr 15 2016, 5:02 PM
tcberner retitled this revision from to Disallow ptrace on greeter and kwin_wayland process on FreeBSD [... for the future].
tcberner updated this object.
tcberner edited the test plan for this revision. (Show Details)
tcberner added reviewers: rakuco, graesslin.
tcberner set the repository for this revision to R108 KWin.
Restricted Application added a project: Plasma. · View Herald TranscriptApr 15 2016, 5:02 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
graesslin accepted this revision.Apr 16 2016, 12:13 PM
graesslin edited edge metadata.

Totally fine with not having the gdb feature - that's also more of a dev feature for me as I often have to run it in the debugger. Once FreeBSD gets to that point there are also other possible solutions like a compile switch to disable it.

This revision is now accepted and ready to land.Apr 16 2016, 12:13 PM
tcberner updated this revision to Diff 3735.May 9 2016, 7:57 PM
tcberner edited edge metadata.

Regenerate the patch.

I cannot give another accept, so ShipIt

This revision was automatically updated to reflect the committed changes.