Subject: linux-next: manual merge of the fsverity tree with the f2fs tree

From: Stephen Rothwell <[email-masked]>
Date: Mon, 19 Aug 2019 10:41:41 +1000

Hi all,

Today's linux-next merge of the fsverity tree got a conflict in:

  fs/f2fs/file.c

between commits:

  d9a94abb3380 ("f2fs: support FS_IOC_{GET,SET}FSLABEL")
  546155f73637 ("f2fs: Support case-insensitive file name lookups")

from the f2fs tree and commit:

  95ae251fe828 ("f2fs: add fs-verity support")

from the fsverity tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc fs/f2fs/file.c
index 32e2cf9d4b07,838bfeecbd86..000000000000
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@@ -1721,7 -1721,7 +1729,8 @@@ static const struct 
  		FS_ENCRYPT_FL |		\
  		FS_INLINE_DATA_FL |	\
  		FS_NOCOW_FL |		\
- 		FS_CASEFOLD_FL)
++		FS_CASEFOLD_FL |	\
+ 		FS_VERITY_FL)
  
  #define F2FS_SETTABLE_FS_FL (		\
  		FS_SYNC_FL |		\
@@@ -3125,77 -3088,34 +3136,101 @@@ static int f2fs_ioc_resize_fs(struct fi
  	return ret;
  }
  
 +static int f2fs_get_volume_name(struct file *filp, unsigned long arg)
 +{
 +	struct inode *inode = file_inode(filp);
 +	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 +	char *vbuf;
 +	int count;
 +	int err = 0;
 +
 +	vbuf = f2fs_kzalloc(sbi, MAX_VOLUME_NAME, GFP_KERNEL);
 +	if (!vbuf)
 +		return -ENOMEM;
 +
 +	down_read(&sbi->sb_lock);
 +	count = utf16s_to_utf8s(sbi->raw_super->volume_name,
 +			ARRAY_SIZE(sbi->raw_super->volume_name),
 +			UTF16_LITTLE_ENDIAN, vbuf, MAX_VOLUME_NAME);
 +	up_read(&sbi->sb_lock);
 +
 +	if (copy_to_user((char __user *)arg, vbuf,
 +				min(FSLABEL_MAX, count)))
 +		err = -EFAULT;
 +
 +	kvfree(vbuf);
 +	return err;
 +}
 +
 +static int f2fs_set_volume_name(struct file *filp, unsigned long arg)
 +{
 +	struct inode *inode = file_inode(filp);
 +	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 +	char *vbuf;
 +	int err = 0;
 +
 +	if (!capable(CAP_SYS_ADMIN))
 +		return -EPERM;
 +
 +	vbuf = strndup_user((const char __user *)arg, FSLABEL_MAX);
 +	if (IS_ERR(vbuf))
 +		return PTR_ERR(vbuf);
 +
 +	err = mnt_want_write_file(filp);
 +	if (err)
 +		goto out;
 +
 +	down_write(&sbi->sb_lock);
 +
 +	memset(sbi->raw_super->volume_name, 0,
 +			sizeof(sbi->raw_super->volume_name));
 +	utf8s_to_utf16s(vbuf, strlen(vbuf), UTF16_LITTLE_ENDIAN,
 +			sbi->raw_super->volume_name,
 +			ARRAY_SIZE(sbi->raw_super->volume_name));
 +
 +	err = f2fs_commit_super(sbi, false);
 +
 +	up_write(&sbi->sb_lock);
 +
 +	mnt_drop_write_file(filp);
 +out:
 +	kfree(vbuf);
 +	return err;
 +}
 +
+ static int f2fs_ioc_enable_verity(struct file *filp, unsigned long arg)
+ {
+ 	struct inode *inode = file_inode(filp);
+ 
+ 	f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
+ 
+ 	if (!f2fs_sb_has_verity(F2FS_I_SB(inode))) {
+ 		f2fs_warn(F2FS_I_SB(inode),
+ 			  "Can't enable fs-verity on inode %lu: the verity feature is not enabled on this filesystem.\n",
+ 			  inode->i_ino);
+ 		return -EOPNOTSUPP;
+ 	}
+ 
+ 	return fsverity_ioctl_enable(filp, (const void __user *)arg);
+ }
+ 
+ static int f2fs_ioc_measure_verity(struct file *filp, unsigned long arg)
+ {
+ 	if (!f2fs_sb_has_verity(F2FS_I_SB(file_inode(filp))))
+ 		return -EOPNOTSUPP;
+ 
+ 	return fsverity_ioctl_measure(filp, (void __user *)arg);
+ }
+ 
  long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  {
 +	int ret;
 +
  	if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
  		return -EIO;
 +	ret = f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp)));
 +	if (ret)
 +		return ret;
  
  	switch (cmd) {
  	case F2FS_IOC_GETFLAGS:
@@@ -3260,10 -3170,10 +3295,14 @@@
  		return f2fs_ioc_precache_extents(filp, arg);
  	case F2FS_IOC_RESIZE_FS:
  		return f2fs_ioc_resize_fs(filp, arg);
 +	case F2FS_IOC_GET_VOLUME_NAME:
 +		return f2fs_get_volume_name(filp, arg);
 +	case F2FS_IOC_SET_VOLUME_NAME:
 +		return f2fs_set_volume_name(filp, arg);
+ 	case FS_IOC_ENABLE_VERITY:
+ 		return f2fs_ioc_enable_verity(filp, arg);
+ 	case FS_IOC_MEASURE_VERITY:
+ 		return f2fs_ioc_measure_verity(filp, arg);
  	default:
  		return -ENOTTY;
  	}
@@@ -3378,8 -3288,8 +3417,10 @@@ long f2fs_compat_ioctl(struct file *fil
  	case F2FS_IOC_SET_PIN_FILE:
  	case F2FS_IOC_PRECACHE_EXTENTS:
  	case F2FS_IOC_RESIZE_FS:
 +	case F2FS_IOC_GET_VOLUME_NAME:
 +	case F2FS_IOC_SET_VOLUME_NAME:
+ 	case FS_IOC_ENABLE_VERITY:
+ 	case FS_IOC_MEASURE_VERITY:
  		break;
  	default:
  		return -ENOIOCTLCMD;