linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Arnd Bergmann <arnd@arndb.de>,
	Amir Goldstein <amir73il@gmail.com>,
	"Darrick J. Wong" <darrick.wong@oracle.com>,
	Dave Chinner <david@fromorbit.com>
Subject: [PATCH v5 05/29] compat: move FS_IOC_RESVSP_32 handling to fs/ioctl.c
Date: Tue, 30 Jul 2019 21:25:16 +0200	[thread overview]
Message-ID: <20190730192552.4014288-6-arnd@arndb.de> (raw)
In-Reply-To: <20190730192552.4014288-1-arnd@arndb.de>

From: Al Viro <viro@zeniv.linux.org.uk>

... and lose the ridiculous games with compat_alloc_user_space()
there.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 fs/compat_ioctl.c      | 35 -----------------------------------
 fs/ioctl.c             | 29 +++++++++++++++++++++++++++++
 include/linux/falloc.h | 20 ++++++++++++++++++++
 3 files changed, 49 insertions(+), 35 deletions(-)

diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 3d08817be7b8..0a748324f96f 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -467,41 +467,6 @@ static int rtc_ioctl(struct file *file,
 	return -ENOIOCTLCMD;
 }
 
-/* on ia32 l_start is on a 32-bit boundary */
-#if defined(CONFIG_X86_64)
-struct space_resv_32 {
-	__s16		l_type;
-	__s16		l_whence;
-	__s64		l_start	__attribute__((packed));
-			/* len == 0 means until end of file */
-	__s64		l_len __attribute__((packed));
-	__s32		l_sysid;
-	__u32		l_pid;
-	__s32		l_pad[4];	/* reserve area */
-};
-
-#define FS_IOC_RESVSP_32		_IOW ('X', 40, struct space_resv_32)
-#define FS_IOC_RESVSP64_32	_IOW ('X', 42, struct space_resv_32)
-
-/* just account for different alignment */
-static int compat_ioctl_preallocate(struct file *file,
-			struct space_resv_32    __user *p32)
-{
-	struct space_resv	__user *p = compat_alloc_user_space(sizeof(*p));
-
-	if (copy_in_user(&p->l_type,	&p32->l_type,	sizeof(s16)) ||
-	    copy_in_user(&p->l_whence,	&p32->l_whence, sizeof(s16)) ||
-	    copy_in_user(&p->l_start,	&p32->l_start,	sizeof(s64)) ||
-	    copy_in_user(&p->l_len,	&p32->l_len,	sizeof(s64)) ||
-	    copy_in_user(&p->l_sysid,	&p32->l_sysid,	sizeof(s32)) ||
-	    copy_in_user(&p->l_pid,	&p32->l_pid,	sizeof(u32)) ||
-	    copy_in_user(&p->l_pad,	&p32->l_pad,	4*sizeof(u32)))
-		return -EFAULT;
-
-	return ioctl_preallocate(file, p);
-}
-#endif
-
 /*
  * simple reversible transform to make our table more evenly
  * distributed after sorting.
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 3f28b39f32f3..9d26251f34a9 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -490,6 +490,35 @@ int ioctl_preallocate(struct file *filp, void __user *argp)
 	return vfs_fallocate(filp, FALLOC_FL_KEEP_SIZE, sr.l_start, sr.l_len);
 }
 
+/* on ia32 l_start is on a 32-bit boundary */
+#if defined CONFIG_COMPAT && defined(CONFIG_X86_64)
+/* just account for different alignment */
+int compat_ioctl_preallocate(struct file *file,
+				struct space_resv_32 __user *argp)
+{
+	struct inode *inode = file_inode(file);
+	struct space_resv_32 sr;
+
+	if (copy_from_user(&sr, argp, sizeof(sr)))
+		return -EFAULT;
+
+	switch (sr.l_whence) {
+	case SEEK_SET:
+		break;
+	case SEEK_CUR:
+		sr.l_start += file->f_pos;
+		break;
+	case SEEK_END:
+		sr.l_start += i_size_read(inode);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return vfs_fallocate(file, FALLOC_FL_KEEP_SIZE, sr.l_start, sr.l_len);
+}
+#endif
+
 static int file_ioctl(struct file *filp, unsigned int cmd,
 		unsigned long arg)
 {
diff --git a/include/linux/falloc.h b/include/linux/falloc.h
index 674d59f4d6ce..fc61fdb9d1e9 100644
--- a/include/linux/falloc.h
+++ b/include/linux/falloc.h
@@ -29,4 +29,24 @@ struct space_resv {
 					 FALLOC_FL_INSERT_RANGE |	\
 					 FALLOC_FL_UNSHARE_RANGE)
 
+/* on ia32 l_start is on a 32-bit boundary */
+#if defined(CONFIG_X86_64)
+struct space_resv_32 {
+	__s16		l_type;
+	__s16		l_whence;
+	__s64		l_start	__attribute__((packed));
+			/* len == 0 means until end of file */
+	__s64		l_len __attribute__((packed));
+	__s32		l_sysid;
+	__u32		l_pid;
+	__s32		l_pad[4];	/* reserve area */
+};
+
+#define FS_IOC_RESVSP_32		_IOW ('X', 40, struct space_resv_32)
+#define FS_IOC_RESVSP64_32	_IOW ('X', 42, struct space_resv_32)
+
+int compat_ioctl_preallocate(struct file *, struct space_resv_32 __user *);
+
+#endif
+
 #endif /* _FALLOC_H_ */
-- 
2.20.0


  parent reply	other threads:[~2019-07-30 19:27 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-30 19:25 [PATCH v5 00/29] compat_ioctl.c removal, part 1/3 Arnd Bergmann
2019-07-30 19:25 ` [PATCH v5 01/29] fix compat handling of FICLONERANGE, FIDEDUPERANGE and FS_IOC_FIEMAP Arnd Bergmann
2019-07-30 19:25 ` [PATCH v5 02/29] FIGETBSZ: fix compat Arnd Bergmann
2019-07-30 19:25 ` [PATCH v5 03/29] compat: itanic doesn't have one Arnd Bergmann
2019-07-30 19:25 ` [PATCH v5 04/29] do_vfs_ioctl(): use saner types Arnd Bergmann
2019-07-30 19:25 ` Arnd Bergmann [this message]
2019-07-30 19:25 ` [PATCH v5 06/29] compat_sys_ioctl(): make parallel to do_vfs_ioctl() Arnd Bergmann
2019-07-30 19:25 ` [PATCH v5 07/29] ceph: fix compat_ioctl for ceph_dir_operations Arnd Bergmann
2019-07-30 19:25 ` [PATCH v5 08/29] compat_ioctl: drop FIOQSIZE table entry Arnd Bergmann
2019-07-30 19:25 ` [PATCH v5 09/29] compat_ioctl: pppoe: fix PPPOEIOCSFWD handling Arnd Bergmann
2019-07-30 21:42   ` David Miller
2019-07-30 19:25 ` [PATCH v5 10/29] compat_ioctl: add compat_ptr_ioctl() Arnd Bergmann
2019-07-30 19:25 ` [PATCH v5 11/29] compat_ioctl: move rtc handling into rtc-dev.c Arnd Bergmann
2019-07-30 19:50 ` [PATCH v5 12/29] compat_ioctl: move drivers to compat_ptr_ioctl Arnd Bergmann
2019-07-30 21:43   ` David Miller
2019-07-31  8:37   ` Cornelia Huck
2019-07-30 19:55 ` [PATCH v5 13/29] compat_ioctl: move more " Arnd Bergmann
2019-07-30 19:55   ` [PATCH v5 14/29] compat_ioctl: use correct compat_ptr() translation in drivers Arnd Bergmann
2019-07-30 19:55   ` [PATCH v5 15/29] compat_ioctl: move tape handling into drivers Arnd Bergmann
2019-07-31 10:50     ` Heiko Carstens
2019-07-31 15:47       ` Arnd Bergmann
2019-07-30 19:55   ` [PATCH v5 16/29] compat_ioctl: move ATYFB_CLK handling to atyfb driver Arnd Bergmann
2019-07-30 19:55   ` [PATCH v5 17/29] compat_ioctl: move isdn/capi ioctl translation into driver Arnd Bergmann
2019-07-30 19:55   ` [PATCH v5 18/29] compat_ioctl: move rfcomm handlers " Arnd Bergmann
2019-08-12 16:29     ` Marcel Holtmann
2019-07-30 19:55   ` [PATCH v5 19/29] compat_ioctl: move hci_sock " Arnd Bergmann
2019-08-12 16:29     ` Marcel Holtmann
2019-07-30 20:14   ` [PATCH v5 13/29] compat_ioctl: move more drivers to compat_ptr_ioctl Dan Williams
2019-07-30 20:01 ` [PATCH v5 20/29] compat_ioctl: remove HCIUART handling Arnd Bergmann
2019-07-30 20:01   ` [PATCH v5 21/29] compat_ioctl: remove HIDIO translation Arnd Bergmann
2019-07-30 20:01   ` [PATCH v5 22/29] compat_ioctl: remove translation for sound ioctls Arnd Bergmann
2019-07-30 20:01   ` [PATCH v5 23/29] compat_ioctl: remove IGNORE_IOCTL() Arnd Bergmann
2019-07-30 20:01   ` [PATCH v5 24/29] compat_ioctl: remove /dev/random commands Arnd Bergmann
2019-07-30 20:01   ` [PATCH v5 25/29] compat_ioctl: remove joystick ioctl translation Arnd Bergmann
2019-07-30 20:01   ` [PATCH v5 26/29] compat_ioctl: remove PCI " Arnd Bergmann
2019-07-30 20:01   ` [PATCH v5 27/29] compat_ioctl: remove /dev/raw " Arnd Bergmann
2019-07-30 20:01   ` [PATCH v5 28/29] compat_ioctl: remove last RAID handling code Arnd Bergmann
2019-07-30 20:01   ` [PATCH v5 29/29] compat_ioctl: remove unused convert_in_user macro Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190730192552.4014288-6-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=amir73il@gmail.com \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).