Bug 473780 - System Monitor confuses PID of Flatpak applications with host PID namespace
Summary: System Monitor confuses PID of Flatpak applications with host PID namespace
Status: RESOLVED UNMAINTAINED
Alias: None
Product: ksysguard
Classification: Unmaintained
Component: libksysguard (show other bugs)
Version: master
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KSysGuard Developers
URL:
Keywords: qt6
Depends on:
Blocks:
 
Reported: 2023-08-26 17:21 UTC by ratijas
Modified: 2024-09-23 20:59 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Telegram is now in your kernel-space (138.90 KB, image/png)
2023-08-26 17:21 UTC, ratijas
Details
matrix consumes your kernel too (168.81 KB, image/png)
2023-08-26 17:48 UTC, ratijas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ratijas 2023-08-26 17:21:37 UTC
Created attachment 161197 [details]
Telegram is now in your kernel-space

SUMMARY

KSysGuard ProcessUi::ProcessModel associates kthreadd process (PID 2) with user's Telegram Desktop app running under Flatpak. Table view shows telegram-desktop icon for model's Qt::Decoration role, and context menu item "Show Application Window" activates Telegram window, also "Window Title" column is set to Telegram window's title string.

STEPS TO REPRODUCE
1. Ctrl+Escape
2. ???

OBSERVED RESULT
See the screenshot

EXPECTED RESULT
Definitely not this

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.27.80
KDE Frameworks Version: 5.240.0
Qt Version: 6.5.2
Kernel Version: 6.4.12-arch1-1 (64-bit)
Graphics Platform: X11

ADDITIONAL INFORMATION
Telegram is running from Flatpak. I don't know of its inner working, but maybe it containerized PID namespace just like docker? From the outside, app's PID is 4-digits which is pretty much what you would expect from a normal user process.
Comment 1 ratijas 2023-08-26 17:48:33 UTC
Created attachment 161198 [details]
matrix consumes your kernel too

telegram-desktop process, on the other hand, doesn't get any recognition as being a GUI application. It is running under two nested bwrap processes. This second screenshot shows that Matrix client Element (also packaged as Flatpak) is having identity crisis too.
Comment 2 ratijas 2023-08-26 18:07:53 UTC
Can confirm that PID inside Flatpak running instance is living in a separate namespace from the host.

❯ flatpak ps
Instance   PID   Application          Runtime
574133368  61939 im.riot.Riot         org.freedesktop.Platform
2219558800 61908 im.riot.Riot         org.freedesktop.Platform
505331848  5742  org.telegram.desktop org.freedesktop.Platform
❯ flatpak enter 505331848 /bin/bash
bash-5.1$ ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ratijas        1  0.0  0.0   3148  1152 ?        S    14:17   0:00 bwrap --args 41 /app/bin/telegram-desktop
ratijas        2  2.3  3.2 2605696 527932 ?      Sl   14:17   9:25 /app/bin/telegram-desktop
ratijas     3180  0.0  0.0   4896  3584 pts/6    S    21:03   0:00 /bin/bash
ratijas     3181  0.0  0.0   7224  2944 pts/6    R+   21:03   0:00 ps aux
bash-5.1$ 
exit
❯ flatpak enter 2219558800 /bin/bash
bash-5.1$ ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ratijas        1  0.0  0.0   3148  1152 ?        S    16:06   0:00 bwrap --args 40 /app/bin/element
ratijas        2  0.0  0.0   7708  1664 ?        S    16:06   0:00 /bin/bash /app/bin/element
ratijas        3  0.5  0.8 1177638940 135556 ?   SLl  16:06   1:41 /app/Element/element-desktop --enable-features=WebRTCPipeWireCapturer
ratijas        6  0.0  0.0   5776  1408 ?        S    16:06   0:00 cat
ratijas        7  0.0  0.0   5776  1408 ?        S    16:06   0:00 cat
ratijas       11  0.0  0.2 33782004 38656 ?      S    16:06   0:00 /app/Element/element-desktop --type=zygote --no-zygote-sandbox
ratijas       13  0.0  0.0      0     0 ?        Z    16:06   0:00 [zypak-sandbox] <defunct>
ratijas       16  0.0  0.0   3148  1280 ?        S    16:06   0:00 bwrap --args 40 /app/bin/zypak-helper child - /app/Element/element-desktop --type=zygote
ratijas       17  0.0  0.2 33784380 43520 ?      S    16:06   0:00 /app/Element/element-desktop --type=zygote
ratijas       52  0.2  0.3 33848236 58776 ?      Sl   16:06   0:36 /app/Element/element-desktop --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --ser
ratijas       72  2.0  1.9 1190042736 313312 ?   Sl   16:06   6:04 /app/Element/element-desktop --type=renderer --enable-crash-reporter=c2493621-53db-4c47-b793-81c24740e514,no_c
ratijas       93  1.6  0.4 33957612 65388 ?      Sl   16:06   5:00 /app/Element/element-desktop --type=gpu-process --enable-crash-reporter=c2493621-53db-4c47-b793-81c24740e514,n
ratijas      653  0.0  0.3 33900132 62028 ?      Sl   17:22   0:01 /app/Element/element-desktop --type=utility --utility-sub-type=audio.mojom.AudioService --lang=en-US --service
ratijas     1833  0.0  0.0   4896  3712 pts/6    S    21:04   0:00 /bin/bash
ratijas     1834  0.0  0.0   7224  2944 pts/6    R+   21:04   0:00 ps aux
bash-5.1$ 


Now, how do we end up using conteinerazied PID to slap an icon onto a host process…

By the way, reproducible on both Plasma 5.27 and master. The code hasn't changed significantly in years or even decades.
Comment 3 ratijas 2023-08-26 18:27:53 UTC
Related: Flatpak bug report "KDE: Shared _NET_WM_PID results in incorrect audio indicator" https://github.com/flatpak/flatpak/issues/1523

Resolved as #wontfix by flatpak :-\

See also: BUG 392385

I verified via xprop that WM_CLIENT_MACHINE property is identical for containerized and host-native applications, which was the only hope to distinguish windows of Flatpak apps. I wonder if Flatpak could possibly hijack X11 connection socket and override those two properties for server.
Comment 4 Christoph Cullmann 2024-09-23 20:59:57 UTC
ksysguard is no longer maintained, in Plasma 6 there is the Plasma system monitor for this task.

If your issue still happens with the Plasma 6 replacement, please re-open and we can move this bug to the new product, thanks!