Make linux getrlimit(2) and prlimit(2) return something reasonable

for linux-specific limits.  Fixes prlimit (util-linux-2.31.1-0.4ubuntu3.7).

Reviewed by:	emaste
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26777
This commit is contained in:
Edward Tomasz Napierala 2020-10-16 10:10:09 +00:00
parent ce764cbd1c
commit 139c09788b
2 changed files with 48 additions and 6 deletions

View File

@ -1373,6 +1373,28 @@ linux_getgroups(struct thread *td, struct linux_getgroups_args *args)
return (0);
}
static bool
linux_get_dummy_limit(l_uint resource, struct rlimit *rlim)
{
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;
return (true);
case LINUX_RLIMIT_NICE:
case LINUX_RLIMIT_RTPRIO:
rlim->rlim_cur = 0;
rlim->rlim_max = 0;
return (true);
default:
return (false);
}
}
int
linux_setrlimit(struct thread *td, struct linux_setrlimit_args *args)
{
@ -1405,6 +1427,12 @@ 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)) {
rlim.rlim_cur = bsd_rlim.rlim_cur;
rlim.rlim_max = bsd_rlim.rlim_max;
return (copyout(&rlim, args->rlim, sizeof(rlim)));
}
if (args->resource >= LINUX_RLIM_NLIMITS)
return (EINVAL);
@ -1440,6 +1468,12 @@ 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)) {
rlim.rlim_cur = bsd_rlim.rlim_cur;
rlim.rlim_max = bsd_rlim.rlim_max;
return (copyout(&rlim, args->rlim, sizeof(rlim)));
}
if (args->resource >= LINUX_RLIM_NLIMITS)
return (EINVAL);
@ -2138,6 +2172,14 @@ linux_prlimit64(struct thread *td, struct linux_prlimit64_args *args)
int flags;
int error;
if (args->new == NULL && args->old != NULL) {
if (linux_get_dummy_limit(args->resource, &rlim)) {
lrlim.rlim_cur = rlim.rlim_cur;
lrlim.rlim_max = rlim.rlim_max;
return (copyout(&lrlim, args->old, sizeof(lrlim)));
}
}
if (args->resource >= LINUX_RLIM_NLIMITS)
return (EINVAL);

View File

@ -137,12 +137,12 @@ extern int stclohz;
#define LINUX_P_PID 1
#define LINUX_P_PGID 2
#define LINUX_RLIMIT_LOCKS RLIM_NLIMITS + 1
#define LINUX_RLIMIT_SIGPENDING RLIM_NLIMITS + 2
#define LINUX_RLIMIT_MSGQUEUE RLIM_NLIMITS + 3
#define LINUX_RLIMIT_NICE RLIM_NLIMITS + 4
#define LINUX_RLIMIT_RTPRIO RLIM_NLIMITS + 5
#define LINUX_RLIMIT_RTTIME RLIM_NLIMITS + 6
#define LINUX_RLIMIT_LOCKS 10
#define LINUX_RLIMIT_SIGPENDING 11
#define LINUX_RLIMIT_MSGQUEUE 12
#define LINUX_RLIMIT_NICE 13
#define LINUX_RLIMIT_RTPRIO 14
#define LINUX_RLIMIT_RTTIME 15
#define LINUX_RLIM_INFINITY (~0UL)