lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 22 Jun 2021 14:11:33 +0200
From:   "Enrico Weigelt, metux IT consult" <info@...ux.net>
To:     linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
        viro@...iv.linux.org.uk
Subject: [RFC PATCH 3/6] fs: hpfs: move fstrim to file_operation

Use the newly introduced file_operation callback for FITRIM ioctl.
This removes some common code, eg. permission check, buffer copying,
which is now done by generic vfs code.
---
 fs/hpfs/dir.c     |  1 +
 fs/hpfs/file.c    |  1 +
 fs/hpfs/hpfs_fn.h |  1 +
 fs/hpfs/super.c   | 36 +++++++++++++++---------------------
 4 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/fs/hpfs/dir.c b/fs/hpfs/dir.c
index f32f15669996..92084f4ce6a7 100644
--- a/fs/hpfs/dir.c
+++ b/fs/hpfs/dir.c
@@ -326,4 +326,5 @@ const struct file_operations hpfs_dir_ops =
 	.fsync		= hpfs_file_fsync,
 	.unlocked_ioctl	= hpfs_ioctl,
 	.compat_ioctl	= compat_ptr_ioctl,
+	.fitrim		= hpfs_fitrim,
 };
diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c
index 077c25128eb7..66112702cd4c 100644
--- a/fs/hpfs/file.c
+++ b/fs/hpfs/file.c
@@ -216,6 +216,7 @@ const struct file_operations hpfs_file_ops =
 	.splice_read	= generic_file_splice_read,
 	.unlocked_ioctl	= hpfs_ioctl,
 	.compat_ioctl	= compat_ptr_ioctl,
+	.fitrim		= hpfs_fitrim,
 };
 
 const struct inode_operations hpfs_file_iops =
diff --git a/fs/hpfs/hpfs_fn.h b/fs/hpfs/hpfs_fn.h
index 167ec6884642..05c558084033 100644
--- a/fs/hpfs/hpfs_fn.h
+++ b/fs/hpfs/hpfs_fn.h
@@ -329,6 +329,7 @@ void hpfs_error(struct super_block *, const char *, ...);
 int hpfs_stop_cycles(struct super_block *, int, int *, int *, char *);
 unsigned hpfs_get_free_dnodes(struct super_block *);
 long hpfs_ioctl(struct file *file, unsigned cmd, unsigned long arg);
+long hpfs_fitrim(struct file *file, struct fstrim_range *range);
 
 /*
  * local time (HPFS) to GMT (Unix)
diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c
index a7dbfc892022..8c45cb749ba4 100644
--- a/fs/hpfs/super.c
+++ b/fs/hpfs/super.c
@@ -200,30 +200,24 @@ static int hpfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	return 0;
 }
 
+long hpfs_fitrim(struct file *file, struct fstrim_range *range)
+{
+	secno n_trimmed;
+
+	int r = hpfs_trim_fs(file_inode(file)->i_sb, range->start >> 9,
+			     (range->start + range->len) >> 9,
+			     (range->minlen + 511) >> 9, &n_trimmed);
+
+	if (r)
+		return r;
+
+	range->len = (u64)n_trimmed << 9;
+	return 0;
+}
 
 long hpfs_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 {
-	switch (cmd) {
-		case FITRIM: {
-			struct fstrim_range range;
-			secno n_trimmed;
-			int r;
-			if (!capable(CAP_SYS_ADMIN))
-				return -EPERM;
-			if (copy_from_user(&range, (struct fstrim_range __user *)arg, sizeof(range)))
-				return -EFAULT;
-			r = hpfs_trim_fs(file_inode(file)->i_sb, range.start >> 9, (range.start + range.len) >> 9, (range.minlen + 511) >> 9, &n_trimmed);
-			if (r)
-				return r;
-			range.len = (u64)n_trimmed << 9;
-			if (copy_to_user((struct fstrim_range __user *)arg, &range, sizeof(range)))
-				return -EFAULT;
-			return 0;
-		}
-		default: {
-			return -ENOIOCTLCMD;
-		}
-	}
+	return -ENOIOCTLCMD;
 }
 
 
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ