From patchwork Wed Oct 9 19:10:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 175647 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1171609ill; Wed, 9 Oct 2019 12:12:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyb+hTF3hlaLQC1TlU46zABinO0o6Ssc2HuT7vjVoAQW9XN7vRUxBREFmcaUfdhJZlvMXHb X-Received: by 2002:a05:6402:2042:: with SMTP id bc2mr4552750edb.12.1570648327718; Wed, 09 Oct 2019 12:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570648327; cv=none; d=google.com; s=arc-20160816; b=qrvDIecmbhDS+xDwb3YYDYFXouNbs0Dpg5ziH46AoDeqdZ1BPLtnOcq9nJl21bujM2 wr6HIhQrErmgDEeH+HAPClgpjF/+nAtrjCgHgoaNjlLVvol/pdjS8Z4T5T5QJzJ5IES3 n+luYZepJy+ojRQ1JO80mk0TbE8wHISZb7Eb+zmFX8QEfElWWOa4n6GYA0QBt8RAdnl4 8KRSt7aZNjfvgcI3VrFLzNi3+V7qx2Nw4xkG+MWDVLpnRe0UtlSJd1Tmny7Dohf0XxzE 2GuUAFLS4JJTozMViJNDTAJZbjC2DQBHGHOyy5D5KRfhqbNxOZCOmxbBQQxlCHo8QzsP 6k+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2U0R9XLW5nfShfx5anlsuf7ibZ8182mJ82UEsDkmLyw=; b=oS0pfnQQ14dR6QTBUxKdAJMWK3tRE9hqjyzxnnnnSGT9oDmVUdPOeGtMLkRpxd8v05 AFIv9GuZekVSUGaE8gYx/1Bl9jyCiefsbBAU7uAwo6t/4rMfBcqTZfrOV4yz4XCrv1Qc sD5/BGSJhjKpexBf6dQSLXZYe13sZXh7MEuhrC+8mGv0FE3+Ux/0nGONVSo+W0Y6nBoP u08uNx4lIwVVSfXOdW2MvYeJRtihLI8hQA30tPEXeMPpFvNu1ror3nv9L3eHJyqe3V3/ XyGPl7HOowvSlHNLKaQyD2gtTHS0WdDKUY3i/B3BefrOOHIS4bmYOoE47aa5VeHMAuij VooA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gh16si1676469ejb.150.2019.10.09.12.12.07; Wed, 09 Oct 2019 12:12:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732127AbfJITLi (ORCPT + 26 others); Wed, 9 Oct 2019 15:11:38 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:49579 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732007AbfJITL2 (ORCPT ); Wed, 9 Oct 2019 15:11:28 -0400 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1Md6dH-1hiwkU0jNz-00aG5k; Wed, 09 Oct 2019 21:11:21 +0200 From: Arnd Bergmann To: Al Viro 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 , "David S. Miller" , Arnd Bergmann Subject: [PATCH v6 38/43] compat_ioctl: move PPPIOCSCOMPRESS to ppp_generic Date: Wed, 9 Oct 2019 21:10:39 +0200 Message-Id: <20191009191044.308087-39-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191009190853.245077-1-arnd@arndb.de> References: <20191009190853.245077-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:H6G0tlLSScXup0r7qf/eAazbyiLfB1lHraA+to9mpDntYcl55Fx rV4LMRRmalhAIrE4CLMuoXlSi43enKLVS1soV9cB/axH1hNh69KlrEr/90ZIJYNvBDzt2uS q0SPqlKKurnJ6Sk2G7iPnPbbR4ATD9bd6k8dT3+mAmEXTzF3vD26SOywuwEy/YN2vTshp/Y TGyvbKmU/56xSps1PpChw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:Rq7Oei81/w8=:kSykHrXN0CmDk/mp6241EF XQ1OAhGsHI24UVLWlFYg0SHky3n3vXHDC3MDmXbIqAeLz9ylkQluT7c5tc65FHuzhUI9/er9X najDOE+hbSvosgtUGUFa29rwC1XrP7U9wyUOVc9SiKXvF8uTWxKIyYo+/WyFgaT3XAbXyo68B wgJLYglr5IE7AsDf4QYmZk8HScOQxMYFfjXGKdHrgSwq1bFmeejio0GehhdJPtR7vFg2xLHuX d3Ul6z8+UZvLa0vp+I+BCzfLYGUn4DEdIaIoEVZsAiUCjdocQ5oPya6zxG7uob9MPYKr4PuBL RpAK2To3rtV+9YGDy5VoXpQR1ixjeOhRwuhspKmT0jZZTmLjbYW0rmHff07wtWVKU8+qkynwt IlickwH2a2DmRFLB/GUgS1RHQfu7yKvO9sEm+PLmRqqZe1F4Ja9rCPnYI1gBDapRnGAUtLENk jVoyjSvwSP6eKRfzQX16AaCYf8/EUaltABOz5IPYafpaOYsgz/FVEdvToPNW0SwOiOFw1yzXJ UtBqWrFsIclFWLyxSSVId8qKFhMjmQx1rzv0piOt6KDRop+SsrAwM0gfjDhNCod5GaSVmPLKG 0hcD0Ro1hdhVNbNsXuWjg8lnIKwbyWhFG50+fGH2aGRoR1htTZ8uX96JwaXflNUvOfoTbEMjm 78o5r8Q4D++z+0b64V2GXof51PUasLrvEjUseUytCXIA4cXtYjynYMYAQJOGqdmHvzcMH63eD QJ/ETelUxdp9k2heA5yoahl3/BUc0aKoswgoCRrmozGkpgiK4jVEbf6rgm+f4fs/KCRMJtOQS +bOBjVaBMdSD+QOJpWg9kjfXUqj0JGgcj0uSx6AHeVjPAmPvUtsE7iNXe1p9yGENuVeKEUCiM Be2qhJvzUMBBG1rD+ARA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro 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 Cc: netdev@vger.kernel.org Cc: linux-ppp@vger.kernel.org Cc: Paul Mackerras Cc: "David S. Miller" Signed-off-by: Arnd Bergmann --- drivers/net/ppp/ppp_generic.c | 53 +++++++++++++++++++++++++---------- fs/compat_ioctl.c | 32 --------------------- 2 files changed, 38 insertions(+), 47 deletions(-) -- 2.20.0 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);