git: a7cc56b28fb1 - main - linux: Adjust rlimit SIGPENDING & MSGQUEUE behaviour to match linprocfs

From: Warner Losh <imp_at_FreeBSD.org>
Date: Fri, 10 May 2024 20:51:31 UTC
The branch main has been updated by imp:

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

commit a7cc56b28fb1615a8ac4ebe826312a5d8a0f17da
Author:     Ricardo Branco <rbranco@suse.de>
AuthorDate: 2024-05-10 14:20:16 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-05-10 20:50:04 +0000

    linux: Adjust rlimit SIGPENDING & MSGQUEUE behaviour to match linprocfs
    
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/1227
---
 sys/compat/linux/linux_misc.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index cb62b0e70c0d..9b8ab193f2bd 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -1125,16 +1125,16 @@ linux_getgroups(struct thread *td, struct linux_getgroups_args *args)
 }
 
 static bool
-linux_get_dummy_limit(l_uint resource, struct rlimit *rlim)
+linux_get_dummy_limit(struct thread *td, l_uint resource, struct rlimit *rlim)
 {
+	ssize_t size;
+	int res, error;
 
 	if (linux_dummy_rlimits == 0)
 		return (false);
 
 	switch (resource) {
 	case LINUX_RLIMIT_LOCKS:
-	case LINUX_RLIMIT_SIGPENDING:
-	case LINUX_RLIMIT_MSGQUEUE:
 	case LINUX_RLIMIT_RTTIME:
 		rlim->rlim_cur = LINUX_RLIM_INFINITY;
 		rlim->rlim_max = LINUX_RLIM_INFINITY;
@@ -1144,6 +1144,23 @@ linux_get_dummy_limit(l_uint resource, struct rlimit *rlim)
 		rlim->rlim_cur = 0;
 		rlim->rlim_max = 0;
 		return (true);
+	case LINUX_RLIMIT_SIGPENDING:
+		error = kernel_sysctlbyname(td,
+		    "kern.sigqueue.max_pending_per_proc",
+		    &res, &size, 0, 0, 0, 0);
+		if (error != 0)
+			return (false);
+		rlim->rlim_cur = res;
+		rlim->rlim_max = res;
+		return (true);
+	case LINUX_RLIMIT_MSGQUEUE:
+		error = kernel_sysctlbyname(td,
+		    "kern.ipc.msgmnb", &res, &size, 0, 0, 0, 0);
+		if (error != 0)
+			return (false);
+		rlim->rlim_cur = res;
+		rlim->rlim_max = res;
+		return (true);
 	default:
 		return (false);
 	}
@@ -1181,7 +1198,7 @@ linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
 	struct rlimit bsd_rlim;
 	u_int which;
 
-	if (linux_get_dummy_limit(args->resource, &bsd_rlim)) {
+	if (linux_get_dummy_limit(td, args->resource, &bsd_rlim)) {
 		rlim.rlim_cur = bsd_rlim.rlim_cur;
 		rlim.rlim_max = bsd_rlim.rlim_max;
 		return (copyout(&rlim, args->rlim, sizeof(rlim)));
@@ -1222,7 +1239,7 @@ linux_getrlimit(struct thread *td, struct linux_getrlimit_args *args)
 	struct rlimit bsd_rlim;
 	u_int which;
 
-	if (linux_get_dummy_limit(args->resource, &bsd_rlim)) {
+	if (linux_get_dummy_limit(td, args->resource, &bsd_rlim)) {
 		rlim.rlim_cur = bsd_rlim.rlim_cur;
 		rlim.rlim_max = bsd_rlim.rlim_max;
 		return (copyout(&rlim, args->rlim, sizeof(rlim)));
@@ -2009,7 +2026,7 @@ linux_prlimit64(struct thread *td, struct linux_prlimit64_args *args)
 	int error;
 
 	if (args->new == NULL && args->old != NULL) {
-		if (linux_get_dummy_limit(args->resource, &rlim)) {
+		if (linux_get_dummy_limit(td, args->resource, &rlim)) {
 			lrlim.rlim_cur = rlim.rlim_cur;
 			lrlim.rlim_max = rlim.rlim_max;
 			return (copyout(&lrlim, args->old, sizeof(lrlim)));