Skip to content

Commit

Permalink
fix file permissions
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Allen <[email protected]>
  • Loading branch information
Paul Allen authored and paulcallen committed Jun 9, 2022
1 parent 992d802 commit a0678d0
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions crt/enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ int myst_retrieve_wanted_secrets()
goto done;
}

fchmod(fileno(file), S_IWUSR | S_IRUSR | S_IRGRP);

r = fwrite(release_secret.data, 1, release_secret.length, file);
fclose(file);
file = NULL;
Expand Down
2 changes: 1 addition & 1 deletion host/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int myst_write_file(const char* path, const void* data, size_t size)
size_t r = size;
ssize_t n;

if ((fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
if ((fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0640)) < 0)
ERAISE(-errno);

while ((n = write(fd, p, r)) > 0)
Expand Down
2 changes: 1 addition & 1 deletion kernel/udsdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static int _create_acceptor(const char* sun_path, acceptor_t** acceptor_out)
static int _create_uds_file(const char* path)
{
long ret = 0;
const int mode = 0666;
const int mode = 0600;
int fd = -1;

if ((fd = creat(path, mode)) < 0)
Expand Down
6 changes: 3 additions & 3 deletions tools/myst/host/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ long init_symbol_file_tmpdir(char* tmpdir)

if (!mkdtemp(tmpdir))
ERAISE(errno);
ECHECK(chmod(tmpdir, 0777));
ECHECK(chmod(tmpdir, 0750));

done:
return ret;
Expand Down Expand Up @@ -245,7 +245,7 @@ long myst_tcall_add_symbol_file(
{
ERAISE(-ENAMETOOLONG);
}
if ((fd = creat(tmp, 0666)) < 0)
if ((fd = creat(tmp, 0750)) < 0)
goto done;
}
}
Expand All @@ -261,7 +261,7 @@ long myst_tcall_add_symbol_file(
ERAISE(-ENAMETOOLONG);
}

if ((fd = creat(tmp, 0666)) < 0)
if ((fd = creat(tmp, 0750)) < 0)
goto done;
}

Expand Down
3 changes: 3 additions & 0 deletions tools/myst/host/mkext2/mkext2.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ static void _create_zero_filled_image(const char* path, size_t size)
if (!(is = fopen(path, "wb")))
_err("failed to open file for write: %s", path);

if (fchmod(fileno(is), S_IRUSR | S_IWUSR | S_IRGRP) != 0)
_err("failed to chmod file: %s", path);

if (fseek(is, size - sizeof(_block), SEEK_SET) != 0)
_err("failed to seek file: %s: %zu", path, size);

Expand Down
2 changes: 1 addition & 1 deletion tools/myst/host/package.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int _package(int argc, const char* argv[])
uint8_t page[PAGE_SIZE];
const int flags = O_CREAT | O_WRONLY | O_TRUNC;

if ((fd = open(rootfs_file, flags, 0666)) < 0)
if ((fd = open(rootfs_file, flags, 0640)) < 0)
_err("failed to create temporary file");

memset(page, 0, sizeof(page));
Expand Down
8 changes: 4 additions & 4 deletions utils/cpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ myst_cpio_t* myst_cpio_open(const char* path, uint32_t flags)

if ((flags & MYST_CPIO_FLAG_CREATE))
{
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640)) < 0)
GOTO(done);

if (write(fd, &_dot, _dot.size) != (ssize_t)_dot.size)
Expand All @@ -306,7 +306,7 @@ myst_cpio_t* myst_cpio_open(const char* path, uint32_t flags)
}
else
{
if ((fd = open(path, O_RDONLY, 0666)) < 0)
if ((fd = open(path, O_RDONLY, 0640)) < 0)
GOTO(done);

cpio->fd = fd;
Expand Down Expand Up @@ -631,7 +631,7 @@ int myst_cpio_unpack(const char* source, const char* target)
{
ssize_t n;

if ((fd = open(locals->path, O_WRONLY | O_CREAT, 0666)) < 0)
if ((fd = open(locals->path, O_WRONLY | O_CREAT, 0640)) < 0)
GOTO(done);

while ((n = myst_cpio_read_data(
Expand Down Expand Up @@ -1120,7 +1120,7 @@ int myst_cpio_mem_unpack(
ssize_t n = (ssize_t)locals->ent.size;

// ATTN: Can we replace 0666 with locals->ent.mode?
if ((fd = open(locals->path, O_WRONLY | O_CREAT, 0666)) < 0)
if ((fd = open(locals->path, O_WRONLY | O_CREAT, 0640)) < 0)
GOTO(done);

if (write(fd, file_data, (size_t)n) != n)
Expand Down

0 comments on commit a0678d0

Please sign in to comment.