lkml.org 
[lkml]   [2020]   [Dec]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.10 620/717] um: Remove use of asprinf in umid.c
    Date
    From: Anton Ivanov <anton.ivanov@cambridgegreys.com>

    commit 97be7ceaf7fea68104824b6aa874cff235333ac1 upstream.

    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>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    arch/um/os-Linux/umid.c | 17 +++++------------
    1 file changed, 5 insertions(+), 12 deletions(-)

    --- a/arch/um/os-Linux/umid.c
    +++ b/arch/um/os-Linux/umid.c
    @@ -137,20 +137,13 @@ static inline int is_umdir_used(char *di
    {
    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;
    + file = malloc(filelen);
    + if (!file)
    + return -ENOMEM;

    - filelen = strlen(file);
    -
    - 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);

    \
     
     \ /
      Last update: 2020-12-28 15:42    [W:2.739 / U:2.608 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site