Skip to content

VFS: Initial procfs support #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2023
Merged

VFS: Initial procfs support #88

merged 1 commit into from
Mar 17, 2023

Conversation

trungnt2910
Copy link
Collaborator

This patch contains changes for procfs support, as well as fixing some bugs in the VFS system:

  • Fixed some more buffer overflow bugs.
  • Fixed traversing across mount boundaries.
  • Fixed errno when doing an unsupported operation on a device. (EPERM, not EOPNOTSUPP).

Currently only a few static files (filesystems, meminfo, mounts, self, uptime), as well as the folder corresponding to the current process and its static contents (cwd, exe, mounts, root) are supported. For further support, blink must have some method to register, manage and query shared process information.

This patch contains changes for procfs support, as well as fixing
some bugs in the VFS system:
- Fixed some more buffer overflow bugs.
- Fixed traversing across mount boundaries.
- Fixed `errno` when doing an unsupported operation on a device.
(`EPERM`, not `EOPNOTSUPP`).

Currently only a few static files (`filesystems`, `meminfo`, `mounts`,
`self`, `uptime`), as well as the folder corresponding to the current
process and its static contents (`cwd`, `exe`, `mounts`, `root`) are
supported. For further support, `blink` must have some method to
register, manage and query shared process information.
Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

struct HostfsDevice *hostfsdevice = (struct HostfsDevice *)device->data;
*spec = strdup(hostfsdevice->source);
if (*spec == NULL) {
return enomem();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just return -1 in cases like this, because strdup already set the errno.

@@ -128,6 +128,21 @@ int HostfsInit(const char *source, u64 flags, const void *data,
return -1;
}

int HostfsReadmountentry(struct VfsDevice *device, char **spec, char **type, char **mntops) {
struct HostfsDevice *hostfsdevice = (struct HostfsDevice *)device->data;
*spec = strdup(hostfsdevice->source);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One best practice for API design in C is that the output parameters should only be modified on success. There's very few exceptions to this rule. But it's mostly an issue for public APIs.

// TODO(trungnt): This should be dynamically allocated when we support
// more processes.
(*info)->ino = PROCFS_FIRST_PID_INO;
sprintf((*info)->name, "%d", pid);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend against using sprintf() because it's one of those functions that triggers security people and attracts attention from scanners.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used sprintf at that once instance as I wonder how a 32-bit int can take more than 16 chars to represent.

@jart jart merged commit 325a5f8 into jart:master Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants