Skip to content

Commit

Permalink
Merge pull request #58 from alexlarsson/dentry-size
Browse files Browse the repository at this point in the history
Limit in-memory use for inodes
  • Loading branch information
alexlarsson authored Aug 23, 2022
2 parents 85149de + 0fbff50 commit 361f373
Show file tree
Hide file tree
Showing 9 changed files with 613 additions and 244 deletions.
37 changes: 16 additions & 21 deletions fuzzing/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ bool iter_cb(void *private, const char *name, int namelen, u64 ino, unsigned int
struct cfs_xattr_header_s *xattrs;
struct cfs_inode_s *s_ino;
struct cfs_inode_s buffer;
struct cfs_dir_s *dir;
struct cfs_dir_data_s dirdata;
loff_t out_size;
char *out_path;
char *payload;
int res;

if (test_ctx->dirs_left == 0)
return false;
Expand Down Expand Up @@ -67,11 +68,9 @@ bool iter_cb(void *private, const char *name, int namelen, u64 ino, unsigned int
free(xattrs);
}

dir = cfs_get_dir(test_ctx->ctx, s_ino, ino);
if (!IS_ERR(dir)) {
cfs_dir_get_link_count(dir);
cfs_dir_iterate(dir, 0, iter_cb, test_ctx);
free(dir);
res = cfs_get_dir_data(test_ctx->ctx, s_ino, ino, &dirdata);
if (res >= 0) {
cfs_dir_iterate(test_ctx->ctx, s_ino->payload_length, ino, &dirdata, 0, iter_cb, test_ctx);
}
return true;
}
Expand Down Expand Up @@ -129,12 +128,13 @@ int LLVMFuzzerTestOneInput(uint8_t *buf, size_t len)
struct cfs_context_s *ctx;
struct cfs_inode_s ino_buf;
struct cfs_inode_s *ino;
struct cfs_dir_s *dir;
struct cfs_dir_data_s dirdata;
char name[NAME_MAX];
char value[256];
u64 index;
u64 off;
int fd;
int res;

cfs_digest_from_payload((const char *) buf, len, digest_out);

Expand All @@ -156,16 +156,12 @@ int LLVMFuzzerTestOneInput(uint8_t *buf, size_t len)
for (off = 0; off < 1000; off++) {
ino = cfs_get_ino_index(ctx, off, &ino_buf);
if (!IS_ERR(ino)) {
struct cfs_dir_s *dir;

dir = cfs_get_dir(ctx, ino, off);
if (!IS_ERR(dir)) {
cfs_dir_get_link_count(dir);
if (dir) {
cfs_dir_lookup(dir, name, strlen(name), &index);
cfs_dir_iterate(dir, 0, iter_cb, &test_ctx);
}
free(dir);
res = cfs_get_dir_data(ctx, ino, off, &dirdata);
if (res >= 0) {
if ((ino->st_mode & S_IFMT) == S_IFDIR) {
cfs_dir_lookup(ctx, ino->payload_length, off, &dirdata, name, strlen(name), &index);
cfs_dir_iterate(ctx, ino->payload_length, off, &dirdata, 0, iter_cb, &test_ctx);
}
}
}
}
Expand All @@ -178,12 +174,11 @@ int LLVMFuzzerTestOneInput(uint8_t *buf, size_t len)
if (!IS_ERR(xattrs))
free(xattrs);

dir = cfs_get_dir(ctx, ino, index);
if (IS_ERR(dir))
res = cfs_get_dir_data(ctx, ino, index, &dirdata);
if (res < 0)
goto cleanup;

cfs_dir_iterate(dir, 0, iter_cb, &test_ctx);
free(dir);
cfs_dir_iterate(ctx, ino->payload_length, index, &dirdata, 0, iter_cb, &test_ctx);

cleanup:
cfs_destroy_ctx(ctx);
Expand Down
3 changes: 2 additions & 1 deletion kernel/Documentation/filesystems/composefs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ payload length attribute gives the size of the variable chunk.

The inode variable chunk contains different things depending on the
file type. For regular files it is the backing filename. For symlinks
it is the symlink target. For directories it is a list of dentries.
it is the symlink target. For directories it is a list of dentries,
stored in chunks of maximum 4k.

The variable data section is stored after the inode section, and you
can find it from the offset in the header. It contains Xattrs data
Expand Down
Loading

0 comments on commit 361f373

Please sign in to comment.