Re: [PATCH] tracing/user_events: Run BPF program if attached
flat view
From: Beau Belgrave <hidden>
Date: 2023-05-18 17:28:15
Also in:
bpf, lkml
On Thu, May 18, 2023 at 09:36:00AM -0400, Steven Rostedt wrote:
On Wed, 17 May 2023 20:14:31 -0700 Alexei Starovoitov [off-list ref] wrote:quoted
On Wed, May 17, 2023 at 7:08 PM Steven Rostedt [off-list ref] wrote:quoted
quoted
The delete IOCTL is different than reg/unreg. I don't see a problem with adding a CAP_SYSADMIN check on the delete IOCTL (and other delete paths) to prevent this. It shouldn't affect anything we are doing to add this and it makes it so non-admins cannot delete any events if they are given write access to the user_events_data file.sysadmin for delete is a pointless. user_events_ioctl_reg() has the same issue. Two different processes using you fancy TRACELOGGING_DEFINE_PROVIDER() macro and picking the same name will race. TRACELOGGING_DEFINE_PROVIDER( // defines the MyProvider symbol MyProvider, // Name of the provider symbol to define "MyCompany_MyComponent_MyProvider", // Human-readable provider name, no ' ' or ':' chars. // {d5b90669-1aad-5db8-16c9-6286a7fcfe33} // Provider guid (ignored on Linux) (0xd5b90669,0x1aad,0x5db8,0x16,0xc9,0x62,0x86,0xa7,0xfc,0xfe,0x33)); I totally get it that Beau is copy pasting these ideas from windows, but windows is likely similarly broken if it's registering names globally. FD should be the isolation boundary. fd = open("/sys/kernel/tracing/user_event") and make sure all events are bound to that file. when file is closed the events _should be auto deleted_. That's another issue I just spotted. Looks like user_events_release() is leaking memory. user_event_refs are just lost. tbh the more I look into the code the more I want to suggest to mark it depends on BROKEN and go back to redesign.I don't think these changes require a redesign. I do like the idea that the events live with the fd. That is, when the fd dies, so does the event. Although, we may keep it around for a bit (no new events, but being able to parse it. That is, the event itself isn't deleted until the fd is closed, and so is the tracing files being read are closed. Beau, How hard is it to give the event an owner, but not for task or user, but with the fd. That way you don't need to worry about other tasks deleting the event. And it also automatically cleans itself up. If we leave it to the sysadmin to clean up, it's going to cause leaks, because it's not something the sysadmin will want to do, as they will need to keep track of what events are created.
We need to ensure that multiple processes can use the same event name: Example we have shared libraries that processes use to publish events. We need to ensure that if the original FD closes and other processes/FDs are using it, those don't get ripped out from underneath it: Example we have perf attached and then the process exits. I think we can accomodate that all neatly if we just make the event self-delete upon the last ref-count decrement. That way no one needs the delete IOCTL and we can prevent things piling up. We have flags in the struct, so we could either make this optional or default. I like this approach Steven. Thanks, -Beau
-- Steve PS. I missed my connection due to unseasonal freezing temperatures, and my little airport didn't have a driver for the deicer, making my flight 2 hours delayed (had to wait for the sun to come up and deice the plane!). Thus, instead of enjoying myself by the pool, I'm in an airport lounge without much to do.