memcg_write_event_control(): fix a user-triggerable oops
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 21 Jul 2024 18:45:08 +0000 (14:45 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 13 Aug 2024 01:58:44 +0000 (21:58 -0400)
we are *not* guaranteed that anything past the terminating NUL
is mapped (let alone initialized with anything sane).

Fixes: 0dea116876ee ("cgroup: implement eventfd-based generic API for notifications")
Cc: stable@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
mm/memcontrol-v1.c

index 2aeea4d8bf8e53b24748b431c16b4b72af22e923..417c96f2da28e8c3984792903d5daed1786a9e2b 100644 (file)
@@ -1842,9 +1842,12 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
        buf = endp + 1;
 
        cfd = simple_strtoul(buf, &endp, 10);
-       if ((*endp != ' ') && (*endp != '\0'))
+       if (*endp == '\0')
+               buf = endp;
+       else if (*endp == ' ')
+               buf = endp + 1;
+       else
                return -EINVAL;
-       buf = endp + 1;
 
        event = kzalloc(sizeof(*event), GFP_KERNEL);
        if (!event)