From patchwork Sun May 27 15:49:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 921167 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40v4GW2zzHz9s1b for ; Mon, 28 May 2018 01:51:15 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0B5B4C21DF9; Sun, 27 May 2018 15:50:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 10273C21DB6; Sun, 27 May 2018 15:49:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 032EAC21BE5; Sun, 27 May 2018 15:49:32 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id A6130C21C2F for ; Sun, 27 May 2018 15:49:32 +0000 (UTC) Received: from LPT2.fritz.box ([95.223.128.184]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LbR3e-1g27Ez2XDG-00ktBq; Sun, 27 May 2018 17:49:27 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Sun, 27 May 2018 17:49:18 +0200 Message-Id: <20180527154920.10959-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180527154920.10959-1-xypron.glpk@gmx.de> References: <20180527154920.10959-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:Y2P9lJ6mM/lr51IUkFRddf3qzCna6KiG5ExGdaixeiCFOk2AvyD tVZLdc1LJHqD+xMu14KjHERj0IVky9OfqOzqEJfw8nl0AsCp1YkybBHh4S0TIx79q2YZ936 Ay7imu48UX2n9QqY+vVmK+py78cmLhkexbKoStSCjBg48sx0umd3wQ+tk7zslMwuvvuH7in UAnyN9A1X3CQMFv3xjEiQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:BnbIrTBhFyE=:Hw3POOvqcKzH7UwzEVylx6 rT5NxQa0qNUFo82PIymNqbCDy1TfXRHGPBUI/t4HApRl9999gki86gFEiknfDchZflKI/L9uB Ya6C4lBc2XKz1X3/pNYtPQDHMxyJglxbTmw6Aq0hUxyT6//yyLyn8hAAL0DO8xM6Q8dPY/js/ PPgQ3BZImSImXnZ99PB3VY+DZ6uRVxeIi57LaBEspWvRLkd9+lA5raiLCCAPC7+xJKCXzWX+D kSmEa5yE8+df/P5t2TqwELJgD4tNE2pHob7Uerq3jxWvuRWRy230NZFL/aRY2Fz37BKj0bCrA kmi9OxpKC97UdM6EYwH113nnDWyD6SbrG7neKxmoJ+HuRoiquujfJAupyBD0hJqCligUbZH3l RXtgi6i0t4zD5p4C3FLZUdwpIda1vPXgGIHeinjg0jjpchueITLVHznt3zvb9Lzx77gbT7XJP 7JYanF3CYBb7kgwtUWW/7qvTRGx6pTTSwSweuTKhFVQ9K7rQADLOheo9pq3LaTF+KDrCg4Zp1 e611zfuDboB2Q2FZMpAC/mUgE/27nMgCDPxsJWRNDPlzDHSNKQ6optu5Cb7gdcremqSIZwTbX 79Fxs6cLxWh2Cds8gFPeg417AbVorrm1eKryF5J6J8UHjp73Oj4U/AkgXzakgRo5Bd2B6S9Qf eggY4dwh8pwpE9Z8WA7YeeJak79uq+dneu8T9VuUn7whHCx/vxGYByx8RkDt7W22l9vb2JqLS ZBrSJnMhRlmP9WMCAWxTkIBli+ZlU2vM3wggMPsm3V8UtBetn0VGXW9UBKI= Cc: Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 1/3] fs: fat: cannot write to subdirectories X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" fs_fat_write() is not able to write to subdirectories. Currently if a filepath with a leading slash is passed, the slash is treated as part of the filename to be created in the root directory. Strip leading (back-)slashes. Check that the remaining filename does not contain any illegal characters (<>:"/\|?*). This way we will throw an error when trying to write to a subdirectory. Signed-off-by: Heinrich Schuchardt --- v2: use ISDIRDELIM() to identify (back-)slashes --- fs/fat/fat_write.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 5ca8fcda73c..c5aee519b79 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -908,9 +908,11 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, volume_info volinfo; fsdata datablock; fsdata *mydata = &datablock; - int cursect; + int cursect, i; int ret = -1, name_len; char l_filename[VFAT_MAXLEN_BYTES]; + char bad[2] = " "; + const char illegal[] = "<>:\"/\\|?*"; *actwrite = size; dir_curclust = 0; @@ -970,6 +972,18 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, } dentptr = (dir_entry *) do_fat_read_at_block; + /* Strip leading (back-)slashes */ + while ISDIRDELIM(*filename) + ++filename; + /* Check that the filename is valid */ + for (i = 0; i < strlen(illegal); ++i) { + *bad = illegal[i]; + if (strstr(filename, bad)) { + printf("FAT: illegal filename (%s)\n", filename); + return -1; + } + } + name_len = strlen(filename); if (name_len >= VFAT_MAXLEN_BYTES) name_len = VFAT_MAXLEN_BYTES - 1; From patchwork Sun May 27 15:49:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 921166 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40v4Fj0pFqz9s1b for ; Mon, 28 May 2018 01:50:33 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9BC52C21C27; Sun, 27 May 2018 15:49:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 44CD3C21C27; Sun, 27 May 2018 15:49:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E6EADC21C27; Sun, 27 May 2018 15:49:32 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lists.denx.de (Postfix) with ESMTPS id 982B6C21BE5 for ; Sun, 27 May 2018 15:49:32 +0000 (UTC) Received: from LPT2.fritz.box ([95.223.128.184]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MADqP-1fTskT0Rqb-00BHSL; Sun, 27 May 2018 17:49:28 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Sun, 27 May 2018 17:49:19 +0200 Message-Id: <20180527154920.10959-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180527154920.10959-1-xypron.glpk@gmx.de> References: <20180527154920.10959-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:teVCi9E0yK0gxQ4MPnfZp1hKjleWUbHeorZ64niP9275bsbSBdw NCNMoHamNnbaAT2TopNKirXBWl3NW+qi2BsmuZWROo0WQwowexGoxZ1qSE3qaV5kufGNADf OL1/bMe9jfafeFTs3WkspaEQers3eC+0hwVx8/caIhxwbKWbuVNDGHijAGMaAu2Ne5ekTM2 Yhgjr++LT6hcm3FWfUWkw== X-UI-Out-Filterresults: notjunk:1; V01:K0:eShz4Qxmg9M=:AFzkcpI+Vl8WlhgPjF0GGv rNO6DJ/eFgRa9pi+49eNqUVCFk2DS/M0xDV9l3iiU5N4THlPu7Kbzpf4L95T37UWddPdi5CqK 5huNoUaMgpTW6RoYrbQP7JVoKGApD+WzcFEJ0WBgT5qOPpg2f/gnUqUOff7ZMW/twM9uzOnIX CG9fofBw5Wl5gjFyhfhS0886OvRASgYqjFGjWTRmb+vsD4X+KczZMzqk/KmOn52INZGSYSp8Z LUCn7HVqb2FifmDg/YHpIG5ADp8AAbKgYcEDq031m2zfh/XqxP6lplXrzQaalIfNUJOdoncNc 9goSd0Ml2PdWp+A7omwKGSWu2b66qA2TLH+HVA3q86BiiFVvUtfmUGvBap/cWZ7t2OR4Bk/vS Q3OGkoNfr2mbrUsLSdR39jCPChGraxLbA2VYWxcRcTOGw8p0Te8RtOa9W/FzoYuzl21oTMbNT MNkF4BAXAqcyrUlRzNYQRL10RF+cvSghDNw59BMrnFrFft4hggGIV5m8DewLJqFI2gG6Ifv1V VVJG7eeCHASmkihXqnfoDsElZSnhlsfqdqvkyEV+VnfVl7i3n1l8jpoq8kXXBfDctjta42wHS cGI7tL+dahewqFoPvZ9ipMD8U2ANYl43Ldd9PNHQXK3VDNIq7OuFre+bh1xR+/iJpqPqAdYWV vi9IMbPLpqGJ5Mgl7oDBitnxZPVMLR4oH8k38seIt+TrBvqnurKVb97P6MQJUDr3THtWQd7vf aCJl1rnS4jTEfmlJsXrV7Sd82Ub1Ji4A4EuRBb65GXG1sCesqch5nN4vNMk= Cc: Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 2/3] efi_selftest: imply FAT, FAT_WRITE X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" efi_selftest_block_device accesses a FAT file system. Signed-off-by: Heinrich Schuchardt --- lib/efi_selftest/Kconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/efi_selftest/Kconfig b/lib/efi_selftest/Kconfig index 3b5f3a1230b..59f9f36801c 100644 --- a/lib/efi_selftest/Kconfig +++ b/lib/efi_selftest/Kconfig @@ -1,6 +1,8 @@ config CMD_BOOTEFI_SELFTEST bool "Allow booting an EFI efi_selftest" depends on CMD_BOOTEFI + imply FAT + imply FAT_WRITE help This adds an EFI test application to U-Boot that can be executed with the 'bootefi selftest' command. It provides extended tests of From patchwork Sun May 27 15:49:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 921168 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40v4Gk3bhjz9s1b for ; Mon, 28 May 2018 01:51:26 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 185DAC21E1B; Sun, 27 May 2018 15:50:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id DEB4CC21E15; Sun, 27 May 2018 15:49:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E49BDC21BE5; Sun, 27 May 2018 15:49:33 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lists.denx.de (Postfix) with ESMTPS id 7AB10C21BE5 for ; Sun, 27 May 2018 15:49:33 +0000 (UTC) Received: from LPT2.fritz.box ([95.223.128.184]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0M3eDF-1gDpUX2esT-00rKIT; Sun, 27 May 2018 17:49:28 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Sun, 27 May 2018 17:49:20 +0200 Message-Id: <20180527154920.10959-4-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180527154920.10959-1-xypron.glpk@gmx.de> References: <20180527154920.10959-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:iztLdm+WR8LMESI9awH5muZC25f/BpzazNru/M+Wq+Fe5B44TvD YgcbWCjQP2b0C2F0rgMUeGe+FXRGZJOy53ji/31m3zxZKROeEw9qHAizTXWAaiZ82wWTZCn mwwjLV+55pppoc+gHSmI+Z+KoEFu8n0sskTTPyxlUDaL+izn8HVMzVVnNMAblAUkxkH/thw scIk/Oht1NBUTTFBYCElw== X-UI-Out-Filterresults: notjunk:1; V01:K0:jcr+aHMSsvE=:/UZxvStsCPd6fJf7Uoc5vp je6OHMWj+eoAUrP9JL60fN4njLbZAbVssYIcDR2ZAOkS/fMCYKm5s8QBjOE8PByI3DX26Z/g6 VozfuWXhlP3SyJzBP84lV7JqrMbZifWHGafc0X2jOti+sowGAbcx+hkuazo4j/ulZGWezfMk0 6Cd3cXFhwEZCvg8+j8dxrEv3wGBYuzJC+gh+IZTnPh0G3726LRytIdWUvWXFtun7V6ZCfcIn+ DqgB7jVqorsT0Dw/kxLThfYzbGdH7h3Zj09z1wzP9wPcjZPSR4eGsdsIUFKijUCxH7XIJa7Ih ThKEkpS3Xo9p74gDBrKsA5BYAHvUgahWDwvSwqWAdXWaaXp25fFqDo0xPqIpeW0c916XS+ZXA MZf6SSq35ajp7dRvAc1suD+wiDQMwKnk9Y/ZuG5tFHzb5yoqsPkJa0cKVqvEolDaTsUVd339d fFIL0sYfp1OH8TqvBFhVW117HoFVEq2ggHD82REXy+tdeYLG8/qkCCWe8wHE/ziWcIeXuTkhC bONySrlSW1g6baIcrsL4uuc6TzP3vgA9w/el0yI7hFRcYVj9lgi66ZjJC08+8bmTJl38sPaFK fBOaN4L8IPJkqbN4kllwU8D8aW08PEHA1A7cc6kaDwNnKcj0pJGasptbUlBkeuMEgndHR8hKj UfdETtRcYNle2sYqp5kHguGwnDsk11NWALeRJ9dAY2Esh+gSEwhOPPBklqyOZu3fSyAVMqy1c hp1RkbMF/AMaBHfSimExtIPn4HGBord9LloKi7qbijlwbwPHeo5DxeOJsmA= Cc: Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 3/3] efi_selftest: test writing to file X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Provide a unit test for writing to a FAT file system. Add some additional comments in block device unit test. Signed-off-by: Heinrich Schuchardt --- v2 Avoid use after free due to calling root->close(root) too often. --- lib/efi_selftest/efi_selftest_block_device.c | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/lib/efi_selftest/efi_selftest_block_device.c b/lib/efi_selftest/efi_selftest_block_device.c index 4af8bd8cb28..6c655a94647 100644 --- a/lib/efi_selftest/efi_selftest_block_device.c +++ b/lib/efi_selftest/efi_selftest_block_device.c @@ -309,11 +309,14 @@ static int execute(void) efi_uintn_t buf_size; char buf[16] __aligned(ARCH_DMA_MINALIGN); + /* Connect controller to virtual disk */ ret = boottime->connect_controller(disk_handle, NULL, NULL, 1); if (ret != EFI_SUCCESS) { efi_st_error("Failed to connect controller\n"); return EFI_ST_FAILURE; } + + /* Get the handle for the partition */ ret = boottime->locate_handle_buffer( BY_PROTOCOL, &guid_device_path, NULL, &no_handles, &handles); @@ -347,6 +350,8 @@ static int execute(void) efi_st_error("Partition handle not found\n"); return EFI_ST_FAILURE; } + + /* Open the simple file system protocol */ ret = boottime->open_protocol(handle_partition, &guid_simple_file_system_protocol, (void **)&file_system, NULL, NULL, @@ -355,6 +360,8 @@ static int execute(void) efi_st_error("Failed to open simple file system protocol\n"); return EFI_ST_FAILURE; } + + /* Open volume */ ret = file_system->open_volume(file_system, &root); if (ret != EFI_SUCCESS) { efi_st_error("Failed to open volume\n"); @@ -377,6 +384,8 @@ static int execute(void) "Wrong volume label '%ps', expected 'U-BOOT TEST'\n", system_info.info.volume_label); } + + /* Read file */ ret = root->open(root, &file, (s16 *)L"hello.txt", EFI_FILE_MODE_READ, 0); if (ret != EFI_SUCCESS) { @@ -389,6 +398,11 @@ static int execute(void) efi_st_error("Failed to read file\n"); return EFI_ST_FAILURE; } + if (buf_size != 13) { + efi_st_error("Wrong number of bytes read: %u\n", + (unsigned int)buf_size); + return EFI_ST_FAILURE; + } if (efi_st_memcmp(buf, "Hello world!", 12)) { efi_st_error("Unexpected file content\n"); return EFI_ST_FAILURE; @@ -398,6 +412,58 @@ static int execute(void) efi_st_error("Failed to close file\n"); return EFI_ST_FAILURE; } + + /* Write file */ + ret = root->open(root, &file, (s16 *)L"u-boot.txt", + EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open file\n"); + return EFI_ST_FAILURE; + } + buf_size = 7; + boottime->set_mem(buf, sizeof(buf), 0); + boottime->copy_mem(buf, "U-Boot", buf_size); + ret = file->write(file, &buf_size, buf); + if (ret != EFI_SUCCESS || buf_size != 7) { + efi_st_error("Failed to write file\n"); + return EFI_ST_FAILURE; + } + ret = file->close(file); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to close file\n"); + return EFI_ST_FAILURE; + } + + /* Verify file */ + boottime->set_mem(buf, sizeof(buf), 0); + ret = root->open(root, &file, (s16 *)L"u-boot.txt", EFI_FILE_MODE_READ, + 0); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to open file\n"); + return EFI_ST_FAILURE; + } + buf_size = sizeof(buf) - 1; + ret = file->read(file, &buf_size, buf); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to read file\n"); + return EFI_ST_FAILURE; + } + if (buf_size != 7) { + efi_st_error("Wrong number of bytes read: %u\n", + (unsigned int)buf_size); + return EFI_ST_FAILURE; + } + if (efi_st_memcmp(buf, "U-Boot", 7)) { + efi_st_error("Unexpected file content %s\n", buf); + return EFI_ST_FAILURE; + } + ret = file->close(file); + if (ret != EFI_SUCCESS) { + efi_st_error("Failed to close file\n"); + return EFI_ST_FAILURE; + } + + /* Close volume */ ret = root->close(root); if (ret != EFI_SUCCESS) { efi_st_error("Failed to close volume\n");