rr-debugger / rr-debugger/rr

Question regarding trying to avoid `perf_event_paranoid` using `setcap`

Open
#3,202 17 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
10.7k
Forks
662
Avg merge
2d 3h
Merged PRs (30d)
2

Description

Hello there,

and apologies if the answer is obvious. I wanted to avoid using the axe

# echo 'kernel.perf_event_paranoid=1' | sudo tee '/etc/sysctl.d/51-enable-perf-events.conf'

and instead, opted for the https://unix.stackexchange.com/a/519071/266638 solution - tl;dr:

sudo newgrp perfmon_users
sudo usermod -aG perfmon_users stdedos

sudo chgrp perfmon_users /usr/bin/rr 
chmod o-rwx /usr/bin/rr
ls -lah /usr/bin/rr
sudo chmod o-rwx /usr/bin/rr
sudo setcap "cap_perfmon,cap_sys_ptrace,cap_syslog=ep" /usr/bin/rr
sudo setcap "cap_sys_ptrace,cap_syslog=ep" /usr/bin/rr
# Only this one ^^^ works on Ubuntu 20.04, ******; or
sudo setcap -v "38,cap_sys_ptrace,cap_syslog=ep" /usr/bin/rr

and I am still getting

$ rr record --wait sleep 20
[FATAL /home/roc/rr/rr/src/PerfCounters.cc:213:start_counter()] Permission denied to use 'perf_event_open'; are hardware perf events available? See https://github.com/rr-debugger/rr/wiki/Will-rr-work-on-my-system

even though, by using sudo, "it seems to be working":

$ cat /proc/1573015/status
Name:	sudo
Umask:	0022
State:	S (sleeping)
Tgid:	1573015
Ngid:	0
Pid:	1573015
PPid:	1553277
TracerPid:	0
Uid:	0	0	0	0
Gid:	0	0	0	0
FDSize:	256
Groups:	0 
NStgid:	1573015
NSpid:	1573015
NSpgid:	1573015
NSsid:	1553133
VmPeak:	   16192 kB
VmSize:	   16192 kB
VmLck:	       0 kB
VmPin:	       0 kB
VmHWM:	    4908 kB
VmRSS:	    4908 kB
RssAnon:	     704 kB
RssFile:	    4204 kB
RssShmem:	       0 kB
VmData:	     856 kB
VmStk:	     276 kB
VmExe:	     104 kB
VmLib:	    3340 kB
VmPTE:	      56 kB
VmSwap:	       0 kB
HugetlbPages:	       0 kB
CoreDumping:	0
THP_enabled:	1
Threads:	1
SigQ:	1/126851
SigPnd:	0000000000000000
ShdPnd:	0000000000000000
SigBlk:	0000000000000000
SigIgn:	0000000000000000
SigCgt:	00000001800b7a07
CapInh:	0000000000000000
CapPrm:	000001ffffffffff
CapEff:	000001ffffffffff
CapBnd:	000001ffffffffff
CapAmb:	0000000000000000
NoNewPrivs:	0
Seccomp:	0
Seccomp_filters:	0
Speculation_Store_Bypass:	thread vulnerable
SpeculationIndirectBranch:	conditional enabled
Cpus_allowed:	ffff
Cpus_allowed_list:	0-15
Mems_allowed:	00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
Mems_allowed_list:	0
voluntary_ctxt_switches:	2
nonvoluntary_ctxt_switches:	0
$ capsh --decode=000001ffffffffff
WARNING: libcap needs an update (cap=40 should have a name).
0x000001ffffffffff=cap_chown,cap_dac_override,cap_dac_read_search,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_linux_immutable,cap_net_bind_service,cap_net_broadcast,cap_net_admin,cap_net_raw,cap_ipc_lock,cap_ipc_owner,cap_sys_module,cap_sys_rawio,cap_sys_chroot,cap_sys_ptrace,cap_sys_pacct,cap_sys_admin,cap_sys_boot,cap_sys_nice,cap_sys_resource,cap_sys_time,cap_sys_tty_config,cap_mknod,cap_lease,cap_audit_write,cap_audit_control,cap_setfcap,cap_mac_override,cap_mac_admin,cap_syslog,cap_wake_alarm,cap_block_suspend,cap_audit_read,38,39,40

(I don't know a way to "freeze" rr while running it in a non-sudo environment; any advice welcome)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing rr record --wait sleep 20 with and without sudo, then inspect src/PerfCounters.cc at start_counter() and the reported perf_event_open failure. Compare the executable capabilities on /usr/bin/rr with the permissions required by the kernel; done means explaining whether this configuration is supported and identifying any rr-side change or documentation needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux
Domain
devtools, operating-systems, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.