Commit Graph

13 Commits

Author SHA1 Message Date
Ernesto A. Fernández 82324fb015 Make record key size checks more strict
For safety, I think it's always better for a filesystem to reject any
malformed data it can notice. Omap and free queue keys have a fixed
size, so the size check we run to prevent out-of-bounds reads, while
correct, should be made more strict. This is what we already do for most
record types these days, both keys and values.

Take this opportunity to improve the code style here and make it more
consistent.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2024-12-04 18:28:20 -03:00
Ernesto A. Fernández d4797823ea Improve error reporting
The driver is much closer to being usable, so I might start getting
subtler bug reports soon. To make them easier to handle, put error
messages all over the place. I should have done this from the beginning,
but I guess I didn't fully understand the need back then.

From now my general policy will be to use apfs_warn() for user errors or
unsupported features; apfs_err() for things that are probably corruption
or io errors; and apfs_alert() for things that are most likely bugs.
These last two should be rare, so the same error/alert will be thrown by
several layers in the callstack to provide as much information as
possible. Be careful and don't flood the console on normal situations.

Also, make messages with a log level lower than warning output their
function name and line number, which I think will help debugging more
than the actual messages.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2023-04-05 21:59:24 -03:00
Ernesto A. Fernández 14a15bd372 Add support for sealed volume reads
Add suport for reads from sealed volumes. The main differences are that
catalog index nodes are bigger, and that file extents are kept in a
separate tree.

Writes could in theory be supported as well, as we do in our internal
tool. It would probably be a bit too hacky though, so I'll wait to see
if anybody asks for it.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2023-01-13 23:12:19 -03:00
Ernesto A. Fernández 97863ab914 Add support for taking snapshots
Implement an ioctl that creates a snapshot for the current transaction.
A matching userland tool has already been added to apfsprogs.

Note that, at this point, snapshots won't be handled correctly on later
writes at all. Being able to actually create snapshots for testing is
only the first step in that direction.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2023-01-06 19:38:54 -03:00
Ernesto A. Fernández 6ca7c7c72a Don't pass the superblock to apfs_keycmp()
Get rid of the unused 'sb' parameter of apfs_keycmp().

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2022-03-01 21:47:41 -03:00
Ernesto A. Fernández abd9238fbf Fix warnings on documentation build
I've been trying to document functions in kernel-doc style since the
beginning, but I had never actually run the kernel-doc script. Fix two
issues with function parameters that were changed without updating the
comments. Also stop documenting multiple arguments in one line, which
doesn't seem to be allowed.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2022-03-01 19:11:15 -03:00
Ernesto A. Fernández 441540d919 Remove unused argument to apfs_init_drec_key()
The 'hashed' argument is never used by apfs_init_drec_key(), since we
can figure that out from the superblock. Get rid of it.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2022-02-03 16:50:24 -03:00
Ernesto A. Fernández dc1ed2cfe7 Rename SPDX license identifier
It seems that the license identifier currently in use (GPL-2.0) has been
deprecated:

  https://spdx.org/licenses/GPL-2.0.html

I don't know how important this is in practice, but I've received some
complaints about it:

  https://github.com/linux-apfs/linux-apfs-rw/issues/18

So, just run

  sed -i 's/2\.0/2.0-only/' *.{c,h}
  sed -i 's/2\.0/2.0-only/' Makefile

and change it to GPL-2.0-only.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2021-11-16 18:41:54 -03:00
Ernesto A. Fernández 07585e3d68 Get the dentry cache to work
Profiling has shown that the module spends too much time inside
apfs_lookup(). I had never really checked if the dentry cache was
working, so naturally that turned out to be the problem: I had always
assumed that the strings inside qstr structures were null-terminated,
but they may actually be a single component in a pathname, terminated by
a forward slash. The result was that we always searched the cache for
full pathnames, which were naturally never found.

To fix this, always pass the filename length from qstr to the unicode
handlers, and make them work without assuming a null-termination.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2021-11-09 18:01:16 -03:00
Ernesto A. Fernández 695f04aa3d Support writes to the middle of files
Currently, the module can only append data to files; add support for
writes to other offsets.

Copy-on-write makes this all a bit tricky, and I'm not convinced of the
quality of my code, but I can go back to it and improve it once I have
xfstests running.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2021-07-09 20:16:02 -03:00
Stan Skowronek b0f0579c80 Avoid npd on dentry hash collisions
Check that none of the names being compared by apfs_keycmp() is NULL
before passing them to strcmp(), to avoid a null pointer dereference.
This was originally never supposed to happen, because keys that reach
this point in the comparison are of the same type; but it does happen
for dentry record insertions because of the hacky way we handle hash
collisions. We still need to properly support that.

[ernesto: added commit message]

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2021-04-17 05:35:53 -03:00
Ernesto A. Fernández b1763ccc87 Avoid fallthrough on apfs_read_cat_key()
The compiler is warning of a fallthrough in apfs_read_cat_key(). By pure
chance, this has no real consequences, but fix it.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2021-04-06 23:24:33 -03:00
Ernesto A. Fernández 45f56acb46 Set up a standalone repository for the APFS module
Start a new out-of-tree repository, like linux-apfs-oot but with write
support.

To get the module to build independently, rewrite the Makefile and
add a definition for the APFS_SUPER_MAGIC macro.  Since the intention is
to support a range of kernel versions, use preprocessor checks to handle
kernels without statx, without iversion, and without SB_RDONLY.

Provide a README file based on the original documentation, but with
additional build and mount instructions.  Add a LICENSE file as well.

Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
2021-03-31 17:16:24 -03:00