https://bugs.kde.org/show_bug.cgi?id=400610

            Bug ID: 400610
           Summary: Application crashes with SIGBUS if XDG_CACHE_HOME is
                    too small (or maybe out of space)
           Product: frameworks-kcoreaddons
           Version: unspecified
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: general
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: ---

Qt application crashes with SIGBUS if XDG_CACHE_HOME is too small

We were able to track down the problem to:
- Package: kde-frameworks/kcoreaddons-5.51.0
- File: src/lib/caching/kshareddatacache.cpp
- Function: void mapSharedMemory()
- Lines: 1051 - 1053
- Code: 
  if (file.open(QIODevice::ReadWrite) &&
    (file.size() >= size ||
      (file.resize(size) && ensureFileAllocated(file.handle(), size)))) {

STEPS TO REPRODUCE
1) Create a small filesystem (as root): mount -t tmpfs -o size=30k tmpfs /mnt

The size seems to depend on the system. If the value in '-o size=' is too small
or too high, you won't get a SIGBUS crash. 30k works on my machine.

2) Create a small test program (as suggested by user "mv")

File a.cc:
  #include <QApplication>
  #include <qframe.h>

  int main(int argc, char ** argv) {
   QApplication a(argc,argv);
   QFrame *view = new QFrame();
   view->show();
   a.connect(&a,SIGNAL(lastWindowClosed()),&a,SLOT(quit()));
   return a.exec();
  }     

File: a.pro     
  TARGET = a
  SOURCES = a.cc
  QT += widgets 

3) Compile the program and run it:

  qmake && make
  XDG_CACHE_HOME=/mnt ./a

4) The program will crash with SIGBUS

5) You can get more details using strace:

  XDG_CACHE_HOME=/mnt strace -o /tmp/strace-log -f ./a

6) strace-log shows:

  1500 openat(AT_FDCWD, "/mnt/icon-cache.kcache", O_RDWR|O_CREAT|O_CLOEXEC,
0666) = 9
  1500 statx(9, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL,
{stx_mask=STATX_BASIC_STATS, stx_attributes=0, stx_mode=S_IFREG|0640,
stx_size=0, ...}) = 0
  1500 lseek(9, 0, SEEK_CUR)             = 0
  1500 ftruncate(9, 10547304)            = 0
  1500 fallocate(9, 0, 0, 10547304)      = -1 ENOSPC (No space left on device)
  1500 mmap(NULL, 10547304, PROT_READ|PROT_WRITE, MAP_SHARED, 9, 0) =
0x7f71484df000   
  1500  --- SIGBUS {si_signo=SIGBUS, si_code=BUS_ADRERR,
si_addr=0x7f71484e3020} --- 

The mmap should have stopped with an error message after fallocate, since this
function failed. But the error was ignored and the program continued with an
mmap. A subsequent memory access to the mmaped memory failed with SIGBUS.  

7) The lines in the strace log correspond to lines 1051 - 1053 of
src/lib/caching/kshareddatacache.cpp

OBSERVED RESULT: SIGBUS

EXPECTED RESULT: Error message stating that XDG_CACHE_HOME is out of space,
followed by a regular abort() or exit().

SOFTWARE VERSIONS
- OS: Gentoo Linux
- KDE Plasma Version: 5.14.2
- KDE Frameworks Version: 5.51.0
- Qt Version: 5.11.2

ADDITIONAL INFORMATION
- Look at https://forums.gentoo.org/viewtopic-t-1087812.html for additional
information.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to