diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-09-18 19:59:14 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-09-18 19:59:14 -0400 |
commit | f60c55a94e1d127186566f06294f2dadd966e9b4 (patch) | |
tree | 2d3dbd572c0096d24f87f581194563ff76e07a6e /fs/f2fs/file.c | |
parent | 734d1ed83e1f9b7bafb650033fb87c657858cf5b (diff) | |
parent | 95ae251fe82838b85c6d37e5a1775006e2a42ae0 (diff) |
Merge tag 'fsverity-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/fscrypt
Pull fs-verity support from Eric Biggers:
"fs-verity is a filesystem feature that provides Merkle tree based
hashing (similar to dm-verity) for individual readonly files, mainly
for the purpose of efficient authenticity verification.
This pull request includes:
(a) The fs/verity/ support layer and documentation.
(b) fs-verity support for ext4 and f2fs.
Compared to the original fs-verity patchset from last year, the UAPI
to enable fs-verity on a file has been greatly simplified. Lots of
other things were cleaned up too.
fs-verity is planned to be used by two different projects on Android;
most of the userspace code is in place already. Another userspace tool
("fsverity-utils"), and xfstests, are also available. e2fsprogs and
f2fs-tools already have fs-verity support. Other people have shown
interest in using fs-verity too.
I've tested this on ext4 and f2fs with xfstests, both the existing
tests and the new fs-verity tests. This has also been in linux-next
since July 30 with no reported issues except a couple minor ones I
found myself and folded in fixes for.
Ted and I will be co-maintaining fs-verity"
* tag 'fsverity-for-linus' of git://git.kernel.org/pub/scm/fs/fscrypt/fscrypt:
f2fs: add fs-verity support
ext4: update on-disk format documentation for fs-verity
ext4: add fs-verity read support
ext4: add basic fs-verity support
fs-verity: support builtin file signatures
fs-verity: add SHA-512 support
fs-verity: implement FS_IOC_MEASURE_VERITY ioctl
fs-verity: implement FS_IOC_ENABLE_VERITY ioctl
fs-verity: add data verification hooks for ->readpages()
fs-verity: add the hook for file ->setattr()
fs-verity: add the hook for file ->open()
fs-verity: add inode and superblock fields
fs-verity: add Kconfig and the helper functions for hashing
fs: uapi: define verity bit for FS_IOC_GETFLAGS
fs-verity: add UAPI header
fs-verity: add MAINTAINERS file entry
fs-verity: add a documentation file
Diffstat (limited to 'fs/f2fs/file.c')
-rw-r--r-- | fs/f2fs/file.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 6a7349f9ac15..39fffc19e00c 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c | |||
@@ -496,6 +496,10 @@ static int f2fs_file_open(struct inode *inode, struct file *filp) | |||
496 | if (err) | 496 | if (err) |
497 | return err; | 497 | return err; |
498 | 498 | ||
499 | err = fsverity_file_open(inode, filp); | ||
500 | if (err) | ||
501 | return err; | ||
502 | |||
499 | filp->f_mode |= FMODE_NOWAIT; | 503 | filp->f_mode |= FMODE_NOWAIT; |
500 | 504 | ||
501 | return dquot_file_open(inode, filp); | 505 | return dquot_file_open(inode, filp); |
@@ -778,6 +782,10 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) | |||
778 | if (err) | 782 | if (err) |
779 | return err; | 783 | return err; |
780 | 784 | ||
785 | err = fsverity_prepare_setattr(dentry, attr); | ||
786 | if (err) | ||
787 | return err; | ||
788 | |||
781 | if (is_quota_modification(inode, attr)) { | 789 | if (is_quota_modification(inode, attr)) { |
782 | err = dquot_initialize(inode); | 790 | err = dquot_initialize(inode); |
783 | if (err) | 791 | if (err) |
@@ -1705,7 +1713,8 @@ static const struct { | |||
1705 | FS_PROJINHERIT_FL | \ | 1713 | FS_PROJINHERIT_FL | \ |
1706 | FS_ENCRYPT_FL | \ | 1714 | FS_ENCRYPT_FL | \ |
1707 | FS_INLINE_DATA_FL | \ | 1715 | FS_INLINE_DATA_FL | \ |
1708 | FS_NOCOW_FL) | 1716 | FS_NOCOW_FL | \ |
1717 | FS_VERITY_FL) | ||
1709 | 1718 | ||
1710 | #define F2FS_SETTABLE_FS_FL ( \ | 1719 | #define F2FS_SETTABLE_FS_FL ( \ |
1711 | FS_SYNC_FL | \ | 1720 | FS_SYNC_FL | \ |
@@ -1750,6 +1759,8 @@ static int f2fs_ioc_getflags(struct file *filp, unsigned long arg) | |||
1750 | 1759 | ||
1751 | if (IS_ENCRYPTED(inode)) | 1760 | if (IS_ENCRYPTED(inode)) |
1752 | fsflags |= FS_ENCRYPT_FL; | 1761 | fsflags |= FS_ENCRYPT_FL; |
1762 | if (IS_VERITY(inode)) | ||
1763 | fsflags |= FS_VERITY_FL; | ||
1753 | if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode)) | 1764 | if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode)) |
1754 | fsflags |= FS_INLINE_DATA_FL; | 1765 | fsflags |= FS_INLINE_DATA_FL; |
1755 | if (is_inode_flag_set(inode, FI_PIN_FILE)) | 1766 | if (is_inode_flag_set(inode, FI_PIN_FILE)) |
@@ -3103,6 +3114,30 @@ static int f2fs_ioc_resize_fs(struct file *filp, unsigned long arg) | |||
3103 | return ret; | 3114 | return ret; |
3104 | } | 3115 | } |
3105 | 3116 | ||
3117 | static int f2fs_ioc_enable_verity(struct file *filp, unsigned long arg) | ||
3118 | { | ||
3119 | struct inode *inode = file_inode(filp); | ||
3120 | |||
3121 | f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); | ||
3122 | |||
3123 | if (!f2fs_sb_has_verity(F2FS_I_SB(inode))) { | ||
3124 | f2fs_warn(F2FS_I_SB(inode), | ||
3125 | "Can't enable fs-verity on inode %lu: the verity feature is not enabled on this filesystem.\n", | ||
3126 | inode->i_ino); | ||
3127 | return -EOPNOTSUPP; | ||
3128 | } | ||
3129 | |||
3130 | return fsverity_ioctl_enable(filp, (const void __user *)arg); | ||
3131 | } | ||
3132 | |||
3133 | static int f2fs_ioc_measure_verity(struct file *filp, unsigned long arg) | ||
3134 | { | ||
3135 | if (!f2fs_sb_has_verity(F2FS_I_SB(file_inode(filp)))) | ||
3136 | return -EOPNOTSUPP; | ||
3137 | |||
3138 | return fsverity_ioctl_measure(filp, (void __user *)arg); | ||
3139 | } | ||
3140 | |||
3106 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | 3141 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
3107 | { | 3142 | { |
3108 | if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) | 3143 | if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) |
@@ -3171,6 +3206,10 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
3171 | return f2fs_ioc_precache_extents(filp, arg); | 3206 | return f2fs_ioc_precache_extents(filp, arg); |
3172 | case F2FS_IOC_RESIZE_FS: | 3207 | case F2FS_IOC_RESIZE_FS: |
3173 | return f2fs_ioc_resize_fs(filp, arg); | 3208 | return f2fs_ioc_resize_fs(filp, arg); |
3209 | case FS_IOC_ENABLE_VERITY: | ||
3210 | return f2fs_ioc_enable_verity(filp, arg); | ||
3211 | case FS_IOC_MEASURE_VERITY: | ||
3212 | return f2fs_ioc_measure_verity(filp, arg); | ||
3174 | default: | 3213 | default: |
3175 | return -ENOTTY; | 3214 | return -ENOTTY; |
3176 | } | 3215 | } |
@@ -3290,6 +3329,8 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
3290 | case F2FS_IOC_SET_PIN_FILE: | 3329 | case F2FS_IOC_SET_PIN_FILE: |
3291 | case F2FS_IOC_PRECACHE_EXTENTS: | 3330 | case F2FS_IOC_PRECACHE_EXTENTS: |
3292 | case F2FS_IOC_RESIZE_FS: | 3331 | case F2FS_IOC_RESIZE_FS: |
3332 | case FS_IOC_ENABLE_VERITY: | ||
3333 | case FS_IOC_MEASURE_VERITY: | ||
3293 | break; | 3334 | break; |
3294 | default: | 3335 | default: |
3295 | return -ENOIOCTLCMD; | 3336 | return -ENOIOCTLCMD; |