discover/device-handler: Prevent normal users changing boot target
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 19 Jun 2018 06:52:27 +0000 (16:52 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Mon, 3 Dec 2018 03:39:57 +0000 (14:39 +1100)
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/device-handler.c
discover/device-handler.h

index 729ed2c0f52ae76f9cbc7474cd803ed773bab3a6..e446cab528fb8d53238a6724a8deddb2dbc744a5 100644 (file)
@@ -81,6 +81,7 @@ struct device_handler {
        struct autoboot_option  *temp_autoboot;
 
        struct discover_boot_option *default_boot_option;
        struct autoboot_option  *temp_autoboot;
 
        struct discover_boot_option *default_boot_option;
+       struct discover_boot_option *last_boot_option;
        int                     default_boot_option_priority;
 
        struct list             unresolved_boot_options;
        int                     default_boot_option_priority;
 
        struct list             unresolved_boot_options;
@@ -756,6 +757,8 @@ static int default_timeout(void *arg)
 
        opt = handler->default_boot_option;
 
 
        opt = handler->default_boot_option;
 
+       handler->last_boot_option = opt;
+
        if (handler->sec_to_boot) {
                countdown_status(handler, opt, handler->sec_to_boot);
                handler->sec_to_boot--;
        if (handler->sec_to_boot) {
                countdown_status(handler, opt, handler->sec_to_boot);
                handler->sec_to_boot--;
@@ -1453,13 +1456,22 @@ static struct discover_boot_option *find_boot_option_by_id(
 }
 
 void device_handler_boot(struct device_handler *handler,
 }
 
 void device_handler_boot(struct device_handler *handler,
-               struct boot_command *cmd)
+               bool change_default, struct boot_command *cmd)
 {
        struct discover_boot_option *opt = NULL;
 
        if (cmd->option_id && strlen(cmd->option_id))
                opt = find_boot_option_by_id(handler, cmd->option_id);
 
 {
        struct discover_boot_option *opt = NULL;
 
        if (cmd->option_id && strlen(cmd->option_id))
                opt = find_boot_option_by_id(handler, cmd->option_id);
 
+       /* Don't allow a normal client to change the default */
+       if (!change_default && handler->last_boot_option &&
+                       opt != handler->last_boot_option) {
+               pb_log("Non-root user tried to change boot option\n");
+               device_handler_status_err(handler,
+                               "Must be root to change default boot option\n");
+               return;
+       }
+
        if (handler->pending_boot)
                boot_cancel(handler->pending_boot);
 
        if (handler->pending_boot)
                boot_cancel(handler->pending_boot);
 
index 9696ec064cd369d7833cd2cd86d4ae1a1d92d9d8..9619a2df0c9df4ed5f078717fb3f35896fa388fa 100644 (file)
@@ -161,7 +161,7 @@ struct discover_boot_option *device_handler_find_option_by_name(
                struct device_handler *handler, const char *device,
                const char *name);
 void device_handler_boot(struct device_handler *handler,
                struct device_handler *handler, const char *device,
                const char *name);
 void device_handler_boot(struct device_handler *handler,
-               struct boot_command *cmd);
+               bool change_default, struct boot_command *cmd);
 void device_handler_cancel_default(struct device_handler *handler);
 void device_handler_update_config(struct device_handler *handler,
                struct config *config);
 void device_handler_cancel_default(struct device_handler *handler);
 void device_handler_update_config(struct device_handler *handler,
                struct config *config);