git: 573b117f6e30 - stable/13 - freebsd32: Report errors when copying out oldlenp in __sysctl

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 02 Jan 2024 01:12:54 UTC
The branch stable/13 has been updated by markj:

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

commit 573b117f6e30b8839bec4a778c37d60d88d980f5
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-12-26 01:37:32 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-01-02 01:12:44 +0000

    freebsd32: Report errors when copying out oldlenp in __sysctl
    
    This matches the native implementation's behaviour.
    
    Reviewed by:    kib
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D43101
    
    (cherry picked from commit 81eb7baa69e983fe159d254a4ed47d9c00396801)
---
 sys/compat/freebsd32/freebsd32_misc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 65b7ddf83e3d..cd6a4c2dc3df 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -2543,9 +2543,9 @@ freebsd32___sysctl(struct thread *td, struct freebsd32___sysctl_args *uap)
 		uap->new, uap->newlen, &j, SCTL_MASK32);
 	if (error)
 		return (error);
-	if (uap->oldlenp)
-		suword32(uap->oldlenp, j);
-	return (0);
+	if (uap->oldlenp != NULL && suword32(uap->oldlenp, j) != 0)
+		error = EFAULT;
+	return (error);
 }
 
 int