linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org,
	linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org,
	linux-ppp@vger.kernel.org, Paul Mackerras <paulus@samba.org>,
	"David S. Miller" <davem@davemloft.net>,
	Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH v6 38/43] compat_ioctl: move PPPIOCSCOMPRESS to ppp_generic
Date: Wed,  9 Oct 2019 21:10:39 +0200	[thread overview]
Message-ID: <20191009191044.308087-39-arnd@arndb.de> (raw)
In-Reply-To: <20191009190853.245077-1-arnd@arndb.de>

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

Rather than using a compat_alloc_user_space() buffer, moving
this next to the native handler allows sharing most of
the code, leaving only the user copy portion distinct.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: netdev@vger.kernel.org
Cc: linux-ppp@vger.kernel.org
Cc: Paul Mackerras <paulus@samba.org>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/net/ppp/ppp_generic.c | 53 +++++++++++++++++++++++++----------
 fs/compat_ioctl.c             | 32 ---------------------
 2 files changed, 38 insertions(+), 47 deletions(-)

diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index 7f8430e6b137..fb8e0ac099b8 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -270,7 +270,7 @@ static void ppp_mp_insert(struct ppp *ppp, struct sk_buff *skb);
 static struct sk_buff *ppp_mp_reconstruct(struct ppp *ppp);
 static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb);
 #endif /* CONFIG_PPP_MULTILINK */
-static int ppp_set_compress(struct ppp *ppp, unsigned long arg);
+static int ppp_set_compress(struct ppp *ppp, struct ppp_option_data *data);
 static void ppp_ccp_peek(struct ppp *ppp, struct sk_buff *skb, int inbound);
 static void ppp_ccp_closed(struct ppp *ppp);
 static struct compressor *find_compressor(int type);
@@ -708,9 +708,14 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		break;
 
 	case PPPIOCSCOMPRESS:
-		err = ppp_set_compress(ppp, arg);
+	{
+		struct ppp_option_data data;
+		if (copy_from_user(&data, argp, sizeof(data)))
+			err = -EFAULT;
+		else
+			err = ppp_set_compress(ppp, &data);
 		break;
-
+	}
 	case PPPIOCGUNIT:
 		if (put_user(ppp->file.index, p))
 			break;
@@ -827,6 +832,13 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 }
 
 #ifdef CONFIG_COMPAT
+struct ppp_option_data32 {
+	compat_uptr_t		ptr;
+	u32			length;
+	compat_int_t		transmit;
+};
+#define PPPIOCSCOMPRESS32	_IOW('t', 77, struct ppp_option_data32)
+
 static long ppp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	struct ppp_file *pf;
@@ -863,6 +875,21 @@ static long ppp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long
 			break;
 		}
 #endif /* CONFIG_PPP_FILTER */
+		case PPPIOCSCOMPRESS32:
+		{
+			struct ppp_option_data32 data32;
+			if (copy_from_user(&data32, argp, sizeof(data32))) {
+				err = -EFAULT;
+			} else {
+				struct ppp_option_data data = {
+					.ptr = compat_ptr(data32.ptr),
+					.length = data32.length,
+					.transmit = data32.transmit
+				};
+				err = ppp_set_compress(ppp, &data);
+			}
+			break;
+		}
 		}
 	}
 	mutex_unlock(&ppp_mutex);
@@ -2783,24 +2810,20 @@ ppp_output_wakeup(struct ppp_channel *chan)
 
 /* Process the PPPIOCSCOMPRESS ioctl. */
 static int
-ppp_set_compress(struct ppp *ppp, unsigned long arg)
+ppp_set_compress(struct ppp *ppp, struct ppp_option_data *data)
 {
-	int err;
+	int err = -EFAULT;
 	struct compressor *cp, *ocomp;
-	struct ppp_option_data data;
 	void *state, *ostate;
 	unsigned char ccp_option[CCP_MAX_OPTION_LENGTH];
 
-	err = -EFAULT;
-	if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
-		goto out;
-	if (data.length > CCP_MAX_OPTION_LENGTH)
+	if (data->length > CCP_MAX_OPTION_LENGTH)
 		goto out;
-	if (copy_from_user(ccp_option, (void __user *) data.ptr, data.length))
+	if (copy_from_user(ccp_option, data->ptr, data->length))
 		goto out;
 
 	err = -EINVAL;
-	if (data.length < 2 || ccp_option[1] < 2 || ccp_option[1] > data.length)
+	if (data->length < 2 || ccp_option[1] < 2 || ccp_option[1] > data->length)
 		goto out;
 
 	cp = try_then_request_module(
@@ -2810,8 +2833,8 @@ ppp_set_compress(struct ppp *ppp, unsigned long arg)
 		goto out;
 
 	err = -ENOBUFS;
-	if (data.transmit) {
-		state = cp->comp_alloc(ccp_option, data.length);
+	if (data->transmit) {
+		state = cp->comp_alloc(ccp_option, data->length);
 		if (state) {
 			ppp_xmit_lock(ppp);
 			ppp->xstate &= ~SC_COMP_RUN;
@@ -2829,7 +2852,7 @@ ppp_set_compress(struct ppp *ppp, unsigned long arg)
 			module_put(cp->owner);
 
 	} else {
-		state = cp->decomp_alloc(ccp_option, data.length);
+		state = cp->decomp_alloc(ccp_option, data->length);
 		if (state) {
 			ppp_recv_lock(ppp);
 			ppp->rstate &= ~SC_DECOMP_RUN;
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index eda41b2537f0..0b5a732d7afd 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -99,13 +99,6 @@ static int sg_grt_trans(struct file *file,
 }
 #endif /* CONFIG_BLOCK */
 
-struct ppp_option_data32 {
-	compat_caddr_t	ptr;
-	u32			length;
-	compat_int_t		transmit;
-};
-#define PPPIOCSCOMPRESS32	_IOW('t', 77, struct ppp_option_data32)
-
 struct ppp_idle32 {
 	compat_time_t xmit_idle;
 	compat_time_t recv_idle;
@@ -133,29 +126,6 @@ static int ppp_gidle(struct file *file, unsigned int cmd,
 	return err;
 }
 
-static int ppp_scompress(struct file *file, unsigned int cmd,
-	struct ppp_option_data32 __user *odata32)
-{
-	struct ppp_option_data __user *odata;
-	__u32 data;
-	void __user *datap;
-
-	odata = compat_alloc_user_space(sizeof(*odata));
-
-	if (get_user(data, &odata32->ptr))
-		return -EFAULT;
-
-	datap = compat_ptr(data);
-	if (put_user(datap, &odata->ptr))
-		return -EFAULT;
-
-	if (copy_in_user(&odata->length, &odata32->length,
-			 sizeof(__u32) + sizeof(int)))
-		return -EFAULT;
-
-	return do_ioctl(file, PPPIOCSCOMPRESS, (unsigned long) odata);
-}
-
 /*
  * simple reversible transform to make our table more evenly
  * distributed after sorting.
@@ -249,8 +219,6 @@ static long do_ioctl_trans(unsigned int cmd,
 	switch (cmd) {
 	case PPPIOCGIDLE32:
 		return ppp_gidle(file, cmd, argp);
-	case PPPIOCSCOMPRESS32:
-		return ppp_scompress(file, cmd, argp);
 #ifdef CONFIG_BLOCK
 	case SG_GET_REQUEST_TABLE:
 		return sg_grt_trans(file, cmd, argp);
-- 
2.20.0


  parent reply	other threads:[~2019-10-09 19:12 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-09 19:08 [PATCH v6 00/43] compat_ioctl: remove most of fs/compat_ioctl.c Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 01/43] fix compat handling of FICLONERANGE, FIDEDUPERANGE and FS_IOC_FIEMAP Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 02/43] FIGETBSZ: fix compat Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 03/43] compat: itanic doesn't have one Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 04/43] do_vfs_ioctl(): use saner types Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 05/43] compat: move FS_IOC_RESVSP_32 handling to fs/ioctl.c Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 06/43] compat_sys_ioctl(): make parallel to do_vfs_ioctl() Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 07/43] ceph: fix compat_ioctl for ceph_dir_operations Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 08/43] compat_ioctl: drop FIOQSIZE table entry Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 09/43] compat_ioctl: add compat_ptr_ioctl() Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 10/43] compat_ioctl: move rtc handling into rtc-dev.c Arnd Bergmann
2019-10-09 19:25   ` Alexandre Belloni
2019-10-09 19:31     ` Arnd Bergmann
2019-10-17 13:42   ` [Y2038] " Ben Hutchings
2019-10-17 14:33     ` Arnd Bergmann
2019-10-17 18:19       ` Ben Hutchings
2019-10-22  4:30       ` Al Viro
2019-10-22 12:14         ` Arnd Bergmann
2019-10-23 10:29           ` Alexandre Belloni
2019-10-23 14:28             ` Arnd Bergmann
2019-10-23 14:34               ` Alexandre Belloni
2019-10-23 15:02                 ` Arnd Bergmann
2019-10-23 10:32       ` Alexandre Belloni
2019-10-09 19:10 ` [PATCH v6 11/43] compat_ioctl: move drivers to compat_ptr_ioctl Arnd Bergmann
2019-10-14 19:30   ` Jarkko Sakkinen
2019-10-22  4:34   ` Al Viro
2019-10-22 10:26     ` Arnd Bergmann
2019-10-23  3:17       ` Al Viro
2019-10-23 15:26         ` Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 12/43] compat_ioctl: move more " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 13/43] compat_ioctl: use correct compat_ptr() translation in drivers Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 14/43] compat_ioctl: move tape handling into drivers Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 15/43] compat_ioctl: move ATYFB_CLK handling to atyfb driver Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 16/43] compat_ioctl: move isdn/capi ioctl translation into driver Arnd Bergmann
2019-10-17 18:25   ` [Y2038] " Ben Hutchings
2019-10-18 14:18     ` Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 17/43] compat_ioctl: move rfcomm handlers " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 18/43] compat_ioctl: move hci_sock " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 19/43] compat_ioctl: remove HCIUART handling Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 20/43] compat_ioctl: remove HIDIO translation Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 21/43] compat_ioctl: remove translation for sound ioctls Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 22/43] compat_ioctl: remove IGNORE_IOCTL() Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 23/43] compat_ioctl: remove /dev/random commands Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 24/43] compat_ioctl: remove joystick ioctl translation Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 25/43] compat_ioctl: remove PCI " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 26/43] compat_ioctl: remove /dev/raw " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 27/43] compat_ioctl: remove last RAID handling code Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 28/43] compat_ioctl: remove unused convert_in_user macro Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 29/43] gfs2: add compat_ioctl support Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 29/43] REPLACE " Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 30/43] fs: compat_ioctl: move FITRIM emulation into file systems Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 31/43] compat_ioctl: move WDIOC handling into wdt drivers Arnd Bergmann
2019-10-18 12:49   ` [Y2038] " Ben Hutchings
2019-10-18 13:31     ` Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 32/43] compat_ioctl: reimplement SG_IO handling Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 33/43] af_unix: add compat_ioctl support Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 34/43] compat_ioctl: handle SIOCOUTQNSD Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 35/43] compat_ioctl: move SIOCOUTQ out of compat_ioctl.c Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 36/43] tty: handle compat PPP ioctls Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 37/43] compat_ioctl: unify copy-in of ppp filters Arnd Bergmann
2019-10-09 19:10 ` Arnd Bergmann [this message]
2019-10-09 19:10 ` [PATCH v6 39/43] compat_ioctl: handle PPPIOCGIDLE for 64-bit time_t Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 40/43] compat_ioctl: ppp: move simple commands into ppp_generic.c Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 41/43] compat_ioctl: move SG_GET_REQUEST_TABLE handling Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 42/43] pktcdvd: add compat_ioctl handler Arnd Bergmann
2019-10-09 19:10 ` [PATCH v6 43/43] scsi: sd: enable compat ioctls for sed-opal 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=20191009191044.308087-39-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ppp@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=y2038@lists.linaro.org \
    /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).