Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3acdbda6 authored by Subash Abhinov Kasiviswanathan's avatar Subash Abhinov Kasiviswanathan Committed by Maciej Żenczykowski
Browse files

ANDROID: nf: IDLETIMER: Fix possible use before initialization in idletimer_resume



idletimer_resume() assumes that the PM_SUSPEND_PREPARE notifier is sent
before PM_POST_SUSPEND so that timer->last_suspend_time is initialized.
However, it is possible for PM_POST_SUSPEND to be sent first if there is an
error returned from another driver's PM_SUSPEND_PREPARE notifier. As a
result, structures are accessed without initialization.

The arguments to set_normalized_timespec are very large and unexpected.
timer->last_suspend_time has the value of
{.tv_sec = 0x6b6b6b6b6b6b6b6b, .tv_nsec=0x6b6b6b6b6b6b6b6b}. Since really
large iterations are required, this operation takes more than a minute
and causes the CPU to trigger a spinbug since the timestamp lock is held.

Call stack -

- set_normalized_timespec
- timespec_sub
- idletimer_resume
- notifier_call_chain
- __blocking_notifier_call_chain
- pm_notifier_call_chain

Add a flag indicating whether the current value of timer->last_suspend is
valid.

Detected with CONFIG_SLUB_DEBUG & CONFIG_DEBUG_SPINLOCK in arm64.

Bug: 140404598
Fixes: f0c2df2b1228a ("ANDROID: netfilter: xt_IDLETIMER: Add new
netlink msg type")
Change-Id: I95328b0ac85dba819ff9cef751c3d07300c232f1
Signed-off-by: default avatarSubash Abhinov Kasiviswanathan <subashab@codeaurora.org>
Signed-off-by: default avatarTodd Kjos <tkjos@google.com>
(cherry picked from commit 7ded4359680d3fb593cbc5c90d84bb5e5083eda9)
parent 96267fbb
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -70,6 +70,7 @@ struct idletimer_tg {
	bool send_nl_msg;
	bool send_nl_msg;
	bool active;
	bool active;
	uid_t uid;
	uid_t uid;
	bool suspend_time_valid;
};
};


static LIST_HEAD(idletimer_tg_list);
static LIST_HEAD(idletimer_tg_list);
@@ -239,8 +240,13 @@ static int idletimer_resume(struct notifier_block *notifier,
	switch (pm_event) {
	switch (pm_event) {
	case PM_SUSPEND_PREPARE:
	case PM_SUSPEND_PREPARE:
		get_monotonic_boottime(&timer->last_suspend_time);
		get_monotonic_boottime(&timer->last_suspend_time);
		timer->suspend_time_valid = true;
		break;
		break;
	case PM_POST_SUSPEND:
	case PM_POST_SUSPEND:
		if (!timer->suspend_time_valid)
			break;
		timer->suspend_time_valid = false;

		spin_lock_bh(&timestamp_lock);
		spin_lock_bh(&timestamp_lock);
		if (!timer->active) {
		if (!timer->active) {
			spin_unlock_bh(&timestamp_lock);
			spin_unlock_bh(&timestamp_lock);
@@ -291,7 +297,7 @@ static int idletimer_tg_create(struct idletimer_tg_info *info)
{
{
	int ret;
	int ret;


	info->timer = kmalloc(sizeof(*info->timer), GFP_KERNEL);
	info->timer = kzalloc(sizeof(*info->timer), GFP_KERNEL);
	if (!info->timer) {
	if (!info->timer) {
		ret = -ENOMEM;
		ret = -ENOMEM;
		goto out;
		goto out;