vmihalko / t2_polkit

Other
0 stars 0 forks source link

polkitd: use PIDFDs if available to track processes - [merged] #382

Closed vmihalko closed 1 year ago

vmihalko commented 1 year ago

In GitLab by @bluca on Apr 6, 2023, 02:15

Merges pidfd -> master

PIDs can be recycled, so when possible it is best to try and use PIDFDs, which are pinned. Change polkitd's unixprocess class so that, if the PIDFD syscall is available, it does not store a PID but only the PIDFD, and gets the PID when required on the fly (which will intentionally fail if the process has disappeared, so that we avoid recycling races).

In the future we will be able to get the PIDFD directly from D-Bus' GetConnectionCredentials() call, but for now get the FD from the PID. It does not completely close the window, but makes things significantly better already.

vmihalko commented 1 year ago

In GitLab by @bluca on Apr 6, 2023, 02:16

@jrybar split this out from https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/154 as it is useful by itself. It strictly improves the situation by taking a pidfd via pidfd_open. No external interface changes as the window is not fully closed until we can get a pidfd from D-Bus, but this is already useful by itself and by splitting it out it should be easier smaller and easier to review, I hope.

vmihalko commented 1 year ago

In GitLab by @bluca on Apr 13, 2023, 12:48

added 4 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on May 12, 2023, 19:47

added 3 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on May 24, 2023, 10:38

added 2 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on May 24, 2023, 15:12

added 2 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on May 24, 2023, 15:13

@jrybar ping, any chance for a review? This PR does not require any new kernel interface and can be used without the other one.

vmihalko commented 1 year ago

In GitLab by @jrybar on May 24, 2023, 15:19

Hello Luca,
of course it has a chance and I will happily review this once I get to it. It's in the queue.

Nonetheless, thanks for your hard work and time!

vmihalko commented 1 year ago

In GitLab by @bluca on May 24, 2023, 15:21

Thanks!

vmihalko commented 1 year ago

In GitLab by @jrybar on Jun 30, 2023, 13:05

Hello Luca,
it is settled that this MR will be the highest priority after this summer's (probably mid-july) release of polkit.

vmihalko commented 1 year ago

In GitLab by @bluca on Jul 4, 2023, 20:53

added 2 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on Jul 24, 2023, 11:54

added 2 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on Jul 30, 2023, 21:30

added 4 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 1, 2023, 12:20

added 2 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 2, 2023, 10:53

added 2 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 8, 2023, 15:04

@jrybar FYI the dbus-daemon change to add the new API has been merged: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/398

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 8, 2023, 21:00

added 3 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 11, 2023, 12:33

dbus-broker PR has been merged too, so now both D-Bus implementations will provide the required API in their next releases: https://github.com/bus1/dbus-broker/pull/312

vmihalko commented 1 year ago

In GitLab by @jrybar on Aug 16, 2023, 12:31

added 3 commits

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @jrybar on Aug 17, 2023, 14:03

requested review from @jrybar

vmihalko commented 1 year ago

In GitLab by @jrybar on Aug 17, 2023, 14:04

resolved all threads

vmihalko commented 1 year ago

In GitLab by @jrybar on Aug 17, 2023, 14:12

Commented on src/polkit/polkitunixprocess.c line 290

Just a question: Since we're really just looking for "^Pid:", wouldn't it be faster to just g_strstr() on *contents?

vmihalko commented 1 year ago

In GitLab by @jrybar on Aug 17, 2023, 14:12

Commented on src/polkit/polkitunixprocess.c line 58

just a typo :)

vmihalko commented 1 year ago

In GitLab by @jrybar on Aug 17, 2023, 14:12

I like the code, neat&tidy.

vmihalko commented 1 year ago

In GitLab by @jrybar on Aug 17, 2023, 14:12

approved this merge request

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 17, 2023, 14:23

Commented on src/polkit/polkitunixprocess.c line 290

It seemed more readable and less error-prone to go line-by-line, so that we can pass an individual buffer to sscanff or example. It's all small in-memory buffers, so I can't imagine it would make a measurable difference?

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 17, 2023, 14:23

Commented on src/polkit/polkitunixprocess.c line 58

changed this line in version 13 of the diff

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 17, 2023, 14:23

added 1 commit

Compare with previous version

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 17, 2023, 14:23

Commented on src/polkit/polkitunixprocess.c line 58

whops, fixed - given it's just one typo, I just amended and force pushed

vmihalko commented 1 year ago

In GitLab by @jrybar on Aug 17, 2023, 14:26

Commented on src/polkit/polkitunixprocess.c line 290

It just seems like a "cannonball on a fly" case where we just trash everything except the one line. But I think I can live with it :D

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 17, 2023, 14:46

Commented on src/polkit/polkitunixprocess.c line 290

Yeah it's usually 4/5 lines and a couple dozen characters, so it normally fits in a single cache line. If you want me to change it I can, otherwise are we good to merge?

$ cat /proc/self/fdinfo/0
pos:    0
flags:  02002002
mnt_id: 25
ino:    6
$ cat /proc/self/fdinfo/0 | wc
      4       8      41
vmihalko commented 1 year ago

In GitLab by @jrybar on Aug 17, 2023, 15:27

Commented on src/polkit/polkitunixprocess.c line 290

I want to try one final run on Rawhide and then it's set to go in.

vmihalko commented 1 year ago

In GitLab by @bluca on Aug 17, 2023, 16:02

Commented on src/polkit/polkitunixprocess.c line 290

thanks! I have rebased https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/154 on master, it's now ready