Bug 482668 - Crash in Energy Savings KCM when configured power action is newly unsupported
Summary: Crash in Energy Savings KCM when configured power action is newly unsupported
Status: RESOLVED FIXED
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_powerdevil (show other bugs)
Version: 6.0.1
Platform: Arch Linux Linux
: NOR crash
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords: qt6
: 482673 484566 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-03-07 09:07 UTC by Tom Englund
Modified: 2024-03-27 23:38 UTC (History)
7 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Englund 2024-03-07 09:07:14 UTC
SUMMARY
#0  0x00007ffff4a951cb in pthread_kill@@GLIBC_2.34 () at /usr/lib/libc.so.6
#1  0x00007ffff4a40f64 in raise () at /usr/lib/libc.so.6
#2  0x00007ffff7b6443f in KCrash::defaultCrashHandler (sig=11) at /usr/src/debug/kcrash/kcrash-6.0.0/src/kcrash.cpp:586
#3  0x00007ffff4a41000 in <signal handler called> () at /usr/lib/libc.so.6
#4  std::__atomic_base<int>::fetch_add (__m=std::memory_order_acq_rel, __i=1, this=0x7, this=<optimized out>, __i=<optimized out>, __m=<optimized out>)
    at /usr/include/c++/13.2.1/bits/atomic_base.h:633
#5  QAtomicOps<int>::ref<int> (_q_value=<error reading variable: Cannot access memory at address 0x7>, _q_value=<optimized out>)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/thread/qatomic_cxx11.h:258
#6  QBasicAtomicInteger<int>::ref (this=0x7, this=<optimized out>) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/thread/qbasicatomic.h:49
#7  QArrayData::ref (this=0x7, this=<optimized out>) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/tools/qarraydata.h:52
#8  QArrayDataPointer<char16_t>::ref (this=0x7fffffff3b30, this=<optimized out>) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/tools/qarraydatapointer.h:412
#9  QArrayDataPointer<char16_t>::QArrayDataPointer (other=..., this=0x7fffffff3b30, this=<optimized out>, other=<optimized out>)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/tools/qarraydatapointer.h:40
#10 QString::QString (other=..., this=0x7fffffff3b30, this=<optimized out>, other=<optimized out>) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/text/qstring.h:1107
#11 QVariant::Private::Private<QString> (t=..., this=0x7fffffff3b30) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/kernel/qvariant_p.h:98
#12 QVariant::QVariant (this=0x7fffffff3b30, val=..., this=<optimized out>, val=<optimized out>) at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.2/src/corelib/kernel/qvariant.cpp:946
#13 0x00007fffd21999c6 in PowerButtonActionModel::data (this=<optimized out>, index=<optimized out>, role=<optimized out>)
    at /usr/src/debug/powerdevil/powerdevil-6.0.1/kcmodule/common/PowerButtonActionModel.cpp:113
#14 0x00007ffff5320e52 in QAbstractItemModel::qt_static_metacall (_o=<optimized out>, _c=<optimized out>, _id=<optimized out>, _a=0x7fffffff3e18)
    at /usr/src/debug/qt6-base/build/src/corelib/Core_autogen/include/moc_qabstractitemmodel.cpp:1078
#15 0x00007ffff5321d33 in QAbstractItemModel::qt_metacall (_a=0x7fffffff3e18, _id=38, _c=QMetaObject::InvokeMetaMethod, this=0x555557d5a360)
    at /usr/src/debug/qt6-base/build/src/corelib/Core_autogen/include/moc_qabstractitemmodel.cpp:1307
#16 QAbstractListModel::qt_metacall (this=0x555557d5a360, _c=QMetaObject::InvokeMetaMethod, _id=<optimized out>, _a=0x7fffffff3e18)
    at /usr/src/debug/qt6-base/build/src/corelib/Core_autogen/include/moc_qabstractitemmodel.cpp:1597
#17 0x00007ffff62d7d64 in QQmlObjectOrGadget::metacall (this=0x7fffffff40d0, type=QMetaObject::InvokeMetaMethod, index=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/qt6-declarative/qtdeclarative-everywhere-src-6.6.2/src/qml/qml/qqmlobjectorgadget.cpp:14
#18 0x00007ffff61b742f in QV4::CallMethod
    (callType=<optimized out>, callArgs=<optimized out>, engine=<optimized out>, argTypes=<optimized out>, argCount=<optimized out>, returnType=..., index=<optimized out>, object=<optimized out>) at /usr/include/qt6/QtCore/qvarlengtharray.h:84
#19 QV4::CallPrecise (object=..., data=<optimized out>, engine=<optimized out>, engine@entry=0x555556a1fa30, callArgs=<optimized out>, 
    callArgs@entry=0x7fffd1be88c0, callType=callType@entry=QMetaObject::InvokeMetaMethod)
    at /usr/src/debug/qt6-declarative/qtdeclarative-everywhere-src-6.6.2/src/qml/jsruntime/qv4qobjectwrapper.cpp:1850
#20 0x00007ffff61bb239 in operator() (__closure=<optimized out>) at /usr/src/debug/qt6-declarative/qtdeclarative-everywhere-src-6.6.2/src/qml/jsruntime/qv4qobjectwrapper.cpp:2753
#21 operator()<QV4::QObjectMethod::callInternal(const QV4::Value*, const QV4::Value*, int) const::<lambda()> > (call=<optimized out>, __closure=<synthetic pointer>)
    at /usr/src/debug/qt6-declarative/qtdeclarative-everywhere-src-6.6.2/src/qml/jsruntime/qv4qobjectwrapper.cpp:2730
#22 QV4::QObjectMethod::callInternal (this=0x7fffffff4190, thisObject=<optimized out>, argv=0x7fffd1be8860, argc=2)
    at /usr/src/debug/qt6-declarative/qtdeclarative-everywhere-src-6.6.2/src/qml/jsruntime/qv4qobjectwrapper.cpp:2753
#23 0x00007ffff61cef61 in QV4::Runtime::CallPropertyLookup::call (engine=0x555556a1fa30, base=..., index=<optimized out>, argv=0x7fffd1be8860, argc=2)
    at /usr/src/debug/qt6-declarative/qtdeclarative-everywhere-src-6.6.2/src/qml/jsruntime/qv4runtime.cpp:1511


STEPS TO REPRODUCE
1. open system settings
2. to to Energy Saving
3. press Advanced Power Settings

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.0.1
KDE Frameworks Version: 6.0.0
Qt Version: 6.6.2
Kernel Version: 6.7.7-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 32 × 13th Gen Intel® Core™ i9-13900HX
Memory: 31,1 GiB of RAM
Graphics Processor: Mesa Intel® Graphics
Manufacturer: LENOVO
Product Name: 82WQ
System Version: Legion Pro 7 16IRX8H
Comment 1 Nate Graham 2024-03-07 19:49:46 UTC
Is this that thing you fixed recently, Jakob?
Comment 2 Jakob Petsovits 2024-03-07 20:09:59 UTC
(In reply to Nate Graham from comment #1)
> Is this that thing you fixed recently, Jakob?

Possibly, but the reproduction steps don't involve *closing* navigating away from the Energy Saving KCM (by closing System Setting, or by trying to open another settings module), which was a crucial step in Bug 481045.

Tom, could you confirm that merely opening Advanced Power Settings is causing the crash? i.e. you don't even get to see the settings form with battery levels and stuff?
Comment 3 Tom Englund 2024-03-07 20:12:56 UTC
(In reply to Jakob Petsovits from comment #2)
> (In reply to Nate Graham from comment #1)
> > Is this that thing you fixed recently, Jakob?
> 
> Possibly, but the reproduction steps don't involve *closing* navigating away
> from the Energy Saving KCM (by closing System Setting, or by trying to open
> another settings module), which was a crucial step in Bug 481045.
> 
> Tom, could you confirm that merely opening Advanced Power Settings is
> causing the crash? i.e. you don't even get to see the settings form with
> battery levels and stuff?

yeah as fast as i press the button it crashes, no window even slightly starts to appear like its trying to load. just instantly on press
Comment 4 Jakob Petsovits 2024-03-07 20:22:51 UTC
Thanks. That's not a duplicate then, different bug.

The stacktrace indicates that it wants something from PowerButtonActionModel but is apparently not finding it there, and crashes instead when trying to access it. The only use of PowerButtonActionModel on the Advanced Settings page is for the critical-battery action combo box. Which... hm, here's an idea

In your $HOME/.config/powerdevilrc file, is there a line that goes like,

BatteryCriticalAction=(some value)

If so, could you please paste that line? And also try if it still crashes when you delete it and save the config file?
Comment 5 Tom Englund 2024-03-07 20:36:49 UTC
(In reply to Jakob Petsovits from comment #4)
> Thanks. That's not a duplicate then, different bug.
> 
> The stacktrace indicates that it wants something from PowerButtonActionModel
> but is apparently not finding it there, and crashes instead when trying to
> access it. The only use of PowerButtonActionModel on the Advanced Settings
> page is for the critical-battery action combo box. Which... hm, here's an
> idea
> 
> In your $HOME/.config/powerdevilrc file, is there a line that goes like,
> 
> BatteryCriticalAction=(some value)
> 
> If so, could you please paste that line? And also try if it still crashes
> when you delete it and save the config file?

[BatteryManagement]
BatteryCriticalAction=1

and yeah removing it makes it work again
Comment 6 Jakob Petsovits 2024-03-07 21:05:59 UTC
(In reply to Tom Englund from comment #5)
> [BatteryManagement]
> BatteryCriticalAction=1
> 
> and yeah removing it makes it work again

Okay, nice. "1" is the value for "Sleep". What it looks like to me is that your system does not actually support the Sleep action (as in PowerManagement::canSuspend()), so it's missing from the list of combo box actions but the UI still tries to find and set it. One instance I could see this happening is if one copies an existing laptop Arch installation (with that setting already set) to a new drive that powers e.g. a PC without "Sleep" functionality. Or maybe "Sleep" was the default a long time ago and written to the config file before we used KConfigXT even for global settings (i.e. before my time here).

Either way, we should probably do something more graceful with unsupported power actions than just crash. Although I'm not quite sure how to deal with that in the UI.

For anyone to reproduce a crash like this, one can add this to their ~/.config/powerdevilrc:

[BatteryManagement]
BatteryCriticalAction=16

which is an action that generally exists (PromptLogoutDialog) but does not exist in the option list for the critical battery action combobox.
Comment 7 Tom Englund 2024-03-07 21:13:43 UTC
(In reply to Jakob Petsovits from comment #6)
> (In reply to Tom Englund from comment #5)
> > [BatteryManagement]
> > BatteryCriticalAction=1
> > 
> > and yeah removing it makes it work again
> 
> Okay, nice. "1" is the value for "Sleep". What it looks like to me is that
> your system does not actually support the Sleep action (as in
> PowerManagement::canSuspend()), so it's missing from the list of combo box
> actions but the UI still tries to find and set it. One instance I could see
> this happening is if one copies an existing laptop Arch installation (with
> that setting already set) to a new drive that powers e.g. a PC without
> "Sleep" functionality. Or maybe "Sleep" was the default a long time ago and
> written to the config file before we used KConfigXT even for global settings
> (i.e. before my time here).
> 
> Either way, we should probably do something more graceful with unsupported
> power actions than just crash. Although I'm not quite sure how to deal with
> that in the UI.
> 
> For anyone to reproduce a crash like this, one can add this to their
> ~/.config/powerdevilrc:
> 
> [BatteryManagement]
> BatteryCriticalAction=16
> 
> which is an action that generally exists (PromptLogoutDialog) but does not
> exist in the option list for the critical battery action combobox.

I think its because i disabled sleep in systemd confs, its half broken on my Nvidia dgpu and the kids have fingered that fn + sleep button more then once heh
Comment 8 Jakob Petsovits 2024-03-07 21:30:36 UTC
This issue would also affect regular profile settings btw. It's somewhat mitigated by the fact that many people use default values for their power actions, and in PowerDevil on Plasma 6 we don't have a config file line for settings with default values. So this will only occur if the power action was explicitly set to a non-default value before, and is now unsupported for whatever reason.

I figure what might work is a warning message or dialog that pops up if we can't find a configured power action in an option list anymore. Something like,

"The action you had configured to occur [after a period of inactivity | when the power button is pressed | when the laptop lid is closed | when the battery reaches a critical level] is not supported on your system. Please review your settings and select a different one."
Comment 9 Jakob Petsovits 2024-03-07 22:25:24 UTC
*** Bug 482673 has been marked as a duplicate of this bug. ***
Comment 10 Tom Englund 2024-03-08 08:09:14 UTC
(In reply to Jakob Petsovits from comment #6)
> (In reply to Tom Englund from comment #5)
> > [BatteryManagement]
> > BatteryCriticalAction=1
> > 
> > and yeah removing it makes it work again
> 
> Okay, nice. "1" is the value for "Sleep". What it looks like to me is that
> your system does not actually support the Sleep action (as in
> PowerManagement::canSuspend()), so it's missing from the list of combo box
> actions but the UI still tries to find and set it. One instance I could see
> this happening is if one copies an existing laptop Arch installation (with
> that setting already set) to a new drive that powers e.g. a PC without
> "Sleep" functionality. Or maybe "Sleep" was the default a long time ago and
> written to the config file before we used KConfigXT even for global settings
> (i.e. before my time here).
> 
> Either way, we should probably do something more graceful with unsupported
> power actions than just crash. Although I'm not quite sure how to deal with
> that in the UI.
> 
> For anyone to reproduce a crash like this, one can add this to their
> ~/.config/powerdevilrc:
> 
> [BatteryManagement]
> BatteryCriticalAction=16
> 
> which is an action that generally exists (PromptLogoutDialog) but does not
> exist in the option list for the critical battery action combobox.

i guess worth mentioning 16 didnt work either, removing the entry the only two options i have is "do nothing and shutdown"
Comment 11 Jakob Petsovits 2024-03-08 08:29:53 UTC
(In reply to Tom Englund from comment #10)
> i guess worth mentioning 16 didnt work either

Sorry yeah, 16 was meant as an example for people who explicitly want to make it crash but don't have your system setup.
Comment 12 Tom Englund 2024-03-08 08:33:27 UTC
(In reply to Jakob Petsovits from comment #11)
> (In reply to Tom Englund from comment #10)
> > i guess worth mentioning 16 didnt work either
> 
> Sorry yeah, 16 was meant as an example for people who explicitly want to
> make it crash but don't have your system setup.

oh i misread your comment "For anyone to reproduce a crash like this" i read it first as "for anyone having a crash like this one can add this to their config " gotta properly read the entire thing before thinking! my mistake. :)
Comment 13 Bug Janitor Service 2024-03-13 05:41:28 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/337
Comment 14 Jakob Petsovits 2024-03-14 03:21:17 UTC
Git commit 8ecf6430ee7a3d3670fd9cb1b6af947f9ac2f352 by Jakob Petsovits.
Committed on 14/03/2024 at 03:19.
Pushed by jpetso into branch 'master'.

kcmodule: Don't crash when a configured button action is unsupported

The bounds check in the data() method of PowerButtonActionModel
and SleepModeModel was incomplete, so passing an invalid index
such as -1 (standard value for "not found") could cause a crash.

For power management settings, a user would run into this crash if
their configuration from powerdevilrc listed a power button action
that's not supported on the current system. For example, a user
may have selected "Sleep" as lid action, but subsequently changed
their systemd configuration to disable suspend-to-RAM because it
caused problems. Or they could have migrated their OS to a new
computer which does not support Sleep.

Fixing this allows us to assign currentIndex declaratively
instead of waiting until Component.onCompleted to (hopefully) find
a valid item in the model.

M  +1    -1    kcmodule/common/PowerButtonActionModel.cpp
M  +1    -1    kcmodule/common/SleepModeModel.cpp
M  +2    -3    kcmodule/profiles/ui/GlobalConfig.qml
M  +8    -12   kcmodule/profiles/ui/ProfileConfig.qml

https://invent.kde.org/plasma/powerdevil/-/commit/8ecf6430ee7a3d3670fd9cb1b6af947f9ac2f352
Comment 15 Jakob Petsovits 2024-03-14 03:32:36 UTC
Git commit aedb2529b31ec9b62ee5a8b3548be848769f4009 by Jakob Petsovits.
Committed on 14/03/2024 at 03:28.
Pushed by jpetso into branch 'Plasma/6.0'.

kcmodule: Don't crash when a configured button action is unsupported

The bounds check in the data() method of PowerButtonActionModel
and SleepModeModel was incomplete, so passing an invalid index
such as -1 (standard value for "not found") could cause a crash.

For power management settings, a user would run into this crash if
their configuration from powerdevilrc listed a power button action
that's not supported on the current system. For example, a user
may have selected "Sleep" as lid action, but subsequently changed
their systemd configuration to disable suspend-to-RAM because it
caused problems. Or they could have migrated their OS to a new
computer which does not support Sleep.

Fixing this allows us to assign currentIndex declaratively
instead of waiting until Component.onCompleted to (hopefully) find
a valid item in the model.


(cherry picked from commit 8ecf6430ee7a3d3670fd9cb1b6af947f9ac2f352)

M  +1    -1    kcmodule/common/PowerButtonActionModel.cpp
M  +1    -1    kcmodule/common/SleepModeModel.cpp
M  +2    -0    kcmodule/profiles/ui/GlobalConfig.qml
M  +8    -0    kcmodule/profiles/ui/ProfileConfig.qml

https://invent.kde.org/plasma/powerdevil/-/commit/aedb2529b31ec9b62ee5a8b3548be848769f4009
Comment 16 Jakob Petsovits 2024-03-16 15:35:52 UTC
Git commit 78415ae0097ad36377b407d3b143589ca8fa8a18 by Jakob Petsovits.
Committed on 16/03/2024 at 15:33.
Pushed by jpetso into branch 'master'.

kcmodule: Revert to binding currentIndex in Component.onCompleted

Commit 8ecf6430 ("Don't crash when a configured button action
is unsupported") caused empty ComboBox selections on initial load.
Turns out `indexOfValue()` can only be used after the
Component.completed() signal is emitted, so a purely declarative
binding worked incorrectly if queried too early by QML.

Therefore, we revert back to assigning a Qt.binding() to
currentIndex in Component.onCompleted.

This commit also adapts PowerProfileModel and its associated
ComboBox in a similar way as the other two models used in this KCM.
Related: bug 483750

M  +1    -1    kcmodule/common/PowerProfileModel.cpp
M  +4    -1    kcmodule/profiles/ui/GlobalConfig.qml
M  +20   -11   kcmodule/profiles/ui/ProfileConfig.qml

https://invent.kde.org/plasma/powerdevil/-/commit/78415ae0097ad36377b407d3b143589ca8fa8a18
Comment 17 Jakob Petsovits 2024-03-16 17:21:46 UTC
(In reply to Jakob Petsovits from comment #16)
> Git commit 78415ae0097ad36377b407d3b143589ca8fa8a18 by Jakob Petsovits.
> Committed on 16/03/2024 at 15:33.
> Pushed by jpetso into branch 'master'.
> 
> kcmodule: Revert to binding currentIndex in Component.onCompleted

Quick note about this patch: due to a messy but paradoxically bug-free cherry-pick of the original fix in this thread, this follow-up fix-for-the-fix is not required on the Plasma/6.0 branch. The original fix already makes it work as intended on Plasma/6.0, unlike master which briefly experienced Bug 483750 until the follow-up was merged.
Comment 18 Nicolas Fella 2024-03-27 23:38:49 UTC
*** Bug 484566 has been marked as a duplicate of this bug. ***