Skip to contentSkip to conversation

poweroff: fix bug in orderly_poweroff

PATCH In review hongfeng 4 participants 6 messages Sep 19, 2012 – Sep 21, 2012

lore
Share & tools
lore

hongfeng

author
#0 lore raw

PATCH v2 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_EXEC which will monitor whether user application successful run.

Change-Id I2f9ebbb90c0c2443780080ec9507c8d004e5da74
---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sys.c +1 -1
index 241507f..a624d4c 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_EXEC,
 				      NULL, argv_cleanup, NULL);
 	if (ret == -ENOMEM)
 		argv_free(argv);
Signature · 1 line
1.7.0.4
Acked-by Serge Hallyn on v2 1/1
#1 lore raw
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,

Note that a changelog here explaining that you switched to UMH_WAIT_EXEC per Eric's suggestion would be both informative and courteous.

Quoted 1 line

should change to UMH_WAIT_EXEC which will monitor whether user application successful run.

Is this actually sufficient for you? The exec will have started, but may for whatever (very unlikely) reason fail. If you're happy with it,

Quoted 28 lines
Change-Id I2f9ebbb90c0c2443780080ec9507c8d004e5da74
---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sys.c +1 -1
index 241507f..a624d4c 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_EXEC,
 				      NULL, argv_cleanup, NULL);
 	if (ret == -ENOMEM)
 		argv_free(argv);
Signature · 7 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
author Acked-by Serge Hallyn Acked-by Kees Cook
#2 lore raw

Hi, Serge,

I am just a graduate and it's my first time to send a patch to opensource, so thank you very much for reminding me the "changelog affairs", it seems this patch has been added to -mm tree as attached mail, and I have no chance to change the comments, right ? Then I must remember this and be careful next time. Thanks again for reminding me !

Quoted 1 line

Is this actually sufficient for you? The exec will have started, but may for whatever (very unlikely) reason fail. If you're happy with it,

I think UMH_WAIT_EXEC is sufficient for me, as in our system there is no "/sbin/poweroff" existed. On the other hand, UMH_WAIT_PROC is not suitable here as Eric analysis; if using UMH_WAIT_EXEC, and the user application fail, I'd prefer to complain bad application. So using UMH_WAIT_EXEC and UMH_WAIT_PROC has a tradeoff here, what do you think so ?

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

-----Original Message-----
From: Serge E. Hallyn [mailto:[email protected]]
Sent: 2012年9月21日 1:07
To: Feng Hong
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V2] 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,

Note that a changelog here explaining that you switched to UMH_WAIT_EXEC per Eric's suggestion would be both informative and courteous.

Quoted 1 line

should change to UMH_WAIT_EXEC which will monitor whether user application successful run.

Is this actually sufficient for you? The exec will have started, but may for whatever (very unlikely) reason fail. If you're happy with it,

Quoted 28 lines
Change-Id I2f9ebbb90c0c2443780080ec9507c8d004e5da74
---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sys.c +1 -1
index 241507f..a624d4c 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_EXEC,
 				      NULL, argv_cleanup, NULL);
 	if (ret == -ENOMEM)
 		argv_free(argv);
Signature · 7 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

The patch titled
Subject: poweroff: fix bug in orderly_poweroff()
has been added to the -mm tree. Its filename is
poweroff-fix-bug-in-orderly_poweroff.patch

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated there every 3-4 working days

------------------------------------------------------
From: hongfeng <[email protected]>
Subject: 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_EXEC which will monitor whether user application successful run.

Cc Serge Hallyn <[email protected]>
Cc "Eric W. Biederman" <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

---

 kernel/sys.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sys.c renamed from kernel/sys.c~poweroff-fix-bug-in-orderly_poweroff +1 -1
diff -puN kernel/sys.c~poweroff-fix-bug-in-orderly_poweroff kernel/sys.c
@@ -2205,7 +2205,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_EXEC,
                                      NULL, argv_cleanup, NULL);
        if (ret == -ENOMEM)
                argv_free(argv);

_

Patches currently in -mm which might be from [email protected] are

poweroff-fix-bug-in-orderly_poweroff.patch

#3 lore raw
Quoted 5 lines · On Thu, 20 Sep 2012 17:16:35 -0700 Feng Hong <[email protected]> wrote:

I am just a graduate and it's my first time to send a patch to opensource, so thank you very much for reminding me the "changelog affairs", it seems this patch has been added to -mm tree as attached mail, and I have no chance to change the comments, right ? Then I must remember this and be careful next time. Thanks again for reminding me!

It depends. If the person who committed the patch was using a git tree then it can be difficult for them to alter a changelog.

But the -mm tree is not mastered in git (for this and other reasons), and I alter changelogs all the time. So please feel free to send replacement text and I shall copy-n-paste that text straight into the patch.

author
#4 lore raw

Hi, Serge, Andrew,

Will following an acceptable change log ?

///////////////////////////////////////////////////////////////////////////////////////////////// orderly_poweroff is trying to poweroff platform by two steps:
step 1: Call user space application to poweroff
step 2: If user space 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, which obey the design goal of orderly_poweroff.

We have two choices here:
UMH_WAIT_EXEC which means wait for the exec, but not the process; UMH_WAIT_PROC which means wait for the process to complete. we need to trade off the two choices:

If using UMH_WAIT_EXEC, there is potential issue comments by Serge E. Hallyn: The exec will have started, but may for whatever (very unlikely) reason fail.

If using UMH_WAIT_PROC, there is potential issue comments by Eric W. Biederman: If the caller is not running in a kernel thread then we can easily get into a case where the user space caller will block waiting for us when we are waiting for the user space caller.

Thanks for their excellent ideas, based on the above discussion, we finally choose UMH_WAIT_EXEC, which is much more safe, if the user application really fails, we just complain the application itself, it seems a better choice here. //////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

-----Original Message-----
From: Andrew Morton [mailto:[email protected]]
Sent: 2012年9月21日 8:25
To: Feng Hong
Cc: Serge E. Hallyn; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V2] poweroff: fix bug in orderly_poweroff

Quoted 5 lines · On Thu, 20 Sep 2012 17:16:35 -0700 Feng Hong <[email protected]> wrote:

I am just a graduate and it's my first time to send a patch to opensource, so thank you very much for reminding me the "changelog affairs", it seems this patch has been added to -mm tree as attached mail, and I have no chance to change the comments, right ? Then I must remember this and be careful next time. Thanks again for reminding me!

It depends. If the person who committed the patch was using a git tree then it can be difficult for them to alter a changelog.

But the -mm tree is not mastered in git (for this and other reasons), and I alter changelogs all the time. So please feel free to send replacement text and I shall copy-n-paste that text straight into the patch.

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

#5 lore raw
In reply to Feng Hong
Quoted 3 lines · Feng Hong

Hi, Serge,

I am just a graduate and it's my first time to send a patch to opensource, so thank you very much for reminding me the "changelog affairs", it seems this patch has been added to -mm tree as attached mail, and I have no chance to change the comments, right ? Then I must remember this and be careful next time. Thanks again for reminding me !

Sorry, your description was fine, what i meant was something below your patch description that looks like

Change since v1:
[date] Per Eric's sugestion, switch from UMH_WAIT_PROC to UMH_WAIT_EXEC.

Quoted 2 lines
Quoted 1 line

Is this actually sufficient for you? The exec will have started, but may for whatever (very unlikely) reason fail. If you're happy with it,

I think UMH_WAIT_EXEC is sufficient for me, as in our system there is no "/sbin/poweroff" existed. On the other hand, UMH_WAIT_PROC is not suitable here as Eric analysis; if using UMH_WAIT_EXEC, and the user application fail, I'd prefer to complain bad application. So using UMH_WAIT_EXEC and UMH_WAIT_PROC has a tradeoff here, what do you think so ?

Yup, that sounds fine to me, I just wanted to make sure you were ok with the fact that application failure (after successful exec) will be ignored.

thanks,
-serge