Linux s390 Architecture development
 help / color / mirror / Atom feed
* [PATCH] s390/appldata: Fix error handling in appldata_generic_handler()
@ 2026-10-21 12:04 Gerald Schaefer
  2026-10-21 12:07 ` sashiko-bot
  2026-10-21 13:16 ` Heiko Carstens
  0 siblings, 2 replies; 3+ messages in thread
From: Gerald Schaefer @ 2026-10-21 12:04 UTC (permalink / raw)
  To: linux-s390
  Cc: Heiko Carstens, Alexander Gordeev, Vasily Gorbik, Sven Schnelle,
	Christian Borntraeger

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.

Cc: stable@vger.kernel.org
Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
---
 arch/s390/appldata/appldata_base.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c
index 836c51da18f4..f10b2f040cc2 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -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> *******************************/
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-21 13:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-21 12:04 [PATCH] s390/appldata: Fix error handling in appldata_generic_handler() Gerald Schaefer
2026-10-21 12:07 ` sashiko-bot
2026-10-21 13:16 ` Heiko Carstens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox