src/bringup/bin/bootsvc/integration_test/integration-test.cc
// We simply check here whether files can be opened with OPEN_RIGHT_EXECUTABLE or not.
//
// Also, this test really needs to be able to open specific files, which unfortunately means some
// specific lists of files to test against that make this a bit fragile. Opening subdirectories
// doesn't get us coverage because we only limit the rights that you can open the files with.
We simply check here whether files can be opened with OPEN_RIGHT_EXECUTABLE or not.
Also, this test really needs to be able to open specific files, which unfortunately means some
specific lists of files to test against that make this a bit fragile. Opening subdirectories
doesn't get us coverage because we only limit the rights that you can open the files with.
We simply check here whether files can be opened with OPEN_RIGHT_EXECUTABLE or not . Also this test really needs to be able to open specific files which unfortunately means some specific lists of files to test against that make this a bit fragile . Opening subdirectories doesn ' t get us coverage because we only limit the rights that you can open the files with .
TEST(BootsvcIntegrationTest, BootfsExecutability) {
  const char* kExecutableFiles[] = {
      "/boot/pkg/bootsvc/bin/bootsvc", "/boot/pkg/dummy_pkg/lib/dummy.so",
      "/boot/driver/fragment.so",      "/boot/lib/dummy.so",
      "/boot/kernel/vdso/full",
  };
  for (const char* file : kExecutableFiles) {
    fbl::unique_fd fd;
    EXPECT_EQ(ZX_OK,
              fdio_open_fd(file, fio::OPEN_RIGHT_READABLE | fio::OPEN_RIGHT_EXECUTABLE,
                           fd.reset_and_get_address()),
              "open %s exec", file);
    zx::vmo vmo;
    EXPECT_EQ(ZX_OK, fdio_get_vmo_exec(fd.get(), vmo.reset_and_get_address()), "get_vmo_exec %s",
              file);
    EXPECT_TRUE(vmo.is_valid());
    EXPECT_EQ(ZX_RIGHT_EXECUTE, get_rights(vmo) & ZX_RIGHT_EXECUTE);
  }
  const char* kNonExecutableFiles[] = {
      "/boot/meta/fake.cm",
      "/boot/kernel/counters/desc",
  };
  for (const char* file : kNonExecutableFiles) {
    fbl::unique_fd fd;
    EXPECT_EQ(ZX_ERR_ACCESS_DENIED,
              fdio_open_fd(file, fio::OPEN_RIGHT_READABLE | fio::OPEN_RIGHT_EXECUTABLE,
                           fd.reset_and_get_address()),
              "open %s exec", file);
    EXPECT_EQ(ZX_OK, fdio_open_fd(file, fio::OPEN_RIGHT_READABLE, fd.reset_and_get_address()),
              "open %s read-only", file);
    zx::vmo vmo;
    EXPECT_EQ(ZX_OK, fdio_get_vmo_clone(fd.get(), vmo.reset_and_get_address()), "get_vmo_clone %s",
              file);
    EXPECT_EQ(ZX_ERR_INVALID_ARGS, fdio_get_vmo_exec(fd.get(), vmo.reset_and_get_address()),
              "get_vmo_exec %s", file);
  }
}
TEST ( BootsvcIntegrationTest , BootfsExecutability ) { const char * kExecutableFiles [ ] = { " " , " " , " " , " " , " " , } ; for ( const char * file : kExecutableFiles ) { fbl :: unique_fd fd ; EXPECT_EQ ( ZX_OK , fdio_open_fd ( file , fio :: OPEN_RIGHT_READABLE | fio :: OPEN_RIGHT_EXECUTABLE , fd . reset_and_get_address ( ) ) , " " , file ) ; zx :: vmo vmo ; EXPECT_EQ ( ZX_OK , fdio_get_vmo_exec ( fd . get ( ) , vmo . reset_and_get_address ( ) ) , " " , file ) ; EXPECT_TRUE ( vmo . is_valid ( ) ) ; EXPECT_EQ ( ZX_RIGHT_EXECUTE , get_rights ( vmo ) & ZX_RIGHT_EXECUTE ) ; } const char * kNonExecutableFiles [ ] = { " " , " " , } ; for ( const char * file : kNonExecutableFiles ) { fbl :: unique_fd fd ; EXPECT_EQ ( ZX_ERR_ACCESS_DENIED , fdio_open_fd ( file , fio :: OPEN_RIGHT_READABLE | fio :: OPEN_RIGHT_EXECUTABLE , fd . reset_and_get_address ( ) ) , " " , file ) ; EXPECT_EQ ( ZX_OK , fdio_open_fd ( file , fio :: OPEN_RIGHT_READABLE , fd . reset_and_get_address ( ) ) , " " , file ) ; zx :: vmo vmo ; EXPECT_EQ ( ZX_OK , fdio_get_vmo_clone ( fd . get ( ) , vmo . reset_and_get_address ( ) ) , " " , file ) ; EXPECT_EQ ( ZX_ERR_INVALID_ARGS , fdio_get_vmo_exec ( fd . get ( ) , vmo . reset_and_get_address ( ) ) , " " , file ) ; } }
We simply check here whether files can be opened with OPEN_RIGHT_EXECUTABLE or not.
We simply check here whether files can be opened with OPEN_RIGHT_EXECUTABLE or not .
// Because of particulars of how fdio works with vmofiles, this returns INVALID_ARGS on failure // instead of ACCESS_DENIED (basically because it fails during a handle_replace inside fdio).