git: 03792b24472f - stable/15 - acpi: Reject duplicate handlers for ioctl commands

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 24 Apr 2026 15:29:00 UTC
The branch stable/15 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=03792b24472f6dc3a043007c7eef455291737889

commit 03792b24472f6dc3a043007c7eef455291737889
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-12-26 15:36:38 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2026-04-24 15:26:38 +0000

    acpi: Reject duplicate handlers for ioctl commands
    
    Reviewed by:    imp
    Sponsored by:   Netflix
    Differential Revision:  https://reviews.freebsd.org/D54311
    
    (cherry picked from commit 4eb560faa725771e536a850a9467fbb592ab3c1b)
---
 sys/dev/acpica/acpi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c
index bac5b8c889e0..47c8ae1d1d6b 100644
--- a/sys/dev/acpica/acpi.c
+++ b/sys/dev/acpica/acpi.c
@@ -4109,7 +4109,7 @@ static int				acpi_ioctl_hooks_initted;
 int
 acpi_register_ioctl(u_long cmd, acpi_ioctl_fn fn, void *arg)
 {
-    struct acpi_ioctl_hook	*hp;
+    struct acpi_ioctl_hook *hp, *thp;
 
     if ((hp = malloc(sizeof(*hp), M_ACPIDEV, M_NOWAIT)) == NULL)
 	return (ENOMEM);
@@ -4122,6 +4122,14 @@ acpi_register_ioctl(u_long cmd, acpi_ioctl_fn fn, void *arg)
 	TAILQ_INIT(&acpi_ioctl_hooks);
 	acpi_ioctl_hooks_initted = 1;
     }
+    TAILQ_FOREACH(thp, &acpi_ioctl_hooks, link) {
+	if (thp->cmd == cmd) {
+	    ACPI_UNLOCK(acpi);
+	    free(hp, M_ACPIDEV);
+	    return (EBUSY);
+	}
+    }
+
     TAILQ_INSERT_TAIL(&acpi_ioctl_hooks, hp, link);
     ACPI_UNLOCK(acpi);