[RFC PATCH 08/13] discover/device-handler: Prevent normal users changing boot target

Samuel Mendoza-Jonas sam at mendozajonas.com
Thu Jun 28 16:41:46 AEST 2018


Signed-off-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
---
 discover/device-handler.c | 14 +++++++++++++-
 discover/device-handler.h |  2 +-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/discover/device-handler.c b/discover/device-handler.c
index aa61bd2..6a5ff3f 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -77,6 +77,7 @@ struct device_handler {
 	unsigned int		sec_to_boot;
 
 	struct discover_boot_option *default_boot_option;
+	struct discover_boot_option *last_boot_option;
 	int			default_boot_option_priority;
 
 	struct list		unresolved_boot_options;
@@ -734,6 +735,8 @@ static int default_timeout(void *arg)
 
 	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--;
@@ -1209,13 +1212,22 @@ static struct discover_boot_option *find_boot_option_by_id(
 }
 
 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);
 
+	/* 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);
 
diff --git a/discover/device-handler.h b/discover/device-handler.h
index 771cd06..5fb6cf3 100644
--- a/discover/device-handler.h
+++ b/discover/device-handler.h
@@ -154,7 +154,7 @@ const char *discover_device_get_param(struct discover_device *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);
-- 
2.18.0



More information about the Petitboot mailing list