diff mbox

[LEDE-DEV,procd,v3,1/2] init: Check chroot return value in sysupgrade_exec_upgraded()

Message ID 20170719152433.29479-1-f.fainelli@gmail.com
State Accepted, archived
Delegated to: Florian Fainelli
Headers show

Commit Message

Florian Fainelli July 19, 2017, 3:24 p.m. UTC
chroot() can fail and its return value should be checked against, in that case
do an exit() since this is a fatal condition that we cannot recover from.

Fixes: 63789e51ed91 ("init: add support for sysupgrades triggered from preinit")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 sysupgrade.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Matthias Schiffer July 20, 2017, 12:39 p.m. UTC | #1
On 07/19/2017 05:24 PM, Florian Fainelli wrote:
> chroot() can fail and its return value should be checked against, in that case
> do an exit() since this is a fatal condition that we cannot recover from.
> 
> Fixes: 63789e51ed91 ("init: add support for sysupgrades triggered from preinit")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
>  sysupgrade.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)

Reviewed-by: Matthias Schiffer <mschiffer@universe-factory.net>

You should be able to push this yourself, otherwise I can do it later today
(I'll also add another commit to change the sysupgrade() return code to
UBUS_STATUS_UNKNOWN_ERROR).

Matthias


> 
> diff --git a/sysupgrade.c b/sysupgrade.c
> index 30f1836135c9..07e33f752d0c 100644
> --- a/sysupgrade.c
> +++ b/sysupgrade.c
> @@ -26,8 +26,10 @@ void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command)
>  {
>  	char *wdt_fd = watchdog_fd();
>  	char *argv[] = { "/sbin/upgraded", NULL, NULL, NULL};
> +	int ret;
>  
> -	if (chroot(prefix)) {
> +	ret = chroot(prefix);
> +	if (ret < 0) {
>  		fprintf(stderr, "Failed to chroot for upgraded exec.\n");
>  		return;
>  	}
> @@ -45,5 +47,9 @@ void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command)
>  	fprintf(stderr, "Failed to exec upgraded.\n");
>  	unsetenv("WDTFD");
>  	watchdog_set_cloexec(true);
> -	chroot(".");
> +	ret = chroot(".");
> +	if (ret < 0) {
> +		fprintf(stderr, "Failed to reset chroot, exiting.\n");
> +		exit(EXIT_FAILURE);
> +	}
>  }
>
Florian Fainelli July 20, 2017, 3:32 p.m. UTC | #2
On 07/20/2017 05:39 AM, Matthias Schiffer wrote:
> On 07/19/2017 05:24 PM, Florian Fainelli wrote:
>> chroot() can fail and its return value should be checked against, in that case
>> do an exit() since this is a fatal condition that we cannot recover from.
>>
>> Fixes: 63789e51ed91 ("init: add support for sysupgrades triggered from preinit")
>> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>> ---
>>  sysupgrade.c | 10 ++++++++--
>>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> Reviewed-by: Matthias Schiffer <mschiffer@universe-factory.net>
> 
> You should be able to push this yourself, otherwise I can do it later today
> (I'll also add another commit to change the sysupgrade() return code to
> UBUS_STATUS_UNKNOWN_ERROR).

Applied and pushed out, thanks!
diff mbox

Patch

diff --git a/sysupgrade.c b/sysupgrade.c
index 30f1836135c9..07e33f752d0c 100644
--- a/sysupgrade.c
+++ b/sysupgrade.c
@@ -26,8 +26,10 @@  void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command)
 {
 	char *wdt_fd = watchdog_fd();
 	char *argv[] = { "/sbin/upgraded", NULL, NULL, NULL};
+	int ret;
 
-	if (chroot(prefix)) {
+	ret = chroot(prefix);
+	if (ret < 0) {
 		fprintf(stderr, "Failed to chroot for upgraded exec.\n");
 		return;
 	}
@@ -45,5 +47,9 @@  void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command)
 	fprintf(stderr, "Failed to exec upgraded.\n");
 	unsetenv("WDTFD");
 	watchdog_set_cloexec(true);
-	chroot(".");
+	ret = chroot(".");
+	if (ret < 0) {
+		fprintf(stderr, "Failed to reset chroot, exiting.\n");
+		exit(EXIT_FAILURE);
+	}
 }