git: c48a331e5479 - stable/15 - linux: Handle OOB accesses in bsd_to_linux_errno()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 17:06:24 UTC
The branch stable/15 has been updated by markj:

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

commit c48a331e54794310fe05dddcb0719cdba1f5b1c3
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-11-16 00:14:21 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-17 17:02:15 +0000

    linux: Handle OOB accesses in bsd_to_linux_errno()
    
    Such accesses can be triggered via ptrace(PT_SET_SC_RET).
    
    Reported by:    Dennys Kaluzny Pereira <dennyskaluzny@gmail.com>
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 8f024e97cabf7497dc047538db9c6be9067752a1)
---
 sys/compat/linux/linux_errno.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/sys/compat/linux/linux_errno.c b/sys/compat/linux/linux_errno.c
index f04f694e5bec..7f0d102b93d5 100644
--- a/sys/compat/linux/linux_errno.c
+++ b/sys/compat/linux/linux_errno.c
@@ -1,4 +1,3 @@
-
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/errno.h>
@@ -10,10 +9,10 @@
 int
 bsd_to_linux_errno(int error)
 {
-
-	KASSERT(error >= 0 && error <= ELAST,
-	    ("%s: bad error %d", __func__, error));
-
+	if (__predict_false(error < 0 || error > ELAST)) {
+		printf("%s: unhandled value %d\n", __func__, error);
+		return (-LINUX_EINVAL);
+	}
 	return (linux_errtbl[error]);
 }