Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3851959imc; Thu, 14 Mar 2019 06:48:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYghTyVa5X3amnw8ywvsAZe1xr8IYvPw7lDRS5QHFxRN+4Vo+KY1eTe9GUDseNVtHnHNNF X-Received: by 2002:a62:ee13:: with SMTP id e19mr49337042pfi.224.1552571289649; Thu, 14 Mar 2019 06:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552571289; cv=none; d=google.com; s=arc-20160816; b=t5YGDazPqbhV3clCQSPIi6FGMY7O44yY2jiZYgzE1bdwCPq0Thyl4rk+6htQtHhKhQ kvlgznhs6UbIHlZdbGQ6uaEDA/dPzpkXuaX7kxHMNRNcIiT2SviZfBsoY1cMaCAyx0yy 0hsUq3Nl8L+e9ajca3CT7BVS+bCkL6GsEKHodTcOEEeA2aVo0gh/3HySwMizniLyNtt9 OGzkGF1+0tXB7u+/IhX4/l9ZtHB/oBh6vJ4VqpCAJW5k85drRcvJ+oNYIWnP+MnI0urw oIdYp2SCenlURc0G0vbUX//gNARXxlTOzGn7PVkIaEdDRj0fSIJS4Snv8P+y0pgLjm6t BIFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=xhZ4hOldz7jGYHmBJUByIYmHsuzD2BXopMBgrB+6Mko=; b=oxivasgLgl10gQIHDR1XZV1TjX0usiVJKyjO+466Szk3oUbVz/FCnx/H+xLfYflF7+ 1Ea4SwoDTD4dm1+oouazqRYAIcWnidjJD2jtGaf1rQ5oYWgZsvrK++Qv+VDDQogxfUb9 vI1fP1jsZCO71aRfJuFn6pWB88Zi6dYGZLTFLlnRrUCnJG8OEIdIYIIo6KIUGrYubRXx TlIMnwuBZzqG4fu1XPdLQRM+Ojmcop4PZT1134Jv+2UnmkkMJwQXxZWi/ia8Emrecton TTDuQ3PguwfPz+ulcclBrBjXEgTlE6aZmSybB/ez5MrU8mXJLnwD3d2XKRhl2oK13CBV ps+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4si7983084pgk.195.2019.03.14.06.47.53; Thu, 14 Mar 2019 06:48:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727568AbfCNNpY (ORCPT + 99 others); Thu, 14 Mar 2019 09:45:24 -0400 Received: from ivanoab6.miniserver.com ([5.153.251.140]:42502 "EHLO www.kot-begemot.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727356AbfCNNpX (ORCPT ); Thu, 14 Mar 2019 09:45:23 -0400 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by www.kot-begemot.co.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1h4Qfg-0004DZ-9v; Thu, 14 Mar 2019 13:45:20 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.89) (envelope-from ) id 1h4Qfe-0002g7-ST; Thu, 14 Mar 2019 13:45:19 +0000 Subject: Re: [PATCH] um: remove uses of variable length arrays To: Bartosz Golaszewski Cc: Jeff Dike , Richard Weinberger , Bartosz Golaszewski , linux-um@lists.infradead.org, Linux Kernel Mailing List References: <20190312133047.16201-1-brgl@bgdev.pl> <56704758-ee74-0e9b-de1c-1dc94deda8d7@cambridgegreys.com> From: Anton Ivanov Message-ID: Date: Thu, 14 Mar 2019 13:45:18 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/03/2019 13:33, Bartosz Golaszewski wrote: > śr., 13 mar 2019 o 10:45 Anton Ivanov > napisał(a): >> On 12/03/2019 13:30, Bartosz Golaszewski wrote: >>> From: Bartosz Golaszewski >>> >>> While the affected code is run in user-mode, the build still warns >>> about it. Convert all uses of VLA to dynamic allocations. >>> >>> Signed-off-by: Bartosz Golaszewski >>> --- >>> arch/um/os-Linux/umid.c | 36 +++++++++++++++++++++++++++--------- >>> 1 file changed, 27 insertions(+), 9 deletions(-) >>> >>> diff --git a/arch/um/os-Linux/umid.c b/arch/um/os-Linux/umid.c >>> index 998fbb445458..e261656fe9d7 100644 >>> --- a/arch/um/os-Linux/umid.c >>> +++ b/arch/um/os-Linux/umid.c >>> @@ -135,12 +135,18 @@ static int remove_files_and_dir(char *dir) >>> */ >>> static inline int is_umdir_used(char *dir) >>> { >>> - char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; >>> - char pid[sizeof("nnnnn\0")], *end; >>> + char pid[sizeof("nnnnn\0")], *end, *file; >>> int dead, fd, p, n, err; >>> + size_t filelen; >>> >>> - n = snprintf(file, sizeof(file), "%s/pid", dir); >>> - if (n >= sizeof(file)) { >>> + err = asprintf(&file, "%s/pid", dir); >>> + if (err < 0) >>> + return 0; >>> + >>> + 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; >>> @@ -185,6 +191,7 @@ static inline int is_umdir_used(char *dir) >>> out_close: >>> close(fd); >>> out: >>> + free(file); >>> return 0; >>> } >>> >>> @@ -210,18 +217,21 @@ static int umdir_take_if_dead(char *dir) >>> >>> static void __init create_pid_file(void) >>> { >>> - char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; >>> - char pid[sizeof("nnnnn\0")]; >>> + char pid[sizeof("nnnnn\0")], *file; >>> int fd, n; >>> >>> - if (umid_file_name("pid", file, sizeof(file))) >>> + file = malloc(strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")); >>> + if (!file) >>> return; >>> >>> + if (umid_file_name("pid", file, sizeof(file))) >>> + goto out; >>> + >>> fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0644); >>> if (fd < 0) { >>> printk(UM_KERN_ERR "Open of machine pid file \"%s\" failed: " >>> "%s\n", file, strerror(errno)); >>> - return; >>> + goto out; >>> } >>> >>> snprintf(pid, sizeof(pid), "%d\n", getpid()); >>> @@ -231,6 +241,8 @@ static void __init create_pid_file(void) >>> errno); >>> >>> close(fd); >>> +out: >>> + free(file); >>> } >>> >>> int __init set_umid(char *name) >>> @@ -385,13 +397,19 @@ __uml_setup("uml_dir=", set_uml_dir, >>> >>> static void remove_umid_dir(void) >>> { >>> - char dir[strlen(uml_dir) + UMID_LEN + 1], err; >>> + char *dir, err; >>> + >>> + dir = malloc(strlen(uml_dir) + UMID_LEN + 1); >>> + if (!dir) >>> + return; >>> >>> sprintf(dir, "%s%s", uml_dir, umid); >>> err = remove_files_and_dir(dir); >>> if (err) >>> os_warn("%s - remove_files_and_dir failed with err = %d\n", >>> __func__, err); >>> + >>> + free(dir); >>> } >>> >>> __uml_exitcall(remove_umid_dir); >>> >> Thanks for bringing it up. It helped me notice that this is actually broken. >> >> PID can be more than 5 digits nowdays. >> >> -- > Do you want to take this patch anyway and then apply the fix for the > array on top of that or do you prefer it be fixed before that? > > Bart > I am OK to take it as is and have the PID length fixed after that. -- Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/