kernel/time: Add max_time_namespaces ucount

Submitted by Jann Horn via Containers on April 6, 2020, 5:13 p.m.

Details

Message ID 20200406171342.128733-1-dima@arista.com
State New
Series "kernel/time: Add max_time_namespaces ucount"
Headers show

Commit Message

Jann Horn via Containers April 6, 2020, 5:13 p.m.
Introduce missing time namespaces limit per-userns.
Michael noticed that userns limit for number of time namespaces is
missing.

Furthermore, time namespace introduced UCOUNT_TIME_NAMESPACES, but
didn't introduce an array member in user_table[]. It would make array's
initialisation OOB write, but by luck the user_table array has
an excessive empty member (all accesses to the array are limited with
UCOUNT_COUNTS - so it silently reuses the last free member.

Fixes user-visible regression: max_inotify_instances by reason of the
missing UCOUNT_ENTRY() has limited max number of namespaces instead of
the number of inotify instances.

Fixes: 769071ac9f20 ("ns: Introduce Time Namespace")
Cc: Adrian Reber <adrian@lisas.de>
Cc: Andrey Vagin <avagin@openvz.org>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Containers <containers@lists.linux-foundation.org>
Cc: Linux API <linux-api@vger.kernel.org>
Cc: stable@kernel.org # v5.6+
Reported-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
Signed-off-by: Dmitry Safonov <dima@arista.com>
---
 Documentation/admin-guide/sysctl/user.rst | 6 ++++++
 kernel/ucount.c                           | 1 +
 2 files changed, 7 insertions(+)

Patch hide | download patch | download mbox

diff --git a/Documentation/admin-guide/sysctl/user.rst b/Documentation/admin-guide/sysctl/user.rst
index 650eaa03f15e..c45824589339 100644
--- a/Documentation/admin-guide/sysctl/user.rst
+++ b/Documentation/admin-guide/sysctl/user.rst
@@ -65,6 +65,12 @@  max_pid_namespaces
   The maximum number of pid namespaces that any user in the current
   user namespace may create.
 
+max_time_namespaces
+===================
+
+  The maximum number of time namespaces that any user in the current
+  user namespace may create.
+
 max_user_namespaces
 ===================
 
diff --git a/kernel/ucount.c b/kernel/ucount.c
index a53cc2b4179c..29c60eb4ec9b 100644
--- a/kernel/ucount.c
+++ b/kernel/ucount.c
@@ -69,6 +69,7 @@  static struct ctl_table user_table[] = {
 	UCOUNT_ENTRY("max_net_namespaces"),
 	UCOUNT_ENTRY("max_mnt_namespaces"),
 	UCOUNT_ENTRY("max_cgroup_namespaces"),
+	UCOUNT_ENTRY("max_time_namespaces"),
 #ifdef CONFIG_INOTIFY_USER
 	UCOUNT_ENTRY("max_inotify_instances"),
 	UCOUNT_ENTRY("max_inotify_watches"),

Comments

Andrei Vagin April 7, 2020, 3:31 a.m.
On Mon, Apr 06, 2020 at 06:13:42PM +0100, Dmitry Safonov via Containers wrote:
> Introduce missing time namespaces limit per-userns.
> Michael noticed that userns limit for number of time namespaces is
> missing.
> 
> Furthermore, time namespace introduced UCOUNT_TIME_NAMESPACES, but
> didn't introduce an array member in user_table[]. It would make array's
> initialisation OOB write, but by luck the user_table array has
> an excessive empty member (all accesses to the array are limited with
> UCOUNT_COUNTS - so it silently reuses the last free member.
> 
> Fixes user-visible regression: max_inotify_instances by reason of the
> missing UCOUNT_ENTRY() has limited max number of namespaces instead of
> the number of inotify instances.
> 
> Fixes: 769071ac9f20 ("ns: Introduce Time Namespace")
> Cc: Adrian Reber <adrian@lisas.de>
> Cc: Andrey Vagin <avagin@openvz.org>
> Cc: Christian Brauner <christian.brauner@ubuntu.com>
> Cc: Eric W. Biederman <ebiederm@xmission.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
> Cc: Containers <containers@lists.linux-foundation.org>
> Cc: Linux API <linux-api@vger.kernel.org>
> Cc: stable@kernel.org # v5.6+
> Reported-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>

Acked-by: Andrei Vagin <avagin@gmail.com>

> Signed-off-by: Dmitry Safonov <dima@arista.com>
Michael Kerrisk (man-pages) April 7, 2020, 8:22 a.m.
On Tue, 7 Apr 2020 at 05:31, Andrei Vagin <avagin@gmail.com> wrote:
>
> On Mon, Apr 06, 2020 at 06:13:42PM +0100, Dmitry Safonov via Containers wrote:
> > Introduce missing time namespaces limit per-userns.
> > Michael noticed that userns limit for number of time namespaces is
> > missing.
> >
> > Furthermore, time namespace introduced UCOUNT_TIME_NAMESPACES, but
> > didn't introduce an array member in user_table[]. It would make array's
> > initialisation OOB write, but by luck the user_table array has
> > an excessive empty member (all accesses to the array are limited with
> > UCOUNT_COUNTS - so it silently reuses the last free member.
> >
> > Fixes user-visible regression: max_inotify_instances by reason of the
> > missing UCOUNT_ENTRY() has limited max number of namespaces instead of
> > the number of inotify instances.
> >
> > Fixes: 769071ac9f20 ("ns: Introduce Time Namespace")
> > Cc: Adrian Reber <adrian@lisas.de>
> > Cc: Andrey Vagin <avagin@openvz.org>
> > Cc: Christian Brauner <christian.brauner@ubuntu.com>
> > Cc: Eric W. Biederman <ebiederm@xmission.com>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
> > Cc: Containers <containers@lists.linux-foundation.org>
> > Cc: Linux API <linux-api@vger.kernel.org>
> > Cc: stable@kernel.org # v5.6+
> > Reported-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
>
> Acked-by: Andrei Vagin <avagin@gmail.com>

Acked-by: Michael Kerrisk <mtk.manpages@gmail.com>
Vincenzo Frascino April 7, 2020, 9:16 a.m.
On 4/7/20 9:22 AM, Michael Kerrisk (man-pages) wrote:
> On Tue, 7 Apr 2020 at 05:31, Andrei Vagin <avagin@gmail.com> wrote:
>>
>> On Mon, Apr 06, 2020 at 06:13:42PM +0100, Dmitry Safonov via Containers wrote:
>>> Introduce missing time namespaces limit per-userns.
>>> Michael noticed that userns limit for number of time namespaces is
>>> missing.
>>>
>>> Furthermore, time namespace introduced UCOUNT_TIME_NAMESPACES, but
>>> didn't introduce an array member in user_table[]. It would make array's
>>> initialisation OOB write, but by luck the user_table array has
>>> an excessive empty member (all accesses to the array are limited with
>>> UCOUNT_COUNTS - so it silently reuses the last free member.
>>>
>>> Fixes user-visible regression: max_inotify_instances by reason of the
>>> missing UCOUNT_ENTRY() has limited max number of namespaces instead of
>>> the number of inotify instances.
>>>
>>> Fixes: 769071ac9f20 ("ns: Introduce Time Namespace")
>>> Cc: Adrian Reber <adrian@lisas.de>
>>> Cc: Andrey Vagin <avagin@openvz.org>
>>> Cc: Christian Brauner <christian.brauner@ubuntu.com>
>>> Cc: Eric W. Biederman <ebiederm@xmission.com>
>>> Cc: Ingo Molnar <mingo@redhat.com>
>>> Cc: Thomas Gleixner <tglx@linutronix.de>
>>> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
>>> Cc: Containers <containers@lists.linux-foundation.org>
>>> Cc: Linux API <linux-api@vger.kernel.org>
>>> Cc: stable@kernel.org # v5.6+
>>> Reported-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
>>
>> Acked-by: Andrei Vagin <avagin@gmail.com>
> 
> Acked-by: Michael Kerrisk <mtk.manpages@gmail.com>
> 
> 
> 

Acked-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Christian Brauner April 7, 2020, 10:43 a.m.
On Mon, Apr 06, 2020 at 06:13:42PM +0100, Dmitry Safonov via Containers wrote:
> Introduce missing time namespaces limit per-userns.
> Michael noticed that userns limit for number of time namespaces is
> missing.
> 
> Furthermore, time namespace introduced UCOUNT_TIME_NAMESPACES, but
> didn't introduce an array member in user_table[]. It would make array's
> initialisation OOB write, but by luck the user_table array has
> an excessive empty member (all accesses to the array are limited with
> UCOUNT_COUNTS - so it silently reuses the last free member.
> 
> Fixes user-visible regression: max_inotify_instances by reason of the
> missing UCOUNT_ENTRY() has limited max number of namespaces instead of
> the number of inotify instances.
> 
> Fixes: 769071ac9f20 ("ns: Introduce Time Namespace")
> Cc: Adrian Reber <adrian@lisas.de>
> Cc: Andrey Vagin <avagin@openvz.org>
> Cc: Christian Brauner <christian.brauner@ubuntu.com>
> Cc: Eric W. Biederman <ebiederm@xmission.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
> Cc: Containers <containers@lists.linux-foundation.org>
> Cc: Linux API <linux-api@vger.kernel.org>
> Cc: stable@kernel.org # v5.6+
> Reported-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
> Signed-off-by: Dmitry Safonov <dima@arista.com>

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>