Skip to contentSkip to conversation

poweroff: fix bug in orderly_poweroff

PATCH Superseded hongfeng 3 participants 6 messages Sep 19, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

hongfeng

author
#0 lore raw

PATCH 1/1 poweroff: fix bug in orderly_poweroff

orderly_poweroff is trying to poweroff platform by two steps:
step 1: Call userspace application to poweroff
step 2: If userspace poweroff fail, then do a force power off if force param is set.

The bug here is, step 1 is always successful with param UMH_NO_WAIT,
should change to UMH_WAIT_PROC which will monitor the return value ofuserspace application.

Change-Id I2f9ebbb90c0c2443780080ec9507c8d004e5da74
---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sys.c +1 -1
index 241507f..1b30b30 100644
@@ -2204,7 +2204,7 @@ static int __orderly_poweroff(void)
 		return -ENOMEM;
 	}
 
-	ret = call_usermodehelper_fns(argv[0], argv, envp, UMH_NO_WAIT,
+	ret = call_usermodehelper_fns(argv[0], argv, envp, UMH_WAIT_PROC,
 				      NULL, argv_cleanup, NULL);
 	if (ret == -ENOMEM)
 		argv_free(argv);
Signature · 1 line
1.7.0.4
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · hongfeng

orderly_poweroff is trying to poweroff platform by two steps:
step 1: Call userspace application to poweroff
step 2: If userspace poweroff fail, then do a force power off if force param is set.

The bug here is, step 1 is always successful with param UMH_NO_WAIT,
should change to UMH_WAIT_PROC which will monitor the return value ofuserspace application.

Seems right to me.

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
#2 lore raw
In reply to hongfeng
Quoted 5 lines · hongfeng

orderly_poweroff is trying to poweroff platform by two steps:
step 1: Call userspace application to poweroff
step 2: If userspace poweroff fail, then do a force power off if force param is set.

The bug here is, step 1 is always successful with param UMH_NO_WAIT,

This code has existed for 5 years. Is this a recent regression? Why has no one complained before?

It looks to me that step 2 is:
step 2: If we can not launch the userspace poweroff fail.

Quoted 2 lines

should change to UMH_WAIT_PROC which will monitor the return value ofuserspace application.

Is it safe to block indefinitely in the callers waiting for userspace?

If the caller is not running in a kernel thread then we can easily get into a case where the userspace caller will block waiting for us when we are waiting for the userspace caller.

I don't want to impeded progress but I don't see the evidence that this change is good enough.

Quoted 19 lines
Change-Id I2f9ebbb90c0c2443780080ec9507c8d004e5da74
---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sys.c +1 -1
index 241507f..1b30b30 100644
@@ -2204,7 +2204,7 @@ static int __orderly_poweroff(void)
 		return -ENOMEM;
 	}
 
-	ret = call_usermodehelper_fns(argv[0], argv, envp, UMH_NO_WAIT,
+	ret = call_usermodehelper_fns(argv[0], argv, envp, UMH_WAIT_PROC,
 				      NULL, argv_cleanup, NULL);
 	if (ret == -ENOMEM)
 		argv_free(argv);
author
#3 lore raw

Hi, Eric

1. We are developing on an Android phone platform, we use thermal framework to monitor the temperature, when the temperature above like 110 degree, thermal framework will use orderly_shutdown to shutdown phone, however, on Android platform there is no " /sbin/poweroff " cmd ready . Then we want "fail ret" to trigger force shutdown (use kernel_power_off), but always we get "suc ret"
2. Here the caller just wait for "poweroff" userspace application, if it block the called, then it's the "poweroff" problem itself
3. As in the original orderly_shutdown design, we must get the right "ret", if this ret is always "0", then it obey orderly_poweroff design goal. Step 2: force shutdown is always useless code.
int orderly_poweroff(bool force)

{
        int ret = __orderly_poweroff();

        if (ret && force) {
                printk(KERN_WARNING "Failed to start orderly shutdown: "
                       "forcing the issue\n");

                /*
                 * I guess this should try to kick off some daemon to sync and
                 * poweroff asap.  Or not even bother syncing if we're doing an
                 * emergency shutdown?
                 */
                emergency_sync();
                kernel_power_off();
        }

        return ret;
}1

--
Best Regards,
Feng Hong
Application Processor Software Engnieer
Marvell Technology (Shanghai) Ltd

-----Original Message-----
From: Eric W. Biederman [mailto:[email protected]]
Sent: 2012年9月19日 12:47
To: Feng Hong
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] poweroff: fix bug in orderly_poweroff

Quoted 5 lines · hongfeng

orderly_poweroff is trying to poweroff platform by two steps:
step 1: Call userspace application to poweroff
step 2: If userspace poweroff fail, then do a force power off if force param is set.

The bug here is, step 1 is always successful with param UMH_NO_WAIT,

This code has existed for 5 years. Is this a recent regression? Why has no one complained before?

It looks to me that step 2 is:
step 2: If we can not launch the userspace poweroff fail.

Quoted 2 lines

should change to UMH_WAIT_PROC which will monitor the return value ofuserspace application.

Is it safe to block indefinitely in the callers waiting for userspace?

If the caller is not running in a kernel thread then we can easily get into a case where the userspace caller will block waiting for us when we are waiting for the userspace caller.

I don't want to impeded progress but I don't see the evidence that this change is good enough.

Quoted 11 lines
Change-Id I2f9ebbb90c0c2443780080ec9507c8d004e5da74
---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sys.c +0 -0
index 241507f..1b30b30 100644

kernel/sys.c static int __orderly_poweroff(void) · line 2210

Quoted 8 lines
kernel/sys.c +1 -1
@@ -2204,7 +2204,7 @@ static int __orderly_poweroff(void)
 		return -ENOMEM;
 	}
 
-	ret = call_usermodehelper_fns(argv[0], argv, envp, UMH_NO_WAIT,
+	ret = call_usermodehelper_fns(argv[0], argv, envp, UMH_WAIT_PROC,
 				      NULL, argv_cleanup, NULL);
 	if (ret == -ENOMEM)
 		argv_free(argv);

�翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m��� �鹅�⒏?朓�

#4 lore raw
Quoted 9 lines · Feng Hong

Hi, Eric

1. We are developing on an Android phone platform, we use thermal framework to monitor the temperature, when the temperature above like 110 degree, thermal framework will use orderly_shutdown to shutdown phone, however, on Android platform there is no " /sbin/poweroff " cmd ready . Then we want "fail ret" to trigger force shutdown (use kernel_power_off), but always we get "suc ret"

Quoted 6 lines

2. Here the caller just wait for "poweroff" userspace application, if it block the called, then it's the "poweroff" problem itself

3. As in the original orderly_shutdown design, we must get the right "ret", if this ret is always "0", then it obey orderly_poweroff design goal. Step 2: force shutdown is always useless code.

That sounds like a clear case that we need to change it to UMH_WAIT_EXEC.

Changing it to UMH_WAIT_PROC seems much more dangerous.

Eric

author
#5 lore raw

Hi, Eric,

I agree with your idea, I'll prepare another patch, thanks for remind this possible issue.

--
Best Regards,
Feng Hong
Application Processor Software Engnieer
Marvell Technology (Shanghai) Ltd

-----Original Message-----
From: Eric W. Biederman [mailto:[email protected]]
Sent: 2012年9月19日 13:58
To: Feng Hong
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] poweroff: fix bug in orderly_poweroff

Quoted 9 lines · Feng Hong

Hi, Eric

1. We are developing on an Android phone platform, we use thermal framework to monitor the temperature, when the temperature above like 110 degree, thermal framework will use orderly_shutdown to shutdown phone, however, on Android platform there is no " /sbin/poweroff " cmd ready . Then we want "fail ret" to trigger force shutdown (use kernel_power_off), but always we get "suc ret"

Quoted 6 lines

2. Here the caller just wait for "poweroff" userspace application, if it block the called, then it's the "poweroff" problem itself

3. As in the original orderly_shutdown design, we must get the right "ret", if this ret is always "0", then it obey orderly_poweroff design goal. Step 2: force shutdown is always useless code.

That sounds like a clear case that we need to change it to UMH_WAIT_EXEC.

Changing it to UMH_WAIT_PROC seems much more dangerous.

Eric �翳簕.n�+壏煯壄�+%娝�遍荻w�簕.n�+壏{炳G珴�妠ay�蕠跈�,jf"穐殢飦�戧鐉_璁(殠娸"濟�m���G珴�⒏?櫒璀�&x忈秈O曟瑉窔v豝�m��� �鹅�⒏?朓�