From patchwork Wed Sep 12 15:01:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 146567 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4931287ljw; Wed, 12 Sep 2018 08:02:18 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaDZ6E3AjrBclTlbAWeItD1iiRPZZsoAyK6CfBxaRrD6nY6UqGPwIsAs+dWD4SSxECS2swh X-Received: by 2002:a63:e4b:: with SMTP id 11-v6mr2819657pgo.320.1536764538399; Wed, 12 Sep 2018 08:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536764538; cv=none; d=google.com; s=arc-20160816; b=dnl2kTLkje7lE4sjcqBSs+dU9a72Xt1m4mc6uwteQIbiTquZg415PEDqdKLvS1H1u3 alHtljZNDZSPqLbXZZv6Da/SP+AQTbSpmib9H2yI7D/n4u4onceAdwz3M9vU86D35HzG mRgrjFiE6ymxMSN86T94ObzRBZ9aBkKMeo5m3vnrsCSrLIXJVK+KyGmzsYJMDPfqXgxt v4oRv+S0HyhFqpgZRLahO7doNbI+wfIVJriGvlTbZMuqFQz7xWH1e702g79fiLlEK9gs nOxP6Do4hFT85Srl6O5Wz2CBwOn5gh1wU0QE/IET6225fSfmPvr6qoGMxuvtmlN90wM4 txkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=x9FbuAIMEI2OIRpwDQ8JVswWlz8K8p1NnEgiEWt+bBk=; b=VfVR8Q1k9fNGn09rTzIZjLZ94jYARSdzl9yruO8BRMe/JoAssJS4wpl+QZP4aB0OUa vcqhhQ02NCqhA13o+5juNAilYWg8cabNWNgrFWShDIZpOZNwFG7MlbkQntjECD/0rUrr e9+N4ELnQPjJyCqkfFItdTlDhpV547oqQfxyyBJ2HSpDe7cvq06ihnF1QTOjLrIrRT7w Lf7ppuPZSm4gFz1+qcorhFVfOrztAynRYFIHOv1Z576lPU0r1sZFnw9ps6fgXf3/8vtp T7rGIdpTTVX9voMq1o0xb9A6g4gRmsjh9W9INicfsldJa1ataSvU0zEjpDC1P9/fUHU7 3KCg== 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 k2-v6si1162087pgp.602.2018.09.12.08.02.17; Wed, 12 Sep 2018 08:02:18 -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 S1728225AbeILUHJ (ORCPT + 32 others); Wed, 12 Sep 2018 16:07:09 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:52626 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727804AbeILUHI (ORCPT ); Wed, 12 Sep 2018 16:07:08 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue002 [212.227.15.129]) with ESMTPA (Nemesis) id 0MHfXI-1fz0Bb1MVw-003Iuh; Wed, 12 Sep 2018 17:01:47 +0200 From: Arnd Bergmann To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH v2 01/17] compat_ioctl: add generic_compat_ioctl_ptrarg() Date: Wed, 12 Sep 2018 17:01:02 +0200 Message-Id: <20180912150142.157913-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ernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Many drivers have ioctl() handlers that are completely compatible between 32-bit and 64-bit architectures, except for the argument that is passed down from user space and may have to be passed through compat_ptr() in order to become a valid 64-bit pointer. Using ".compat_ptr=generic_compat_ioctl_ptrarg" in file operations should let us simplify a lot of those drivers to avoid #ifdef checks, and convert additional drivers that don't have proper compat handling yet. Signed-off-by: Arnd Bergmann --- fs/compat_ioctl.c | 10 ++++++++++ include/linux/fs.h | 7 +++++++ 2 files changed, 17 insertions(+) -- 2.18.0 Reviewed-by: Jason Gunthorpe Acked-by: Greg Kroah-Hartman Acked-by: Greg Kroah-Hartman Reviewed-by: Takashi Iwai Acked-by: Darren Hart (VMware) diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c index a9b00942e87d..2d7c7e149083 100644 --- a/fs/compat_ioctl.c +++ b/fs/compat_ioctl.c @@ -122,6 +122,16 @@ get_user(val, srcptr) || put_user(val, dstptr); \ }) +/* helper function to avoid trivial compat_ioctl() implementations */ +long generic_compat_ioctl_ptrarg(struct file *file, unsigned int cmd, unsigned long arg) +{ + if (!file->f_op->unlocked_ioctl) + return -ENOIOCTLCMD; + + return file->f_op->unlocked_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); +} +EXPORT_SYMBOL_GPL(generic_compat_ioctl_ptrarg); + static int do_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int err; diff --git a/include/linux/fs.h b/include/linux/fs.h index 33322702c910..18a90aa2dc93 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1643,6 +1643,13 @@ int vfs_mkobj(struct dentry *, umode_t, extern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); +#ifdef CONFIG_COMPAT +extern long generic_compat_ioctl_ptrarg(struct file *file, unsigned int cmd, + unsigned long arg); +#else +#define generic_compat_ioctl_ptrarg NULL +#endif + /* * VFS file helper functions. */