Skip to contentSkip to conversation

s390/appldata: Fix error handling in appldata_generic_handler()

PATCH Applied Gerald Schaefer 3 participants 3 messages Oct 21 s390

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390/appldata: Fix error handling in appldata_generic_handler()

appldata_generic_handler() always returns 0 after starting or stopping monitor recording.

So "echo {0,1} > /proc/sys/appldata/{os,mem,net_sum}" returns success even when DIAG 0xDC failed. A failed start would keep ops->active as 0, so reading the sysctl later would correctly reflect this.

A failed stop would falsely set ops->active to 0 and decrement module refcount. This would allow the data gathering module to be removed, and the data buffer to be freed, while z/VM monitor service is still collecting data from that buffer.

Fix this by returning -EIO when appldata_diag() failed, and only set ops->active to 0 and decrement module refcount when it succeeded on stop path.

---
 arch/s390/appldata/appldata_base.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/s390/appldata/appldata_base.c +8 -4
index 836c51da18f4..f10b2f040cc2 100644
@@ -360,21 +360,25 @@ appldata_generic_handler(const struct ctl_table *ctl, int write,
 			pr_err("Starting the data collection for %s "
 			       "failed with rc=%d\n", ops->name, rc);
 			module_put(ops->owner);
+			rc = -EIO;
 		} else
 			ops->active = 1;
 	} else if (!active && (ops->active == 1)) {
-		ops->active = 0;
 		rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
 				(unsigned long) ops->data, ops->size,
 				ops->mod_lvl);
-		if (rc != 0)
+		if (rc != 0) {
 			pr_err("Stopping the data collection for %s "
 			       "failed with rc=%d\n", ops->name, rc);
-		module_put(ops->owner);
+			rc = -EIO;
+		} else {
+			ops->active = 0;
+			module_put(ops->owner);
+		}
 	}
 	mutex_unlock(&appldata_ops_mutex);
 	module_put(ops->owner);
-	return 0;
+	return rc;
 }
 
 /*************************** /proc stuff <END> *******************************/
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines

appldata_generic_handler() always returns 0 after starting or stopping monitor recording.

So "echo {0,1} > /proc/sys/appldata/{os,mem,net_sum}" returns success even when DIAG 0xDC failed. A failed start would keep ops->active as 0, so reading the sysctl later would correctly reflect this.

A failed stop would falsely set ops->active to 0 and decrement module refcount. This would allow the data gathering module to be removed, and the data buffer to be freed, while z/VM monitor service is still collecting data from that buffer.

Quoted 6 lines

Fix this by returning -EIO when appldata_diag() failed, and only set ops->active to 0 and decrement module refcount when it succeeded on stop path.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#2 lore raw
In reply to Gerald Schaefer
Quoted 16 lines · Gerald Schaefer

appldata_generic_handler() always returns 0 after starting or stopping monitor recording.

So "echo {0,1} > /proc/sys/appldata/{os,mem,net_sum}" returns success even when DIAG 0xDC failed. A failed start would keep ops->active as 0, so reading the sysctl later would correctly reflect this.

A failed stop would falsely set ops->active to 0 and decrement module refcount. This would allow the data gathering module to be removed, and the data buffer to be freed, while z/VM monitor service is still collecting data from that buffer.

Fix this by returning -EIO when appldata_diag() failed, and only set ops->active to 0 and decrement module refcount when it succeeded on stop path.

Quoted 5 lines
---
 arch/s390/appldata/appldata_base.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Applied, thanks!