Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/dev/shm permission denied on shared memory file with resolution #514

Open
hgkamath opened this issue Feb 25, 2024 · 2 comments
Open

/dev/shm permission denied on shared memory file with resolution #514

hgkamath opened this issue Feb 25, 2024 · 2 comments
Labels
dependencies Pull requests that update a dependency file

Comments

@hgkamath
Copy link

hgkamath commented Feb 25, 2024

Description

NotepadNext does not start with QSharedMemory::PermissionDenied message.
Problem may have happened because program was first run as root before closing and re-running as regular user.
Resolution included below.

More Details

Linux Fedora-39
dnf copr enable birkch/NotepadNext
dnf install NotepadNext
package installed: NotepadNext-0.7-1.fc39.x86_64

I first ran NotepadNext as root, and it worked fine bringing up the window.
Then i closed window, and re-ran NotepadNext as regular user, but when running as user it fails to start and gives the error in the terminal. If started via the gui app menu, it fails silently.

gana@sirius:/var$ NotepadNext 
[     0.118] C: SingleApplication: Unable to attach to shared memory block.
[     0.118] C: SingleApplication:  QSharedMemory::PermissionDenied "QSharedMemory::attach (shm_open): permission denied"

strace output

gana@sirius:/var$ strace NotepadNext 
:
:
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=16000000}, 0x7fff77a1be20) = 0
getrandom("\xd1\x9e\xe5\x6a\x83\xaa\x42\x71", 8, GRND_NONBLOCK) = 8
newfstatat(AT_FDCWD, "/dev/shm/sem.1EUIzf", 0x7fff77a1b800, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/dev/shm/sem.1EUIzf", O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC, 0600) = 26
write(26, "\1\0\0\0\0\0\0\0\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 32, PROT_READ|PROT_WRITE, MAP_SHARED, 26, 0) = 0x7fd8f43d3000
link("/dev/shm/sem.1EUIzf", "/dev/shm/sem.NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=") = 0
newfstatat(26, "", {st_mode=S_IFREG|0600, st_size=32, ...}, AT_EMPTY_PATH) = 0
unlink("/dev/shm/sem.1EUIzf")           = 0
close(26)                               = 0
openat(AT_FDCWD, "/dev/shm/NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=", O_RDWR|O_NOFOLLOW|O_CLOEXEC) = -1 EACCES (Permission denied)
munmap(0x7fd8f43d3000, 32)              = 0
unlink("/dev/shm/sem.NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=") = 0
getrandom("\x33\xe4\x02\x9e\xee\x98\xaf\xde", 8, GRND_NONBLOCK) = 8
newfstatat(AT_FDCWD, "/dev/shm/sem.Nizx9r", 0x7fff77a1b7f0, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/dev/shm/sem.Nizx9r", O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC, 0600) = 26
write(26, "\1\0\0\0\0\0\0\0\200\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32) = 32
mmap(NULL, 32, PROT_READ|PROT_WRITE, MAP_SHARED, 26, 0) = 0x7fd8f43d3000
link("/dev/shm/sem.Nizx9r", "/dev/shm/sem.NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=") = 0
newfstatat(26, "", {st_mode=S_IFREG|0600, st_size=32, ...}, AT_EMPTY_PATH) = 0
unlink("/dev/shm/sem.Nizx9r")           = 0
close(26)                               = 0
openat(AT_FDCWD, "/dev/shm/NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=", O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC, 0600) = -1 EEXIST (File exists)
openat(AT_FDCWD, "/dev/shm/NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=", O_RDWR|O_NOFOLLOW|O_CLOEXEC) = -1 EACCES (Permission denied)
openat(AT_FDCWD, "/dev/tty", O_RDONLY|O_CLOEXEC) = 26
close(26)                               = 0
write(2, "[     0.260] C: SingleApplicatio"..., 76[     0.260] C: SingleApplication: Unable to attach to shared memory block.
) = 76
write(2, "[     0.260] C: SingleApplicatio"..., 122[     0.260] C: SingleApplication:  QSharedMemory::PermissionDenied "QSharedMemory::attach (shm_open): permission denied"
) = 122
munmap(0x7fd8f43d3000, 32)              = 0
unlink("/dev/shm/sem.NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q=") = 0
write(4, "\1\0\0\0\0\0\0\0", 8)         = 8
futex(0x562204b81d90, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x562204b81d40, FUTEX_WAKE_PRIVATE, 1) = 0
getpid()                                = 290191
getpid()                                = 290191
exit_group(1)                           = ?
+++ exited with 1 +++

Resolution

When I had run NotepadNext as root, a file was created in /dev/shm with root ownership and permissions

oot@sirius:/dev/shm# ls -la
total 8
drwxrwxrwt.  2 root root   80 Feb 25 18:35  .
drwxr-xr-x. 22 root root 5060 Feb 23 20:56  ..
-rw-------.  1 root root  152 Feb 25 15:28 'NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q='

Delete the file, and next time NotepadNext when run as regular user, will recreate the file with regular user ownership and permissions and it will run fine.
mv-ing the file (and then later delete when problem resolved, which is what I really did at first) or chown-ing the file back to the regular user also will work

root@sirius:/dev/shm# ls -la
total 4
drwxrwxrwt.  2 root root   60 Feb 25 18:35  .
drwxr-xr-x. 22 root root 5060 Feb 23 20:56  ..
-rw-------.  1 gana gana  152 Feb 25 18:34 'NQd7ehOB89VHFdGSy2fPICYNWen1ylD7GZQtd_a754Q='

Questions:

Q1) should NotepadNext, when run as root user, check to see if the desktop belongs to a user and create the shm-file with ownership of user, or maybe not?
Q2) should NotepadNext give a different filename to the shm-file per-User-per-Desktop in order to prevent name collision?
Q3) should NotepadNext give a better error message to inform the user as to how to correct the problem?
Q4) should NotepadNext delete the shm-file after the last user-process using it exits?
Q5) should the shm-file's filename have the string NotepadNext in it, in order to clue the user that the file was created by NotepadNext. At first, I was hesitant to delete the file as I did not know if it was created by some other process. The ls -l timestamp strongly hinted that the shm-file might have been freshly created by NotepadNext.

@hgkamath hgkamath changed the title /dev/shm permission denied on shared memory with reolution /dev/shm permission denied on shared memory with resolution Feb 25, 2024
@hgkamath hgkamath changed the title /dev/shm permission denied on shared memory with resolution /dev/shm permission denied on shared memory file with resolution Feb 25, 2024
@dail8859
Copy link
Owner

Thanks for opening this issue. The unfortunate short answer to all this is...I don't know :)

The SingleApplication library is what is used to prevent multiple application instances which is what is using the shared memory. It would be best to open an issue with that repository. I know there was some changes with Qt6.6, and that project is aware of it. I'm not sure what version of Qt your package is using since only the flatpak and appimage are the only supported distributions.

@dail8859 dail8859 added the dependencies Pull requests that update a dependency file label Feb 26, 2024
@hgkamath
Copy link
Author

hgkamath commented Feb 27, 2024

Thank you for your much appreciated contributions to NotepadNext ! .

So it seems the bug is to be handled in an upstream project.
itay-grudev says itay-grudev/SingleApplication#190 (comment)

I am working on a new implementation that doesn't use QSharedMemory but it's not finished yet.

I understand, in which case we must wait until its fixed in the upstream SingleApplication Library.
Also, here-in letting distribution fedora copr builder birkch/h3o66 (@h3o66) know about this issue.
(I hope this notifies, but I'm not sure how github handles mentioned-users, I don't see user added to the the issue's participants/notified subscriber list)

Unless flatpak and appimage, in a different way manage shared /dev/shm file creation per-User-per-Desktop, chances are that the bug might affect them too, unless confirmed not to. Steps to try reproduce.

  • first delete any existing /dev/shm file that may be used by NotepadNext-app
  • run NotepadNext-app as root. Close NotepadNext-app
  • check shm file in /dev/shm and check is created with owner-rw-only permissions as root user
  • try run NotepadNext-app as unprivileged user
  • NotepadNext-app should crash on start

The binary is built against Qt6 using the system libraries that ships with fedora releases, the current version as of 20240227 being 6.6.2-1.fc39.x86_64 .

root@sirius:/dev/shm# ldd /usr/bin/NotepadNext 
	linux-vdso.so.1 (0x00007ffc8ac72000)
	libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f752e7e5000)
	libQt6PrintSupport.so.6 => /lib64/libQt6PrintSupport.so.6 (0x00007f752e764000)
	libQt6Widgets.so.6 => /lib64/libQt6Widgets.so.6 (0x00007f752da00000)
	libQt6Gui.so.6 => /lib64/libQt6Gui.so.6 (0x00007f752d000000)
	libQt6Network.so.6 => /lib64/libQt6Network.so.6 (0x00007f752ce35000)
	libQt6Core5Compat.so.6 => /lib64/libQt6Core5Compat.so.6 (0x00007f752e707000)
	libQt6Core.so.6 => /lib64/libQt6Core.so.6 (0x00007f752c600000)
	libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f752c200000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f752cd54000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f752e6e1000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f752c01e000)
	libXau.so.6 => /lib64/libXau.so.6 (0x00007f752e6db000)
	libEGL.so.1 => /lib64/libEGL.so.1 (0x00007f752e6c7000)
	libfontconfig.so.1 => /lib64/libfontconfig.so.1 (0x00007f752d9b1000)
	libX11.so.6 => /lib64/libX11.so.6 (0x00007f752c4b9000)
	libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f752bed4000)
	libQt6DBus.so.6 => /lib64/libQt6DBus.so.6 (0x00007f752cc87000)
	libxkbcommon.so.0 => /lib64/libxkbcommon.so.0 (0x00007f752e1b7000)
	libGLX.so.0 => /lib64/libGLX.so.0 (0x00007f752d97e000)
	libOpenGL.so.0 => /lib64/libOpenGL.so.0 (0x00007f752d953000)
	libpng16.so.16 => /lib64/libpng16.so.16 (0x00007f752c480000)
	libharfbuzz.so.0 => /lib64/libharfbuzz.so.0 (0x00007f752bdc6000)
	libfreetype.so.6 => /lib64/libfreetype.so.6 (0x00007f752bcf6000)
	libz.so.1 => /lib64/libz.so.1 (0x00007f752c466000)
	libzstd.so.1 => /lib64/libzstd.so.1 (0x00007f752bc3a000)
	libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f752bbe4000)
	libbrotlidec.so.1 => /lib64/libbrotlidec.so.1 (0x00007f752d945000)
	libproxy.so.1 => /lib64/libproxy.so.1 (0x00007f752d940000)
	libcrypto.so.3 => /lib64/libcrypto.so.3 (0x00007f752b600000)
	libicuuc.so.73 => /lib64/libicuuc.so.73 (0x00007f752b200000)
	libicui18n.so.73 => /lib64/libicui18n.so.73 (0x00007f752ae00000)
	libsystemd.so.0 => /lib64/libsystemd.so.0 (0x00007f752baf1000)
	libdouble-conversion.so.3 => /lib64/libdouble-conversion.so.3 (0x00007f752badb000)
	libb2.so.1 => /lib64/libb2.so.1 (0x00007f752c45a000)
	libpcre2-16.so.0 => /lib64/libpcre2-16.so.0 (0x00007f752b573000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f752e82d000)
	libGLdispatch.so.0 => /lib64/libGLdispatch.so.0 (0x00007f752b4bb000)
	libxml2.so.2 => /lib64/libxml2.so.2 (0x00007f752ac8c000)
	libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007f752b420000)
	libdbus-1.so.3 => /lib64/libdbus-1.so.3 (0x00007f752b1ab000)
	libXext.so.6 => /lib64/libXext.so.6 (0x00007f752b40c000)
	libgraphite2.so.3 => /lib64/libgraphite2.so.3 (0x00007f752b18a000)
	libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f752b176000)
	libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f752abb3000)
	libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f752b15e000)
	libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f752b157000)
	libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f752aba3000)
	libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f752b150000)
	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f752ab92000)
	libbrotlicommon.so.1 => /lib64/libbrotlicommon.so.1 (0x00007f752ab6f000)
	libpxbackend-1.0.so => /usr/lib64/libproxy/libpxbackend-1.0.so (0x00007f752ab60000)
	libgobject-2.0.so.0 => /lib64/libgobject-2.0.so.0 (0x00007f752ab00000)
	libicudata.so.73 => /lib64/libicudata.so.73 (0x00007f7528c00000)
	libcap.so.2 => /lib64/libcap.so.2 (0x00007f752aaf6000)
	liblz4.so.1 => /lib64/liblz4.so.1 (0x00007f752aad4000)
	liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f752aaa1000)
	libgomp.so.1 => /lib64/libgomp.so.1 (0x00007f7528bad000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f7528b80000)
	libcurl.so.4 => /lib64/libcurl.so.4 (0x00007f7528acc000)
	libgio-2.0.so.0 => /lib64/libgio-2.0.so.0 (0x00007f75288f6000)
	libduktape.so.207 => /lib64/libduktape.so.207 (0x00007f75288aa000)
	libffi.so.8 => /lib64/libffi.so.8 (0x00007f752aa91000)
	libnghttp2.so.14 => /lib64/libnghttp2.so.14 (0x00007f752887f000)
	libidn2.so.0 => /lib64/libidn2.so.0 (0x00007f752885d000)
	libssh.so.4 => /lib64/libssh.so.4 (0x00007f75287ea000)
	libpsl.so.5 => /lib64/libpsl.so.5 (0x00007f75287d6000)
	libssl.so.3 => /lib64/libssl.so.3 (0x00007f7528733000)
	libldap.so.2 => /lib64/libldap.so.2 (0x00007f75286ce000)
	liblber.so.2 => /lib64/liblber.so.2 (0x00007f75286bc000)
	libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x00007f75286b5000)
	libmount.so.1 => /lib64/libmount.so.1 (0x00007f7528664000)
	libunistring.so.5 => /lib64/libunistring.so.5 (0x00007f75284b4000)
	libevent-2.1.so.7 => /lib64/libevent-2.1.so.7 (0x00007f752845c000)
	libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007f752843d000)
	libblkid.so.1 => /lib64/libblkid.so.1 (0x00007f7528401000)
	libcrypt.so.2 => /lib64/libcrypt.so.2 (0x00007f75283c8000)

root@sirius:/dev/shm# rpm -qa | grep -Ei Qt  | sort
adwaita-qt4-1.1.3-4.fc33.x86_64
adwaita-qt5-1.4.2-5.fc39.x86_64
adwaita-qt6-1.4.2-5.fc39.x86_64
dbusmenu-qt-0.9.3-0.32.20160218.fc39.x86_64
dbusmenu-qt5-0.9.3-0.32.20160218.fc39.x86_64
gstreamer1-plugins-good-qt-1.22.9-3.fc39.x86_64
gstreamer1-plugins-good-qt6-1.22.9-3.fc39.x86_64
ibus-qt-1.3.4-8.fc39.x86_64
libadwaita-qt5-1.4.2-5.fc39.x86_64
libadwaita-qt6-1.4.2-5.fc39.x86_64
lxqt-wallet-3.2.2-6.fc39.x86_64
polkit-qt5-1-0.114.0-7.fc39.x86_64
qadwaitadecorations-qt5-0.1.4-2.fc39.x86_64
qadwaitadecorations-qt6-0.1.4-2.fc39.x86_64
qca-qt5-2.3.6-2.fc39.x86_64
qca-qt5-ossl-2.3.6-2.fc39.x86_64
qgnomeplatform-qt5-0.9.2-10.fc39.x86_64
qgnomeplatform-qt6-0.9.2-10.fc39.x86_64
qt-4.8.7-74.fc39.x86_64
qt5-qtbase-5.15.12-5.fc39.x86_64
qt5-qtbase-common-5.15.12-5.fc39.noarch
qt5-qtbase-gui-5.15.12-5.fc39.x86_64
qt5-qtdeclarative-5.15.12-1.fc39.x86_64
qt5-qtgraphicaleffects-5.15.12-1.fc39.x86_64
qt5-qtimageformats-5.15.12-1.fc39.x86_64
qt5-qtmultimedia-5.15.12-1.fc39.x86_64
qt5-qtquickcontrols2-5.15.12-1.fc39.x86_64
qt5-qtquickcontrols-5.15.12-1.fc39.x86_64
qt5-qtspeech-5.15.12-1.fc39.x86_64
qt5-qtspeech-speechd-5.15.12-1.fc39.x86_64
qt5-qtsvg-5.15.12-1.fc39.x86_64
qt5-qttools-common-5.15.12-1.fc39.noarch
qt5-qttools-libs-help-5.15.12-1.fc39.x86_64
qt5-qttranslations-5.15.12-1.fc39.noarch
qt5-qtwayland-5.15.12-2.fc39.x86_64
qt5-qtwebsockets-5.15.12-1.fc39.x86_64
qt5-qtx11extras-5.15.12-1.fc39.x86_64
qt5-qtxmlpatterns-5.15.12-1.fc39.x86_64
qt5-srpm-macros-5.15.12-1.fc39.noarch
qt6-qt5compat-6.6.2-1.fc39.x86_64
qt6-qtbase-6.6.2-1.fc39.x86_64
qt6-qtbase-common-6.6.2-1.fc39.noarch
qt6-qtbase-gui-6.6.2-1.fc39.x86_64
qt6-qtdeclarative-6.6.2-1.fc39.x86_64
qt6-qtmultimedia-6.6.2-1.fc39.x86_64
qt6-qtshadertools-6.6.2-1.fc39.x86_64
qt6-qtsvg-6.6.2-1.fc39.x86_64
qt6-qttranslations-6.6.2-1.fc39.noarch
qt6-qtwayland-6.6.2-1.fc39.x86_64
qt6-srpm-macros-6.6.2-1.fc39.noarch
qt-common-4.8.7-74.fc39.noarch
qt-heif-image-plugin-0.3.4-1.fc39.x86_64
qt-settings-39.1-1.fc39.noarch
qt-x11-4.8.7-74.fc39.x86_64
sni-qt-0.2.7-0.13.20170217.fc39.x86_64

root@sirius:/dev/shm# rpm -qil NotepadNext
Name        : NotepadNext
Version     : 0.7
Release     : 1.fc39
Architecture: x86_64
Install Date: Sun 25 Feb 2024 03:28:46 PM IST
Group       : Unspecified
Size        : 5563473
License     : GPLv3
Signature   : RSA/SHA256, Sun 25 Feb 2024 07:28:13 AM IST, Key ID 0e867c75e06fb945
Source RPM  : NotepadNext-0.7-1.fc39.src.rpm
Build Date  : Sun 25 Feb 2024 07:20:45 AM IST
Build Host  : copr-hv-x86-64-03-prod-05618753-20240225-013915
Vendor      : Fedora Copr - user birkch
URL         : https://github.com/dail8859/NotepadNext
Summary     : A cross-platform, reimplementation of Notepad++
Description :
A cross-platform, reimplementation of Notepad++.
/usr/bin/NotepadNext
/usr/lib/.build-id
/usr/lib/.build-id/73
/usr/lib/.build-id/73/74815c660f105f0a9870db32ea9a0b9ac33c3e
/usr/share/applications/NotepadNext.desktop
/usr/share/doc/NotepadNext
/usr/share/doc/NotepadNext/README.md
/usr/share/doc/NotepadNext/doc
/usr/share/doc/NotepadNext/doc/Building.md
/usr/share/doc/NotepadNext/doc/Create Release.md
/usr/share/doc/NotepadNext/doc/Translation.md
/usr/share/doc/NotepadNext/doc/Update Scintilla.md
/usr/share/doc/NotepadNext/doc/screenshot.png
/usr/share/doc/NotepadNext/doc/screenshot_linux.png
/usr/share/icons/hicolor/scalable/apps/NotepadNext.svg
/usr/share/icons/hicolor/scalable/mimetypes/NotepadNext.svg
/usr/share/licenses/NotepadNext
/usr/share/licenses/NotepadNext/LICENSE
/usr/share/metainfo/com.github.dail8859.NotepadNext.metainfo.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

2 participants