Commit Graph

59 Commits

Author SHA1 Message Date
Paul Lawrence
d434336cff ANDROID: Incremental fs: Add FS_IOC_READ_VERITY_METADATA
Bug: 180942327
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I6d6532496c072145f22bcf9ff4499ec3f52e94b5
2021-04-13 15:22:56 +00:00
Paul Lawrence
f75e40b0c7 ANDROID: Incremental fs: Truncate file when complete
Bug: 182185202
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I96a192011f19efa1c597275dafc6c216f8ed0b56
2021-03-24 16:10:08 +00:00
Paul Lawrence
dc07a7efb6 ANDROID: Incremental fs: Fix mlock to fail gracefully on corrupt files
Test: incfs_test passes
Bug: 174875107
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I93ce3600e88ddd89cf69f032ea858d169b0a7bec
2021-03-24 16:09:51 +00:00
Paul Lawrence
bc5c0903a7 ANDROID: Incremental fs: Support STATX_ATTR_VERITY
Bug: 181242243
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Id996e0d5d95c8b42254d1e1e0c1dad9317183a17
2021-03-11 08:42:18 -08:00
Greg Kroah-Hartman
2fec063693 ANDROID: Incremental fs: fix up for recent vfs changes
Lots of different vfs changes happened in 7d6beb71da ("Merge tag
'idmapped-mounts-v5.12' of
git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux") which were
not made to incfs as it is out-of-tree :(

So fix it up by doing a quick port to the initial user namespace and
hopefully all works properly now, at least it builds :)

Fixes: 7d6beb71da ("Merge tag 'idmapped-mounts-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux")
Cc: Paul Lawrence <paullawrence@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I32899a792fbfad9455d504868e7a02d30a0a6049
2021-03-06 19:50:59 +01:00
Greg Kroah-Hartman
c4299f9857 Revert "FROMLIST: Add flags option to get xattr method paired to __vfs_getxattr"
This reverts commit 3484eba91d.

It's causing too many merge issues, so revert it for now and hopefully
bring it back later...

Cc: Mark Salyzyn <salyzyn@android.com>
Bug: 133515582
Bug: 136124883
Bug: 129319403
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Id70a37d9471eff58f0027a1371538858136604d3
2021-03-06 12:51:05 +01:00
Paul Lawrence
822f25ac84 ANDROID: Incremental fs: Add FS_IOC_MEASURE_VERITY
Add ioctl to return the verity file digest, compatible with the identical
ioctl in fs/verity/.

Bug: 160634504
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I1bc2dc975b9be122e1c831a25a1d44f27a360f3c
2021-02-10 14:41:17 -08:00
Paul Lawrence
ab6055cb62 ANDROID: Incremental fs: Store fs-verity state in backing file
Now fsverity state is preserved across inode eviction.

Added incfs.verity xattr to track when a file is fs-verity enabled.

Bug: 160634504
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I41d90abd55527884d9eff642c9834ad837ff6918
2021-02-10 14:41:14 -08:00
Paul Lawrence
ab19218f50 ANDROID: Incremental fs: Add FS_IOC_GETFLAGS
Add FS_IOC_GETFLAGS ioctl to incfs. Currently this will only get the
S_VERITY flag.

Bug: 160634504
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Id79add0db0d66f604ca0f222fe5faec91450ade5
2021-02-10 14:19:46 -08:00
Paul Lawrence
ca9597811d ANDROID: Incremental fs: Add FS_IOC_ENABLE_VERITY
Add FS_IOC_ENABLE_VERITY ioctl

When called, calculate measurement, validate signature against fsverity,
and set S_VERITY flag.

This does not (yet) preserve the verity status once the inode is
evicted.

Bug: 160634504
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I88af2721f650098accc72a64528c7d85b753c7f6
2021-02-10 14:19:46 -08:00
Paul Lawrence
d52341bb66 ANDROID: Incremental fs: inotify on create mapped file
Bug: 175323815
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I670e8a7f4a68012d68718a431be3450646a614c0
2021-02-01 09:51:06 -08:00
Paul Lawrence
fe9f1726b2 ANDROID: Incremental fs: inotify support
Bug: 175323815
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ife372fa2f10dd51f61def9feb461e965d276c6bf
2021-01-27 16:31:47 +00:00
Paul Lawrence
1f3a58dbb3 ANDROID: Incremental fs: Free mount info after files are flushed
Bug: 177280103
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I24b0d4bf5353834900f868f65e7510529867b615
2021-01-12 22:18:24 +00:00
Paul Lawrence
a31de8b2a5 ANDROID: Incremental fs: Fix selinux issues
Bug: 177075428
Test: incfs_test passes
      atest GtsIncrementalInstallTestCases has only 8 failures
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I73accfc1982aec1cd7947996c25a23e4a97cfdac
2021-01-12 22:18:17 +00:00
Yurii Zubrytskyi
d749bc24dc ANDROID: Incremental fs: fix .blocks_written
.blocks_writen file handling was missing some operations:
SELinux xattr handlers, safety checks for it being a
pseudo file etc.

This CL generalizes pseudo file handling so that all such
files work in a generic way and next time it should be
easier to add all operations at once.

Bug: 175823975
Test: incfs_tests pass
Change-Id: Id2b1936018c81c62c8ab4cdbaa8827e2679b513f
Signed-off-by: Yurii Zubrytskyi <zyy@google.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2021-01-06 16:57:22 +00:00
Paul Lawrence
5ef8ab7172 ANDROID: Incremental fs: Change per UID timeouts to microseconds
Bug: 174495152
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Id76d2fec83a0eb7b70ad85f1fac81bf319563a66
2020-12-10 20:16:01 +00:00
Paul Lawrence
b1cc5f1b63 ANDROID: Incremental fs: Small improvements
Rmove bc_mutex used to protect metadata chain, now that is only
read at file open time
Remove certain unused mount options

Bug: 172482559
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Id70e5a5d08e5de79f391e19ea97e356f39a3ed51
2020-11-05 15:26:48 +00:00
Paul Lawrence
65a0f002c0 ANDROID: Incremental fs: Initialize mount options correctly
report_uid was not being initialized, leading to random behavior

Bug: 172480517
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ib121136d6f570f99e9060bdde9aa43ff2995514e
2020-11-05 15:26:31 +00:00
Paul Lawrence
142953a07f ANDROID: Incremental fs: Add per UID read timeouts
Bug: 169056129
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I8cad9ee4095123bafba33abb65bbb339ba6ff8b5
2020-09-28 09:13:12 -07:00
Paul Lawrence
7e7bfa94e5 ANDROID: Incremental fs: Add .incomplete folder
Bug: 165929150
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ib6952391aea76bf0318cbad8da7a1276f8f9e8ba
2020-09-21 14:48:29 +00:00
Eric Biggers
79581f9ee7 ANDROID: Incremental fs: Fix uninitialized variable
'error' isn't initialized before being returned.

Fixes: d4d1163e53 ("ANDROID: Incremental fs: Add INCFS_IOC_GET_BLOCK_COUNT")
Change-Id: I3082ac4a3f9d8632080a8e8c9221fda25ef152a0
Signed-off-by: Eric Biggers <ebiggers@google.com>
2020-09-17 19:47:36 -07:00
Paul Lawrence
9cbdd375f6 ANDROID: Incremental fs: Fix filled block count from get filled blocks
Bug: 165929150
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I8845adcafcc3a3f01730e8b5534fb25ea3d551db
2020-09-17 21:19:18 +00:00
Paul Lawrence
c0391ecb55 ANDROID: Incremental fs: Add hash block counts to IOC_IOCTL_GET_BLOCK_COUNT
Bug: 166638631
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I0061a855ec563de8df40ba0b35292e99be33c6c0
2020-09-16 15:44:06 -07:00
Paul Lawrence
d4d1163e53 ANDROID: Incremental fs: Add INCFS_IOC_GET_BLOCK_COUNT
Bug: 166638631
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ia7a8cab87688fc401f0719df84fe79ea75887692
2020-09-16 18:05:34 +00:00
Paul Lawrence
8334d69e65 ANDROID: Incremental fs: Separate pseudo-file code
Also fixed two bugs in the process:

is_pseudo_filename was not previously checking for .log, so an attempt
to create a .log would succeed.

All ioctls could be called on all files. ioctls now set on the correct
files.

Bug: 162856396
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I3f1e87d018836f51a97897880dd70181db4f7169
2020-08-26 18:59:29 +00:00
Paul Lawrence
7ab6cf0fec ANDROID: Incremental fs: Add UID to pending_read
Test: incfs_test passes
Bug: 160634477
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Iaf817cf1f7ccd0109b2114b425ea7f26718345ab
2020-08-19 17:13:16 +00:00
Paul Lawrence
3f4938108a ANDROID: Incremental fs: Create mapped file
Bug: 160634482
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ic2ac8dfccd60f6c9c72c38bf323997fce7546c1c
2020-08-18 12:37:59 -07:00
mtk81325
7c02f94255 ANDROID: Incremental fs: fix magic compatibility again
It's still magic number issue which cannot be compatible with
arm-32 platform, although we try to fix it in Iae4f3877444
("ANDROID: Incremental fs: magic number compatible 32-bit"),
there is still incompatible scenario, such as: get_incfs_node(),
it will return NULL then kernel exception will be trigger because
of NULL pointer access. (inode_set() -> get_incfs_node(), then used
node->xxx directly)

We change magic number directly, otherwise, we must fix above issues one by one.

Bug: 159772865
Fixes: Iae4f3877444("ANDROID: Incremental fs: magic number compatible 32-bit")
Signed-off-by: Peng Zhou <Peng.Zhou@mediatek.com>
Signed-off-by: mtk81325 <peng.zhou@mediatek.com>
Change-Id: I71f279c1bb55ea296ab33a47644f30df4a9f60a6
2020-08-18 17:12:58 +00:00
Akilesh Kailash
22b27c439f ANDROID: Incremental fs: Don't allow renaming .index directory.
Add additional check to verify dentry is hashed after vfs_mkdir()
is successful.

Bug: 148423333
Test: kernel seftest - incfs_test, manual test removing .index when
mounted

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: I7d2d71d480db4f02b7f3a347b5734c6643843594
2020-08-13 02:46:00 +00:00
Paul Lawrence
b59b963a7d ANDROID: Incremental fs: Fix incfs to work on virtio-9p
Test: incfs_test on a virtio 9p drive. Note test 6 fails still,
but I think this is a result of caching directory entries over a
network file system.
Bug: 161802292
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I6986fb3e9b403181cf81024046f394960caf4620
2020-08-04 17:06:31 +00:00
Akilesh Kailash
f39f1b550a ANDROID: Incremental fs: Use R/W locks to read/write segment blockmap.
Use Read-Write locks for reading/writing segment in blockmap.
This should allow parallel reads when there are
multiple reads within same segment.

A small optimization in pending_reads_read(). Since
incfs_collect_pending_reads() already iterate to
populate buffer, new_max_sn - highest serial number
among all the pending read buffer can be done in the same
loop instead of looping again in pending_reads_read().

Bug: 161566104
Test: kernel selftest - incfs_test and incfs_perf

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Id00376b0e4cb8c0c0bc8264cdddd6f38c4aa85f0
2020-07-28 05:11:50 +00:00
Akilesh Kailash
b0fa24d335 ANDROID: Incremental fs: dentry_revalidate should not return -EBADF.
Fix of bug 161565969 added EBADF when backing path doesn't
exist. However, .log and .pending reads doesn't have
backing path causing incfs_test to fail.

Bug: 162243475
Test: incfs_test on QEMU passes

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Iba303bbc42b431fe4a4fbacb40584faaff4b14b7
2020-07-27 18:47:26 +00:00
Akilesh Kailash
000d95ac2d ANDROID: Incremental fs: Fix minor bugs
1: Invoke kunmap(page) in error path
2: Validate NULL checks at few places in the code.
3: path_put() should not be invoked if path entry is null.
   Although path_put() checks for NULL condition internally,
   caller should gracefully handle it.

Bug: 161565969
Test: kernel selftest - incfs_test, incfs_perf

Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Ie4dfaaba4b09f4798d492f8a25dd9dcc8da89e51
2020-07-24 19:13:44 +00:00
mtk81325
839511af20 ANDROID: Incremental fs: magic number compatible 32-bit
Incfs's magic is bigger than 32-bit, but super block structure's
s_magic is unsigned long which is 32-bit in ARM 32-bit platform.

Do the cast for magic!

Bug: 159772865
Signed-off-by: Peng Zhou <Peng.Zhou@mediatek.com>
Signed-off-by: mtk81325 <peng.zhou@mediatek.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Iae4f38774440c7d6ae44529d4f0f8ebb2ec5dacc
2020-07-24 16:54:44 +00:00
Greg Kroah-Hartman
3be0477f5a ANDROID: Incremental fs: fix up attempt to copy structures with READ/WRITE_ONCE
READ/WRITE_ONCE are for atomic data types, not for structures.  Fix this
up by doing a memcpy to make it explicit just how messy this copy is...

This fixes a build error on 5.8-rc1, as things are more strict, odds are
it's also wrong in other kernel versions as well...

Cc: Daniel Mentz <danielmentz@google.com>
Cc: Paul Lawrence <paullawrence@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I7ecd3d05bd94c936dd5e69c63028458786f37a78
2020-06-25 15:20:35 +00:00
Paul Lawrence
21e6d932da ANDROID: Incremental fs: Cache successful hash calculations
Bug: 155996534
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ic508e6fa07c90decb29e07647dd3b0fc4d243ce8
2020-06-04 21:17:47 +00:00
Paul Lawrence
f6691cbdb6 ANDROID: Incremental fs: Fix scheduling while atomic error
If an incfs file is created, then the file system is sync'd,on opening
the incfs file inode_set reads the size from the backing file from
within iget5_locked, causing this error.

Test: incfs_test passes, this no longer occurs
Bug: 156413528
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I8939c4afa514d39d251c044d7680cfc69272669e
2020-05-13 13:28:59 +00:00
Paul Lawrence
3e4fa206ce ANDROID: Incremental fs: Fix issues with very large files
Test: incfs_test passes
Bug: 155590527
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Iaecfcd40e8c089d11b34c7aff2090fbfe0c36219
2020-05-04 23:37:33 +00:00
Paul Lawrence
fe4fae35fe ANDROID: Incremental fs: Add setattr call
As was, chmod would change the cached inode's mode, which would
persist until the inode was uncached.

Fix to change mode of backing file, but make sure mount files
are read only, backing files are always writeable.

Test: App no longer fails with incfs errors
Bug: 154972299
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I40517331f24329484387c6b880f1517f887b29f6
2020-04-30 15:14:27 +00:00
Paul Lawrence
b6b4a3a404 ANDROID: Incremental fs: Use simple compression in log buffer
Bug: 154342202
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ibcc641dd92596018c9f10b5bc7bd0db2642a80c7
2020-04-24 12:28:45 -07:00
Paul Lawrence
b4c6269563 ANDROID: Incremental fs: Fix compound page usercopy crash
Bug: 153560805
Test: incfs_test passes on qemu and Pixel 4
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I1b55341e4e4247a74f3f539b9d190fef0ca409b8
2020-04-09 18:52:01 +00:00
Yurii Zubrytskyi
35deb33fa2 ANDROID: Incremental fs: make remount log buffer change atomic
Read log buffer can have multiple threads doing any of these
operations simultaneously:
- Polling for changes
- Reading log records
- Adding new log records
- Updating log buffer size, or enabling/disabling it completely

As we don't control the userspace, and it turns out that they
all currently originate from different processes, code needs to
be safe against parallel access to a read buffer and a request
for reallocating it.

This CL add an r/w spinlock to protect the buffer and its size.
Each remount takes the write lock, while everything else takes
a read lock. Remount makes sure it doesn't take too long by
preallocating and precalculating all updates, while other
operations don't care much about their critical section size -
they all can still run together.

Bug: 152633648
Test: manual remount + reading
Signed-off-by: Yurii Zubrytskyi <zyy@google.com>
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I7271b4cb89f1ae2cbee6e5b073758f344c4ba66a
2020-04-08 16:53:20 +00:00
Paul Lawrence
764dba028d ANDROID: Incremental fs: Fix mislabeled __user ptrs
Found by sparse

Bug: 153174547
Test: make C=2 fs/incfs/incrementalfs.ko no errors, incfs_test pass
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I9ff4f4f35975fe09936724488b96cd8bdeeb719e
2020-04-08 13:36:10 +00:00
Paul Lawrence
2fb9b719ce ANDROID: Incremental fs: Fix remount
Bug: 153017385
Test: incfs_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I13f3a3c91d746d725e0e21b1e2bcfe0a64a13716
2020-04-01 23:32:34 +00:00
Paul Lawrence
ca72c79936 ANDROID: Incremental fs: Protect get_fill_block, and add a field
Since INCFS_IOC_GET_FILLED_BLOCKS potentially leaks information about usage
patterns, and is only useful to someone filling the file, best protect it in
the same way as INCFS_IOC_FILL_BLOCKS.

Add useful field data_block_out as well

Test: incfs_test passes
Bug: 152983639
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I126a8cf711e56592479093e9aadbfd0e7f700752
2020-04-01 23:32:27 +00:00
Paul Lawrence
c062bc8e76 ANDROID: Incremental fs: Fix four resource bugs
Without these, you can't unmount a volume on which incfs was
mounted and the tests run.

Also incfs_tests would fail sporadically without the fix to
test_inode

Test: Run incfs_test and unmount underlying volume 1000 times
Bug: 152636070
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I88f11f5d4269c22d9073e5eb671d0c7cc4629f6c
2020-03-30 06:20:08 +00:00
Paul Lawrence
8d963bb240 ANDROID: Incremental fs: Add INCFS_IOC_GET_FILLED_BLOCKS
Test: incfs_test passes
Bug: 151240628
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: I66d0ba1911adc5d68ed404585222e6a81a7eb94f
2020-03-26 21:02:02 +00:00
Paul Lawrence
e94931cb2c ANDROID: Incremental fs: Add INCFS_IOC_PERMIT_FILL
Provide a securable way to open a file for filling

Test: incfs_test passes
Bug: 138149732
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ib4b6fd839ad30ce08e31121d19e2c0d7066d302f
2020-03-18 16:22:25 +00:00
Paul Lawrence
bc6a70e849 ANDROID: Incremental fs: Remove signature checks from kernel
Test: selftests pass
Bug: 133435829
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ia7e69b1b0176202da4b418ea815b370cbdacd5c2
2020-03-18 16:22:17 +00:00
Paul Lawrence
21b07a7140 ANDROID: Incremental fs: Make fill block an ioctl
Filling blocks is not equivalent to writing a file, since they are
constrained by the root hash. selinux policy may wish to treat them
differently, for instance.

Test: incfs_test passes
Bug: 138149732
Signed-off-by: Paul Lawrence <paullawrence@google.com>
Change-Id: Ic369b84b92547b1cfefe422bd881c4e466090aed
2020-03-18 16:21:50 +00:00