[lxc-devel] [lxd/master] lxd: Fix possible segfaults in tasks

monstermunchkin on Github lxc-bot at linuxcontainers.org
Tue Jan 29 11:13:09 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 469 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190129/e0ab2377/attachment.bin>
-------------- next part --------------
From 693ba1a4cf7831dfca668ee9742ca00b7c8c486c Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Tue, 29 Jan 2019 11:50:34 +0100
Subject: [PATCH] lxd: Fix possible segfaults in tasks

Calling op.Run() if operationCreate() has failed will cause a segfault.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/backup.go                   | 1 +
 lxd/container.go                | 1 +
 lxd/container_instance_types.go | 1 +
 lxd/images.go                   | 2 ++
 lxd/logging.go                  | 1 +
 5 files changed, 6 insertions(+)

diff --git a/lxd/backup.go b/lxd/backup.go
index ec1e4959c5..46a53a3014 100644
--- a/lxd/backup.go
+++ b/lxd/backup.go
@@ -387,6 +387,7 @@ func pruneExpiredContainerBackupsTask(d *Daemon) (task.Func, task.Schedule) {
 		op, err := operationCreate(d.cluster, "", operationClassTask, db.OperationBackupsExpire, nil, nil, opRun, nil, nil)
 		if err != nil {
 			logger.Error("Failed to start expired backups operation", log.Ctx{"err": err})
+			return
 		}
 
 		logger.Info("Pruning expired container backups")
diff --git a/lxd/container.go b/lxd/container.go
index 533f5d7c93..d9aa6ba59e 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -1586,6 +1586,7 @@ func autoCreateContainerSnapshotsTask(d *Daemon) (task.Func, task.Schedule) {
 		op, err := operationCreate(d.cluster, "", operationClassTask, db.OperationSnapshotCreate, nil, nil, opRun, nil, nil)
 		if err != nil {
 			logger.Error("Failed to start create snapshot operation", log.Ctx{"err": err})
+			return
 		}
 
 		logger.Info("Creating scheduled container snapshots")
diff --git a/lxd/container_instance_types.go b/lxd/container_instance_types.go
index c451baac60..b353ad5734 100644
--- a/lxd/container_instance_types.go
+++ b/lxd/container_instance_types.go
@@ -94,6 +94,7 @@ func instanceRefreshTypesTask(d *Daemon) (task.Func, task.Schedule) {
 		op, err := operationCreate(d.cluster, "", operationClassTask, db.OperationInstanceTypesUpdate, nil, nil, opRun, nil, nil)
 		if err != nil {
 			logger.Error("Failed to start instance types update operation", log.Ctx{"err": err})
+			return
 		}
 
 		logger.Info("Updating instance types")
diff --git a/lxd/images.go b/lxd/images.go
index 59dadf433a..fadb6f64a5 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -863,6 +863,7 @@ func autoUpdateImagesTask(d *Daemon) (task.Func, task.Schedule) {
 		op, err := operationCreate(d.cluster, "", operationClassTask, db.OperationImagesUpdate, nil, nil, opRun, nil, nil)
 		if err != nil {
 			logger.Error("Failed to start image update operation", log.Ctx{"err": err})
+			return
 		}
 
 		logger.Infof("Updating images")
@@ -1090,6 +1091,7 @@ func pruneExpiredImagesTask(d *Daemon) (task.Func, task.Schedule) {
 		op, err := operationCreate(d.cluster, "", operationClassTask, db.OperationImagesExpire, nil, nil, opRun, nil, nil)
 		if err != nil {
 			logger.Error("Failed to start expired image operation", log.Ctx{"err": err})
+			return
 		}
 
 		logger.Infof("Pruning expired images")
diff --git a/lxd/logging.go b/lxd/logging.go
index 53a70e8605..ab244ad5ca 100644
--- a/lxd/logging.go
+++ b/lxd/logging.go
@@ -26,6 +26,7 @@ func expireLogsTask(state *state.State) (task.Func, task.Schedule) {
 		op, err := operationCreate(state.Cluster, "", operationClassTask, db.OperationLogsExpire, nil, nil, opRun, nil, nil)
 		if err != nil {
 			logger.Error("Failed to start log expiry operation", log.Ctx{"err": err})
+			return
 		}
 
 		logger.Infof("Expiring log files")


More information about the lxc-devel mailing list