From patchwork Wed Aug 14 20:54:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 171369 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1320753ily; Wed, 14 Aug 2019 13:56:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9HG22rGFDnMGEwJLhVNYFvTxz1CPpjJkclsxBpIT3yrW5eD1TNMjUFT2j055g/gZoOeNQ X-Received: by 2002:a65:614a:: with SMTP id o10mr828223pgv.407.1565816188127; Wed, 14 Aug 2019 13:56:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565816188; cv=none; d=google.com; s=arc-20160816; b=xnMSugtfgb7VG6SG0qHm+h/AR4Lv6L6CaWYoznRw5HfHbXn/V8Ei4teka21by94V0E wEGUnSCU3o54sG17BNJgnRNletjKI8haaOZfqG3W9/2OWd3aMzrvaTYOCQAn9xfI6Gq1 CC+J2W9gaOkkqgGfzX+KQjVsh4/9+sIG5+12ooDW+3VYl+3ybI9pDq7MeYc8P6yJBJrs 78fvVkAIMUwR5nlEXWytQe+jzS0PqsrlG3Fd1lPUzCMWUirMjI8l2iDb2ZiIOHLai5pN aTexgDF6033JBbCabW/l3bo6Y2Bqu0C94NXFkeOWqvDH50/E24A/jg2VGp2g6BFOMg9M Sfpg== 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=tsSxsjVGUVkLwy+nHhcU7jpAePwrrsM7u53H+DTLBZY=; b=SlGhu8pFLyrf0EtqFPySj1nqHQQswZc5c9rlrIxOoZJH1kOmEk8Ilwly8pMS/EPn8F nq4iTwFLHjdVUA5VycQTMS4XZqgk2Lhs5DNU8atZt1B2LbOIVnt2FHoQEiPn1Ri76cDQ oQicq/CtfJfsOOCZRQB7K18I6BX+umtmpuwFGvoflIzVwxbyYUoQQmoiEu7iSIhVdr7/ A2zoMhH1b06W/6DGQQ/7EKKRUQ7jr4n19jwna3oPKpCHFi8rgepHpui1zjG3eAsu2Ed0 0chbbDxBRptT10f0FcOsCTRF8AURjBcEl44WnHJ7QWEOcCk62jb4v96owOfM/a0k4iZz KB6A== 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 z9si569261plo.66.2019.08.14.13.56.27; Wed, 14 Aug 2019 13:56:28 -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 S1730046AbfHNU40 (ORCPT + 28 others); Wed, 14 Aug 2019 16:56:26 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:41555 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729547AbfHNU40 (ORCPT ); Wed, 14 Aug 2019 16:56:26 -0400 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1Mq33i-1icEwC2vac-00nBpN; Wed, 14 Aug 2019 22:56:18 +0200 From: Arnd Bergmann To: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, Paul Mackerras , "David S. Miller" Cc: Arnd Bergmann , Greg Kroah-Hartman , linux-ppp@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v5 13/18] compat_ioctl: move PPPIOCSCOMPRESS to ppp_generic Date: Wed, 14 Aug 2019 22:54:48 +0200 Message-Id: <20190814205521.122180-4-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20190814204259.120942-1-arnd@arndb.de> References: <20190814204259.120942-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:udnKTOM/1mbLHbQUn0rirIQLTUIu/NvLort76AdGfCbEvjij9Rk USgtylTUknlJaGhjBmz2nqZyCbQIYXNFPMTJH4ULrrssYAkJp/7sJL0fkltg22eIpao+6K1 umR/cMUFd8rXt7+qoI4/zk1KeaNniBK24hYWshdgcodDZpZNMuQqkkJFMqGTjT1JdCK30PL gV0B9aMZNrMeNMyw7OO7A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:zWgcd8uHvCo=:+3VhA5j2wTFJs1s/SEUYpw KCeo2xG4MKF0Be5k9nzt9GYHzSmwsPRm1t18w01/doFpLL9sfMWnYmwtTfySXJXJK8OjTbzXJ wr551CrrXcNf1Sj49t5jkpn0mf2mMXhvkPhu+CPOXk3ryranetpCWtnKQ7hAaGrLWeBYfg8dv lYujtQvHh4QTDUvzbeeB/JTlRr+ZoyX1hFnkuYl7eiMpXlhJR5RxpLsbEn66uZl5lZmdTsDzE jOkzQc4fnjOlZdaoqV6lHN2SVJBiArAVvWOLIbwTn/V2GMx+nGPUtpZc5HGBTHm3dRH+Apvnb /FcXrp+/KwOZLhfv6oKJlxScew6FX8f5kQ52PbOO5kNZCe9qPr4kXdeKeuzpyPI+iUpCbWwqA riH3MtzZWD8gl3nJi4G8fficgbzGALFBb08eQ0zJdWn5j8yJz2/8X2yqnok+zRgW5rAveI+Rt mAyqmFGBZ2To1bHW29VJ+tO17yZvpSmUPULfnl/+Id0HaISF4jnUlcW4fuLDPXHreLqlqo2Z+ Nk2nvBq3zCBxqxVaKOlA75Yqv7UDPQDaOnTCWQ5RafgvPPaijwAtOmEd+jvnw8H3XlD/0CbgY yG0JgXMi97/UYmQc5PZRAn2u+UpXLGh2gCsnZB/8GE43bCqqLHHpwsikQRNvOm5WOZ8cLzIMS JdmMrqe4OzA+FL5BSNwjOAfxVEgPcDwhrAunKJGsgtmUW1E0xIjRbVZMET0oQyaGG0XyWPAA5 3N3TXz1PUeM0DYfguvEPwrW8byNuVlZDcFRluQ== 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 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 e3f207767589..2ab67bad6224 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); @@ -2781,24 +2808,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( @@ -2808,8 +2831,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; @@ -2827,7 +2850,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);