From f9be133913a22d5d7be5df3f198b6abcf98ae99b Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 30 May 2023 15:53:27 -0700 Subject: [PATCH] libsysprof-profile: implement loading files via sysprofd If we need access to a privileged file in /proc or /sys we need to get that through sysprofd. This implements basic checking of paths to see if we need to get a /proc file from there. We can't use the GetProfFD variant because that may still cause errors when reading back due to how selinux and other LSMs may restrict read() to get kallsyms. This requires recent API additions in libdex. --- src/libsysprof-profile/sysprof-recording.c | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/libsysprof-profile/sysprof-recording.c b/src/libsysprof-profile/sysprof-recording.c index 82545cfe..53a245e3 100644 --- a/src/libsysprof-profile/sysprof-recording.c +++ b/src/libsysprof-profile/sysprof-recording.c @@ -354,10 +354,31 @@ sysprof_recording_add_file_fiber (gpointer user_data) * We use g_file_has_prefix() for this as it will canonicalize the paths * of #GFile rather than us having to be careful here. */ - //if (g_file_has_prefix (file, proc)) - //{ - //} - //else + if (g_file_has_prefix (file, proc)) + { + g_autoptr(GDBusConnection) connection = NULL; + g_autoptr(GVariant) reply = NULL; + g_autoptr(GBytes) input_bytes = NULL; + + if (!(connection = dex_await_object (dex_bus_get (G_BUS_TYPE_SYSTEM), &error))) + return dex_future_new_for_error (g_steal_pointer (&error)); + + if (!(reply = dex_await_variant (dex_dbus_connection_call (connection, + "org.gnome.Sysprof3", + "/org/gnome/Sysprof3", + "org.gnome.Sysprof3.Service", + "GetProcFile", + g_variant_new ("(^ay)", g_file_get_path (file)), + G_VARIANT_TYPE ("(ay)"), + G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, + G_MAXINT), + &error))) + return dex_future_new_for_error (g_steal_pointer (&error)); + + input_bytes = g_variant_get_data_as_bytes (reply); + input = g_memory_input_stream_new_from_bytes (input_bytes); + } + else { if (!(input = dex_await_object (dex_file_read (file, 0), &error))) return dex_future_new_for_error (g_steal_pointer (&error));