efi_selftest: block device: avoid read after free
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Fri, 21 Dec 2018 23:37:41 +0000 (00:37 +0100)
committerAlexander Graf <agraf@suse.de>
Sun, 23 Dec 2018 01:04:25 +0000 (02:04 +0100)
Reading the position in a file after closing the same results in a read
after free.

Correct the sequence in the test.

Reported-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
lib/efi_selftest/efi_selftest_block_device.c

index d4e4fac1c74421921e56228b40c154f3f7a7bf86..f038da9f1909dc2869f666633996ec93524fda64 100644 (file)
@@ -445,11 +445,6 @@ static int execute(void)
                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;
-       }
        ret = file->getpos(file, &pos);
        if (ret != EFI_SUCCESS) {
                efi_st_error("GetPosition failed\n");
@@ -460,6 +455,11 @@ static int execute(void)
                             (unsigned int)pos);
                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);