Skip to contentSkip to conversation

Reimplement RLIMIT_MSGQUEUE on top of ucounts

PATCH In review Ma, XinjianX 3 participants 9 messages Aug 17, 2021 – Aug 24, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

Hi Alexey,

When lkp team run kernel selftests, we found after these series of patches, testcase mqueue: mq_perf_tests in kselftest failed with following message.

If you confirm and fix the issue, kindly add following tag as appropriate

```
# selftests: mqueue: mq_perf_tests
#
# Initial system state:
#       Using queue path:                       /mq_perf_tests
#       RLIMIT_MSGQUEUE(soft):                  819200
#       RLIMIT_MSGQUEUE(hard):                  819200
#       Maximum Message Size:                   8192
#       Maximum Queue Size:                     10
#       Nice value:                             0
#
# Adjusted system state for testing:
#       RLIMIT_MSGQUEUE(soft):                  (unlimited)
#       RLIMIT_MSGQUEUE(hard):                  (unlimited)
#       Maximum Message Size:                   16777216
#       Maximum Queue Size:                     65530
#       Nice value:                             -20
#       Continuous mode:                        (disabled)
#       CPUs to pin:                            3
# ./mq_perf_tests: mq_open() at 296: Too many open files
not ok 2 selftests: mqueue: mq_perf_tests # exit=1
```    

Test env:
rootfs: debian-10
gcc version: 9

------
Thanks
Ma Xinjian

#1 lore raw
Quoted 4 lines · XinjianX

Hi Alexey,

When lkp team run kernel selftests, we found after these series of patches, testcase mqueue: mq_perf_tests in kselftest failed with following message.

Which kernel was this run against?

Where can the mq_perf_tests that you ran and had problems with be found?

During your run were you using user namespaces as part of your test environment?

The error message too many files corresponds to the error code EMFILES which is the error code that is returned when the rlimit is reached.

One possibility is that your test environment was run in a user namespace and so you wound up limited by rlimit of the user who created the user namespace at the point of user namespace creation.

At this point if you can give us enough information to look into this and attempt to reproduce it that would be appreciated.

Quoted 26 lines

If you confirm and fix the issue, kindly add following tag as appropriate

```
# selftests: mqueue: mq_perf_tests
#
# Initial system state:
#       Using queue path:                       /mq_perf_tests
#       RLIMIT_MSGQUEUE(soft):                  819200
#       RLIMIT_MSGQUEUE(hard):                  819200
#       Maximum Message Size:                   8192
#       Maximum Queue Size:                     10
#       Nice value:                             0
#
# Adjusted system state for testing:
#       RLIMIT_MSGQUEUE(soft):                  (unlimited)
#       RLIMIT_MSGQUEUE(hard):                  (unlimited)
#       Maximum Message Size:                   16777216
#       Maximum Queue Size:                     65530
#       Nice value:                             -20
#       Continuous mode:                        (disabled)
#       CPUs to pin:                            3
# ./mq_perf_tests: mq_open() at 296: Too many open files
not ok 2 selftests: mqueue: mq_perf_tests # exit=1
```    
Quoted 7 lines

Test env:
rootfs: debian-10
gcc version: 9

------
Thanks
Ma Xinjian

Eric

#2 lore raw
Quoted 17 lines · Eric W. Biederman
Quoted 4 lines · XinjianX

Hi Alexey,

When lkp team run kernel selftests, we found after these series of patches, testcase mqueue: mq_perf_tests in kselftest failed with following message.

Which kernel was this run against?

Where can the mq_perf_tests that you ran and had problems with be found?

During your run were you using user namespaces as part of your test environment?

The error message too many files corresponds to the error code EMFILES which is the error code that is returned when the rlimit is reached.

Quoted 6 lines

One possibility is that your test environment was run in a user namespace and so you wound up limited by rlimit of the user who created the user namespace at the point of user namespace creation.

At this point if you can give us enough information to look into this and attempt to reproduce it that would be appreciated.

I was able to reproduce it on master without using user namespace. I suspect that the maximum value is not assigned here [1]:

set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE, task_rlimit(&init_task, RLIMIT_MSGQUEUE));

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/fork.c#n832

Quoted 36 lines
Quoted 26 lines

If you confirm and fix the issue, kindly add following tag as appropriate

```
# selftests: mqueue: mq_perf_tests
#
# Initial system state:
#       Using queue path:                       /mq_perf_tests
#       RLIMIT_MSGQUEUE(soft):                  819200
#       RLIMIT_MSGQUEUE(hard):                  819200
#       Maximum Message Size:                   8192
#       Maximum Queue Size:                     10
#       Nice value:                             0
#
# Adjusted system state for testing:
#       RLIMIT_MSGQUEUE(soft):                  (unlimited)
#       RLIMIT_MSGQUEUE(hard):                  (unlimited)
#       Maximum Message Size:                   16777216
#       Maximum Queue Size:                     65530
#       Nice value:                             -20
#       Continuous mode:                        (disabled)
#       CPUs to pin:                            3
# ./mq_perf_tests: mq_open() at 296: Too many open files
not ok 2 selftests: mqueue: mq_perf_tests # exit=1
```    
Quoted 7 lines

Test env:
rootfs: debian-10
gcc version: 9

------
Thanks
Ma Xinjian

Eric

Signature · 1 line
Rgrds, legion
#3 lore raw
Quoted 45 lines

-----Original Message-----
From: Alexey Gladkov <[email protected]>
Sent: Wednesday, August 18, 2021 9:11 PM
To: Eric W. Biederman <[email protected]>
Cc: Ma, XinjianX <[email protected]>; [email protected]; lkp <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; kernel- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v11 5/9] Reimplement RLIMIT_MSGQUEUE on top of ucounts

Quoted 6 lines · Eric W. Biederman
Quoted 4 lines · XinjianX

Hi Alexey,

When lkp team run kernel selftests, we found after these series of patches, testcase mqueue: mq_perf_tests in kselftest failed with

following message.

Quoted 4 lines

Which kernel was this run against?

Where can the mq_perf_tests that you ran and had problems with be

found?

Quoted 7 lines

During your run were you using user namespaces as part of your test environment?

The error message too many files corresponds to the error code EMFILES which is the error code that is returned when the rlimit is reached.

Quoted 6 lines

One possibility is that your test environment was run in a user namespace and so you wound up limited by rlimit of the user who created the user namespace at the point of user namespace creation.

At this point if you can give us enough information to look into this and attempt to reproduce it that would be appreciated.

I was able to reproduce it on master without using user namespace. I suspect that the maximum value is not assigned here [1]:

Quoted 6 lines

set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE, task_rlimit(&init_task, RLIMIT_MSGQUEUE));

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kerne
l/fork.c#n832

Thank you for confirming the issue. And will you plan to fix this issue? If it's your plan, kindly add following tag as appropriate

Quoted 41 lines
Quoted 32 lines
Quoted 32 lines

If you confirm and fix the issue, kindly add following tag as appropriate

```
# selftests: mqueue: mq_perf_tests
#
# Initial system state:
#       Using queue path:                       /mq_perf_tests
#       RLIMIT_MSGQUEUE(soft):                  819200
#       RLIMIT_MSGQUEUE(hard):                  819200
#       Maximum Message Size:                   8192
#       Maximum Queue Size:                     10
#       Nice value:                             0
#
# Adjusted system state for testing:
#       RLIMIT_MSGQUEUE(soft):                  (unlimited)
#       RLIMIT_MSGQUEUE(hard):                  (unlimited)
#       Maximum Message Size:                   16777216
#       Maximum Queue Size:                     65530
#       Nice value:                             -20
#       Continuous mode:                        (disabled)
#       CPUs to pin:                            3
# ./mq_perf_tests: mq_open() at 296: Too many open files not ok 2
selftests: mqueue: mq_perf_tests # exit=1
```

Test env:
rootfs: debian-10
gcc version: 9

Quoted 6 lines
Quoted 3 lines

------
Thanks
Ma Xinjian

Eric

--
Rgrds, legion

#4 lore raw
In reply to Alexey Gladkov
Quoted 25 lines · Alexey Gladkov
Quoted 17 lines · Eric W. Biederman
Quoted 4 lines · XinjianX

Hi Alexey,

When lkp team run kernel selftests, we found after these series of patches, testcase mqueue: mq_perf_tests in kselftest failed with following message.

Which kernel was this run against?

Where can the mq_perf_tests that you ran and had problems with be found?

During your run were you using user namespaces as part of your test environment?

The error message too many files corresponds to the error code EMFILES which is the error code that is returned when the rlimit is reached.

Quoted 6 lines

One possibility is that your test environment was run in a user namespace and so you wound up limited by rlimit of the user who created the user namespace at the point of user namespace creation.

At this point if you can give us enough information to look into this and attempt to reproduce it that would be appreciated.

Quoted 6 lines

I was able to reproduce it on master without using user namespace. I suspect that the maximum value is not assigned here [1]:

set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE, task_rlimit(&init_task, RLIMIT_MSGQUEUE));

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/fork.c#n832

The rlimits for init_task are set to INIT_RLIMITS. In INIT_RLIMITS RLIMIT_MSGQUEUE is set to MQ_MAX_BYTES

So that definitely means that as the code is current constructed the rlimit can not be effectively raised.

So it looks like we are just silly and preventing the initial rlimits from being raised.

So we probably want to do something like:

kernel/fork.c +4 -4
index bc94b2cc5995..557ce0083ba3 100644
@@ -825,13 +825,13 @@ void __init fork_init(void)
 	init_task.signal->rlim[RLIMIT_SIGPENDING] =
 		init_task.signal->rlim[RLIMIT_NPROC];
 
+	/* For non-rlimit ucounts make their default limit max_threads/2 */
 	for (i = 0; i < MAX_PER_NAMESPACE_UCOUNTS; i++)
 		init_user_ns.ucount_max[i] = max_threads/2;
 
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_NPROC, task_rlimit(&init_task, RLIMIT_NPROC));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE, task_rlimit(&init_task, RLIMIT_MSGQUEUE));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_SIGPENDING, task_rlimit(&init_task, RLIMIT_SIGPENDING));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MEMLOCK, task_rlimit(&init_task, RLIMIT_MEMLOCK));
+	/* In init_user_ns default rlimit to be the only limit */
+	for (; i < UCOUNT_COUNTS; i++)
+		set_rlimit_ucount_max(&init_user_ns, i, RLIMIT_INFINITY);
 
 #ifdef CONFIG_VMAP_STACK
 	cpuhp_setup_state(CPUHP_BP_PREPARE_DYN, "fork:vm_stack_cache",

Eric

#5 lore raw
Quoted 37 lines · Eric W. Biederman
Quoted 25 lines · Alexey Gladkov
Quoted 17 lines · Eric W. Biederman
Quoted 4 lines · XinjianX

Hi Alexey,

When lkp team run kernel selftests, we found after these series of patches, testcase mqueue: mq_perf_tests in kselftest failed with following message.

Which kernel was this run against?

Where can the mq_perf_tests that you ran and had problems with be found?

During your run were you using user namespaces as part of your test environment?

The error message too many files corresponds to the error code EMFILES which is the error code that is returned when the rlimit is reached.

Quoted 6 lines

One possibility is that your test environment was run in a user namespace and so you wound up limited by rlimit of the user who created the user namespace at the point of user namespace creation.

At this point if you can give us enough information to look into this and attempt to reproduce it that would be appreciated.

Quoted 6 lines

I was able to reproduce it on master without using user namespace. I suspect that the maximum value is not assigned here [1]:

set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE, task_rlimit(&init_task, RLIMIT_MSGQUEUE));

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/fork.c#n832

The rlimits for init_task are set to INIT_RLIMITS. In INIT_RLIMITS RLIMIT_MSGQUEUE is set to MQ_MAX_BYTES

Quoted 7 lines

So that definitely means that as the code is current constructed the rlimit can not be effectively raised.

So it looks like we are just silly and preventing the initial rlimits from being raised.

So we probably want to do something like:

Damn, you are faster than me! :)

Quoted 9 lines
kernel/fork.c +1 -0
index bc94b2cc5995..557ce0083ba3 100644
@@ -825,13 +825,13 @@ void __init fork_init(void)
 	init_task.signal->rlim[RLIMIT_SIGPENDING] =
 		init_task.signal->rlim[RLIMIT_NPROC];
 
+	/* For non-rlimit ucounts make their default limit max_threads/2 */

kernel/fork.c void __init fork_init(void) · line 834

Quoted 10 lines
kernel/fork.c +3 -4
 	for (i = 0; i < MAX_PER_NAMESPACE_UCOUNTS; i++)
 		init_user_ns.ucount_max[i] = max_threads/2;
 
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_NPROC, task_rlimit(&init_task, RLIMIT_NPROC));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE, task_rlimit(&init_task, RLIMIT_MSGQUEUE));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_SIGPENDING, task_rlimit(&init_task, RLIMIT_SIGPENDING));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MEMLOCK, task_rlimit(&init_task, RLIMIT_MEMLOCK));
+	/* In init_user_ns default rlimit to be the only limit */
+	for (; i < UCOUNT_COUNTS; i++)
+		set_rlimit_ucount_max(&init_user_ns, i, RLIMIT_INFINITY);

s/RLIMIT_INFINITY/RLIM_INFINITY/

kernel/fork.c void __init fork_init(void)

Quoted 4 lines
kernel/fork.c +0 -0
 #ifdef CONFIG_VMAP_STACK
 	cpuhp_setup_state(CPUHP_BP_PREPARE_DYN, "fork:vm_stack_cache",
 

I cannot complete this test on my laptop. On 4Gb, the test ends with oom-killer. But with this patch, the test definitely passes the moment of the previous fall.

Signature · 1 line
Rgrds, legion
#6 lore raw

PATCH 1/1 ucounts: Fix regression preventing increasing of rlimits in init_user_ns

"Ma, XinjianX" <[email protected]> reported:

Quoted 21 lines

When lkp team run kernel selftests, we found after these series of patches, testcase mqueue: mq_perf_tests in kselftest failed with following message.

# selftests: mqueue: mq_perf_tests
#
# Initial system state:

#       Using queue path:                       /mq_perf_tests
#       RLIMIT_MSGQUEUE(soft):                  819200
#       RLIMIT_MSGQUEUE(hard):                  819200
#       Maximum Message Size:                   8192
#       Maximum Queue Size:                     10
#       Nice value:                             0
#
# Adjusted system state for testing:
#       RLIMIT_MSGQUEUE(soft):                  (unlimited)
#       RLIMIT_MSGQUEUE(hard):                  (unlimited)
#       Maximum Message Size:                   16777216
#       Maximum Queue Size:                     65530
#       Nice value:                             -20
#       Continuous mode:                        (disabled)
#       CPUs to pin:                            3
Quoted 7 lines

# ./mq_perf_tests: mq_open() at 296: Too many open files not ok 2 selftests: mqueue: mq_perf_tests # exit=1 ```

Test env:
rootfs: debian-10
gcc version: 9

After investigation the problem turned out to be that ucount_max for the rlimits in init_user_ns was being set to the initial rlimit value. The practical problem is that ucount_max provides a limit that applications inside the user namespace can not exceed. Which means in practice that rlimits that have been converted to use the ucount infrastructure were not able to exceend their initial rlimits.

Solve this by setting the relevant values of ucount_max to RLIM_INIFINITY. A limit in init_user_ns is pointless so the code should allow the values to grow as large as possible without riscking an underflow or an overflow.

As the ltp test case was a bit of a pain I have reproduced the rlimit failure and tested the fix with the following little C program:

Quoted 43 lines

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>

int main(int argc, char **argv)

{
	struct mq_attr mq_attr;
	struct rlimit rlim;
	mqd_t mqd;
	int ret;

	ret = getrlimit(RLIMIT_MSGQUEUE, &rlim);
	if (ret != 0) {
		fprintf(stderr, "getrlimit(RLIMIT_MSGQUEUE) failed: %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}
	printf("RLIMIT_MSGQUEUE %lu %lu\n",
	       rlim.rlim_cur, rlim.rlim_max);
	rlim.rlim_cur = RLIM_INFINITY;
	rlim.rlim_max = RLIM_INFINITY;
	ret = setrlimit(RLIMIT_MSGQUEUE, &rlim);
	if (ret != 0) {
		fprintf(stderr, "setrlimit(RLIMIT_MSGQUEUE, RLIM_INFINITY) failed: %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}

	memset(&mq_attr, 0, sizeof(struct mq_attr));
	mq_attr.mq_maxmsg = 65536 - 1;
	mq_attr.mq_msgsize = 16*1024*1024 - 1;

	mqd = mq_open("/mq_rlimit_test", O_RDONLY|O_CREAT, 0600, &mq_attr);
	if (mqd == (mqd_t)-1) {
		fprintf(stderr, "mq_open failed: %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}
Quoted 8 lines
	ret = mq_close(mqd);
	if (ret) {
		fprintf(stderr, "mq_close failed; %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}

	return EXIT_SUCCESS;
}
Fixes 6e52a9f0532f ("Reimplement RLIMIT_MSGQUEUE on top of ucounts")
Fixes d7c9e99aee48 ("Reimplement RLIMIT_MEMLOCK on top of ucounts")
Fixes d64696905554 ("Reimplement RLIMIT_SIGPENDING on top of ucounts")
Fixes 21d1c5e386bc ("Reimplement RLIMIT_NPROC on top of ucounts")

---

This is a simplified version of my previous change that I have tested and will push out to linux-next and then to Linus shortly.

 kernel/fork.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/fork.c +4 -4
index bc94b2cc5995..44f4c2d83763 100644
@@ -828,10 +828,10 @@ void __init fork_init(void)
 	for (i = 0; i < MAX_PER_NAMESPACE_UCOUNTS; i++)
 		init_user_ns.ucount_max[i] = max_threads/2;
 
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_NPROC, task_rlimit(&init_task, RLIMIT_NPROC));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE, task_rlimit(&init_task, RLIMIT_MSGQUEUE));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_SIGPENDING, task_rlimit(&init_task, RLIMIT_SIGPENDING));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MEMLOCK, task_rlimit(&init_task, RLIMIT_MEMLOCK));
+	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_NPROC,      RLIM_INFINITY);
+	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE,   RLIM_INFINITY);
+	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_SIGPENDING, RLIM_INFINITY);
+	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MEMLOCK,    RLIM_INFINITY);
 
 #ifdef CONFIG_VMAP_STACK
 	cpuhp_setup_state(CPUHP_BP_PREPARE_DYN, "fork:vm_stack_cache",
Signature · 1 line
2.20.1
#7 lore raw

RE: [PATCH] ucounts: Fix regression preventing increasing of rlimits in init_user_ns

Quoted 112 lines

-----Original Message-----
From: Eric W. Biederman <[email protected]>
Sent: Tuesday, August 24, 2021 5:07 AM
To: Alexey Gladkov <[email protected]>
Cc: Ma, XinjianX <[email protected]>; [email protected]; lkp <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; kernel- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH] ucounts: Fix regression preventing increasing of rlimits in init_user_ns

"Ma, XinjianX" <[email protected]> reported:

Quoted 2 lines

When lkp team run kernel selftests, we found after these series of patches, testcase mqueue: mq_perf_tests in kselftest failed with following

message.

Quoted 19 lines

# selftests: mqueue: mq_perf_tests
#
# Initial system state:

#       Using queue path:                       /mq_perf_tests
#       RLIMIT_MSGQUEUE(soft):                  819200
#       RLIMIT_MSGQUEUE(hard):                  819200
#       Maximum Message Size:                   8192
#       Maximum Queue Size:                     10
#       Nice value:                             0
#
# Adjusted system state for testing:
#       RLIMIT_MSGQUEUE(soft):                  (unlimited)
#       RLIMIT_MSGQUEUE(hard):                  (unlimited)
#       Maximum Message Size:                   16777216
#       Maximum Queue Size:                     65530
#       Nice value:                             -20
#       Continuous mode:                        (disabled)
#       CPUs to pin:                            3
Quoted 6 lines

# ./mq_perf_tests: mq_open() at 296: Too many open files not ok 2
selftests: mqueue: mq_perf_tests # exit=1 ```

Test env:
rootfs: debian-10
gcc version: 9

After investigation the problem turned out to be that ucount_max for the rlimits in init_user_ns was being set to the initial rlimit value. The practical problem is that ucount_max provides a limit that applications inside the user namespace can not exceed. Which means in practice that rlimits that have been converted to use the ucount infrastructure were not able to exceend their initial rlimits.

Solve this by setting the relevant values of ucount_max to RLIM_INIFINITY. A limit in init_user_ns is pointless so the code should allow the values to grow as large as possible without riscking an underflow or an overflow.

As the ltp test case was a bit of a pain I have reproduced the rlimit failure and tested the fix with the following little C program:

Quoted 13 lines

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>

int main(int argc, char **argv)

Quoted 9 lines
{
	struct mq_attr mq_attr;
	struct rlimit rlim;
	mqd_t mqd;
	int ret;

	ret = getrlimit(RLIMIT_MSGQUEUE, &rlim);
	if (ret != 0) {
		fprintf(stderr, "getrlimit(RLIMIT_MSGQUEUE) failed: %s\n",

strerror(errno));

Quoted 9 lines
		exit(EXIT_FAILURE);
	}
	printf("RLIMIT_MSGQUEUE %lu %lu\n",
	       rlim.rlim_cur, rlim.rlim_max);
	rlim.rlim_cur = RLIM_INFINITY;
	rlim.rlim_max = RLIM_INFINITY;
	ret = setrlimit(RLIMIT_MSGQUEUE, &rlim);
	if (ret != 0) {
		fprintf(stderr, "setrlimit(RLIMIT_MSGQUEUE, RLIM_INFINITY)

failed: %s\n", strerror(errno));

Quoted 8 lines
		exit(EXIT_FAILURE);
	}

	memset(&mq_attr, 0, sizeof(struct mq_attr));
	mq_attr.mq_maxmsg = 65536 - 1;
	mq_attr.mq_msgsize = 16*1024*1024 - 1;

	mqd = mq_open("/mq_rlimit_test", O_RDONLY|O_CREAT, 0600,

&mq_attr);

Quoted 10 lines
	if (mqd == (mqd_t)-1) {
		fprintf(stderr, "mq_open failed: %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}
	ret = mq_close(mqd);
	if (ret) {
		fprintf(stderr, "mq_close failed; %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}
Quoted 8 lines
Quoted 2 lines
	return EXIT_SUCCESS;
}
Fixes 6e52a9f0532f ("Reimplement RLIMIT_MSGQUEUE on top of ucounts")
Fixes d7c9e99aee48 ("Reimplement RLIMIT_MEMLOCK on top of ucounts")
Fixes d64696905554 ("Reimplement RLIMIT_SIGPENDING on top of ucounts")
Fixes 21d1c5e386bc ("Reimplement RLIMIT_NPROC on top of ucounts")

Sorry, but <> around email address is needed

Quoted 40 lines

---

This is a simplified version of my previous change that I have tested and will push out to linux-next and then to Linus shortly.

 kernel/fork.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/fork.c index bc94b2cc5995..44f4c2d83763 renamed from kernel/fork.c +0 -0

100644

kernel/fork.c +0 -4
@@ -828,10 +828,10 @@ void __init fork_init(void)
 	for (i = 0; i < MAX_PER_NAMESPACE_UCOUNTS; i++)
 		init_user_ns.ucount_max[i] = max_threads/2;
 
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_NPROC,
 task_rlimit(&init_task, RLIMIT_NPROC));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE,
 task_rlimit(&init_task, RLIMIT_MSGQUEUE));
-	set_rlimit_ucount_max(&init_user_ns,
 UCOUNT_RLIMIT_SIGPENDING, task_rlimit(&init_task, RLIMIT_SIGPENDING));
-	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MEMLOCK,

task_rlimit(&init_task, RLIMIT_MEMLOCK));

kernel/fork.c +1 -0
+	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_NPROC,

RLIM_INFINITY);

kernel/fork.c +1 -0
+	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MSGQUEUE,

RLIM_INFINITY);

kernel/fork.c +1 -0
+	set_rlimit_ucount_max(&init_user_ns,

UCOUNT_RLIMIT_SIGPENDING, RLIM_INFINITY);

kernel/fork.c +1 -0
+	set_rlimit_ucount_max(&init_user_ns, UCOUNT_RLIMIT_MEMLOCK,

RLIM_INFINITY);

#ifdef CONFIG_VMAP_STACK
cpuhp_setup_state(CPUHP_BP_PREPARE_DYN,
"fork:vm_stack_cache",
--
2.20.1

#8 lore raw

Re: [PATCH] ucounts: Fix regression preventing increasing of rlimits in init_user_ns

Quoted 6 lines · XinjianX
Quoted 4 lines

-----Original Message-----
From: Eric W. Biederman <[email protected]>
...

Sorry, but <> around email address is needed

The change is already tested and pushed out so I really don't want to mess with it. Especially as I am aiming to send it to Linus on Wednesday after it has had a chance to pass through linux-next and whatever automated tests are there.

What does copying and pasting the Reported-by: tag as included in your original report cause to break?

At this point I suspect that the danger of fat fingering something far outweighs whatever benefits might be gained by surrounding the email address with <> marks.

Eric