um: Remove use of asprinf in umid.c
authorAnton Ivanov <anton.ivanov@cambridgegreys.com>
Fri, 13 Nov 2020 10:26:17 +0000 (10:26 +0000)
committerRichard Weinberger <richard@nod.at>
Sun, 13 Dec 2020 21:21:07 +0000 (22:21 +0100)
asprintf is not compatible with the existing uml memory allocation
mechanism. Its use on the "user" side of UML results in a corrupt slab
state.

Fixes: 0d4e5ac7e780 ("um: remove uses of variable length arrays")
Cc: stable@vger.kernel.org
Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
arch/um/os-Linux/umid.c

index 1d7558d..a3dd615 100644 (file)
@@ -137,20 +137,13 @@ static inline int is_umdir_used(char *dir)
 {
        char pid[sizeof("nnnnnnnnn")], *end, *file;
        int dead, fd, p, n, err;
-       size_t filelen;
+       size_t filelen = strlen(dir) + sizeof("/pid") + 1;
 
-       err = asprintf(&file, "%s/pid", dir);
-       if (err < 0)
-               return 0;
-
-       filelen = strlen(file);
+       file = malloc(filelen);
+       if (!file)
+               return -ENOMEM;
 
-       n = snprintf(file, filelen, "%s/pid", dir);
-       if (n >= filelen) {
-               printk(UM_KERN_ERR "is_umdir_used - pid filename too long\n");
-               err = -E2BIG;
-               goto out;
-       }
+       snprintf(file, filelen, "%s/pid", dir);
 
        dead = 0;
        fd = open(file, O_RDONLY);