openbsd-ext4/writeup/3.md

42 lines
1.9 KiB
Markdown
Raw Normal View History

# Mount source code
Let's look at OpenBSD's mounting, as present in `ext2fs_vfsops.c`.
The first two function declarations prove quite useful:
```c
int ext2fs_sbupdate(struct ufsmount *, int);
static int e2fs_sbcheck(struct ext2fs *, int);
```
The first thing we are concerned with, of course, is the super block. With that being said, let's keep reading.
Below that, we have a struct called `ext2fs_vfsops` which just contains values that are defined as certain constants (e.g. `.vfs_mount = ext2fs_mount`), but we don't care about that. Then we have the inode pool, the `ext2gennumber`, and below that, we have the initializer of the inode pool, which probably needs to be tweaked for 64-bit as well. No wonder nobody has done it 😅
At this point, we should see where in the mounting process ext4 fails. Create an ext4 filesystem using qemu and mount it; make sure that the virtual machine manager marks it as a readonly filesystem before mounting it to ensure that it doesn't get corrupted (at least, not yet).
2024-08-18 20:50:11 +02:00
Finally, on line 106 we have the `ext2fs_mountroot` function. This is where the bulk of our analysis will start.
```c
struct m_ext2fs *fs;
struct mount *mp;
struct proc *p = curproc; /* XXX */
struct ufsmount *ump;
int error;
/*
* Get vnodes for swapdev and rootdev.
*/
if (bdevvp(swapdev, &swapdev_vp) || bdevvp(rootdev, &rootvp))
panic("ext2fs_mountroot: can't setup bdevvp's");
```
So here we have to figure out what exactly the bdevvp function is.
From the OpenBSD man page:
> bdevvp() will create a vnode for a block device, and is used for the root device and swap areas, among other things.
I guess our question starts at, what exactly is a virtual node? It's nothing more than "an abstract ayer on top of a more concrete filesystem." (Wikipedia).
Meaning nothing more than what we have to do in order for there to be no difference when we run `ls`, `cd`, `rm`, `mkdir`, etc. Abstractions are necessary.