Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1129435ybl; Wed, 4 Dec 2019 17:39:42 -0800 (PST) X-Google-Smtp-Source: APXvYqyrDel8JYGWMObHdAWRHEcsDS/1UhSNnVStT5l4sVJgW4A9Csf/lectx5SrPoU7sj2H6frK X-Received: by 2002:a05:6830:1bd5:: with SMTP id v21mr5170017ota.154.1575509982858; Wed, 04 Dec 2019 17:39:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575509982; cv=none; d=google.com; s=arc-20160816; b=P8mUhg+kOCgAOGrq8BAIn7X3gnqYJh3bEi8ofX7M+fhsYOh5y96Vetw2PIPSJ7M5M0 uVOfvLA6lgUEIy5UKWUOTwkWw9ie8jux2xHS9CKMAUbh9eXiT1UcgGJ+vdcObm+qGW+/ jFD31eMZ0LMCqacLtPbirpPCTP86iJt8bmv9SBVtwuhBW9lAJZmTp8KcdU3gMeQqzI8r GL7PzGZ7MD3iV3D5WL8eqAWBDcH5qDtCVh+VgWQFI2mEr5D5uJZy7gKMSldUZi4uKx4H WYG1WiCayVKZsvuVu1WwpfVznMuTB8LHFo2fom/1rf9jnv7iYhl75zj24ZdlDTY7G1JA HK0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=y5OyeMAaXxgAsXOOHmvpW7WsRUDMj2ghMVP9WbA7dSs=; b=O1J2HEMF+rLCafu9/vzE0ktPuMOQVbMHfakSD/hro1kotvmHyGMiFDouvIORf8Yesq wATwyaEZQQ1RiSntYP2153Yv/9lqLyQ2kShp6mi49JqCMP6S3UsHS3qzVtSr4FfTiIXP wt7xUokS/B1OqThd+kvxAbCEGCGEOvmp9OuRvANcshv/CvgCaBnlnNgsjm+m3al5THiJ EwTcy2qN9eRJuOOQPRazIFOwkEYqfV7ZM7KDMWLzcIkEqeHbKYek8rza1Df95t7b4OIY kGzi/aYcN5QcaHGtR55Ne9KuVKFaPnxxHKgAoO7oBN1IONKCF7NpezBZ+BdDVCkrrRvt 3siQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j1PtrmYc; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5si4684801oth.288.2019.12.04.17.39.12; Wed, 04 Dec 2019 17:39:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j1PtrmYc; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728121AbfLEBjJ (ORCPT + 99 others); Wed, 4 Dec 2019 20:39:09 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33493 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728098AbfLEBjI (ORCPT ); Wed, 4 Dec 2019 20:39:08 -0500 Received: by mail-pf1-f196.google.com with SMTP id y206so785334pfb.0; Wed, 04 Dec 2019 17:39:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=y5OyeMAaXxgAsXOOHmvpW7WsRUDMj2ghMVP9WbA7dSs=; b=j1PtrmYci3d/o0TYIkz5oe2dZc+fncrSlHwG2Cz/22uIuV0HbESTZVKJobQqM7O8yD 23nbMjdwKw7DZ56b0WhciP4cHHohnyGHiSya9Pgz5nHSeqALQ7Uwret3AbSUICgdzQD2 bF+0xHH4NKKjThpBQg0xhwS/PkbBbXds6Ittdhj1YACepzB75Smsr+0zXANEJ7nttC+F 1nf6fyG0F5Jjgtxod5j7EKhYgYETqMntBdAxxjfaLJy17IA4kbTWk81y6Hq5Di++hY4b IlLjXk9RcR5Q02NWXwHPSpD7KnwVQcelpcvnMorufOeFqcggXw4HbwCC7ZEGH1OFHdaK 4lvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=y5OyeMAaXxgAsXOOHmvpW7WsRUDMj2ghMVP9WbA7dSs=; b=e7QtGRjrnuO1K/6hD+otlQqtNwT54tqUwukx5ohdplaBBlCMFevptVclbz8Ep+Q/vl 2e/H7cqErz+TkmXVN8FAK+XteKkJExhETPKxJC+eeLSvNCSh0GCwkKqMa99/gX0wRUef R/Wx/BelocqAAWObisawqaut4OfbzdWW3QWUKBjOpZWdlbXCy0jQx8xo6sqL7IzJNTzH VQSlvOctpnbUXqeQxcwdPuVfIWSv6rUnGLxM/AbnsW1BAeZiPoaXC+gZeN/OFIdp01V8 a3ZIjojfpybxjVfSaEN90X345ULU8lKqDzg4Pt8EnEUCLbmPmP32j5aGHJBxmNy7xofg fRrQ== X-Gm-Message-State: APjAAAXv2wSDzG78BlfobubSo5RmleiEHNoH1OOFi2z0w7/9hMpu3RWO T4EYZptCslnz/LRtVPitjO5gh61X X-Received: by 2002:a63:e0c:: with SMTP id d12mr6455249pgl.3.1575509947770; Wed, 04 Dec 2019 17:39:07 -0800 (PST) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id j17sm9319208pfr.2.2019.12.04.17.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2019 17:39:07 -0800 (PST) Date: Wed, 4 Dec 2019 17:39:04 -0800 From: Dmitry Torokhov To: Abhishek Pandit-Subedi Cc: Pali =?iso-8859-1?Q?Roh=E1r?= , linux-input@vger.kernel.org, linux-bluetooth@vger.kernel.org, Luiz Augusto von Dentz , Bjorn Helgaas , linux-kernel@vger.kernel.org, Thomas Gleixner , Logan Gunthorpe , Greg Kroah-Hartman , Andrey Smirnov , Kirill Smelkov Subject: Re: [PATCH v3] Input: uinput - Add UI_SET_PHYS_STR and UI_SET_UNIQ_STR Message-ID: <20191205013904.GP50317@dtor-ws> References: <20191204135434.v3.1.Ib53f70556ffe94d9a1903632ee9b0dc929f94557@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191204135434.v3.1.Ib53f70556ffe94d9a1903632ee9b0dc929f94557@changeid> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On Wed, Dec 04, 2019 at 01:55:35PM -0800, Abhishek Pandit-Subedi wrote: > The ioctl definition for UI_SET_PHYS is ambiguous because it is defined > with size = sizeof(char*) but is expected to be given a variable length > string. Add a deprecation notice for UI_SET_PHYS and provide > UI_SET_PHYS_STR(len) which expects a size from the user. > > Also support setting the uniq attribute of the input device. The uniq > attribute is used as a unique identifier for the connected device. > > For example, uinput devices created by BlueZ will store the address of > the connected device as the uniq property. > > Signed-off-by: Abhishek Pandit-Subedi > --- > Hi input maintainers, > > Here is an updated patch that refactors the ioctl handlers (properly > allowing the size to be set from userspace). When calling the new > ioctls, the call signature will look like this: > > ``` > ioctl(fd, UI_SET_PHYS_STR(18), "00:11:22:33:44:55"); > ``` > > I've tested this on a Chromebook running kernel v4.19 with a sample > program compiled for both 32-bit (i.e. gcc -m32 test.c) and 64-bit. > > The final uinput device looks like this: > > ``` > udevadm info -a -p /devices/virtual/input/input18 > > Udevadm info starts with the device specified by the devpath and then > walks up the chain of parent devices. It prints for every device > found, all possible attributes in the udev rules key format. > A rule to match, can be composed by the attributes of the device > and the attributes from one single parent device. > > looking at device '/devices/virtual/input/input18': > KERNEL=="input18" > SUBSYSTEM=="input" > DRIVER=="" > ATTR{inhibited}=="0" > ATTR{name}=="Test" > ATTR{phys}=="00:00:00:33:44:55" > ATTR{properties}=="0" > ATTR{uniq}=="00:11:22:00:00:00" > > ``` > > > Changes in v3: > - Added UI_SET_PHYS_STR(len) and UI_SET_UNIQ_STR(len) and added > deprecation notice for UI_SET_PHYS > > Changes in v2: > - Added compat handling for UI_SET_UNIQ > > drivers/input/misc/uinput.c | 41 ++++++++++++++++++++++++++++++++++++- > include/uapi/linux/uinput.h | 5 +++++ > 2 files changed, 45 insertions(+), 1 deletion(-) > > diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c > index 84051f20b18a..27a750896c71 100644 > --- a/drivers/input/misc/uinput.c > +++ b/drivers/input/misc/uinput.c > @@ -20,6 +20,7 @@ > */ > #include > #include > +#include > #include > #include > #include > @@ -280,7 +281,7 @@ static int uinput_dev_flush(struct input_dev *dev, struct file *file) > > static void uinput_destroy_device(struct uinput_device *udev) > { > - const char *name, *phys; > + const char *name, *phys, *uniq; > struct input_dev *dev = udev->dev; > enum uinput_state old_state = udev->state; > > @@ -289,6 +290,7 @@ static void uinput_destroy_device(struct uinput_device *udev) > if (dev) { > name = dev->name; > phys = dev->phys; > + uniq = dev->uniq; > if (old_state == UIST_CREATED) { > uinput_flush_requests(udev); > input_unregister_device(dev); > @@ -297,6 +299,7 @@ static void uinput_destroy_device(struct uinput_device *udev) > } > kfree(name); > kfree(phys); > + kfree(uniq); > udev->dev = NULL; > } > } > @@ -840,6 +843,7 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, > struct uinput_ff_erase ff_erase; > struct uinput_request *req; > char *phys; > + char *uniq; > const char *name; > unsigned int size; > > @@ -916,6 +920,8 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, > goto out; > > case UI_SET_PHYS: > + pr_warn_once("uinput: UI_SET_PHYS is deprecated. Use UI_SET_PHYS_STR"); > + > if (udev->state == UIST_CREATED) { > retval = -EINVAL; > goto out; > @@ -1023,6 +1029,39 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, > case UI_ABS_SETUP & ~IOCSIZE_MASK: > retval = uinput_abs_setup(udev, p, size); > goto out; > + > + case UI_SET_PHYS_STR(0): > + if (udev->state == UIST_CREATED) { > + retval = -EINVAL; > + goto out; > + } > + > + phys = strndup_user(p, size); > + if (IS_ERR(phys)) { > + retval = PTR_ERR(phys); > + goto out; > + } > + > + kfree(udev->dev->phys); > + udev->dev->phys = phys; Could we maybe refactor this into uinput_get_user_str(udev, &udev->dev->phys, p, size) ? > + goto out; > + > + case UI_SET_UNIQ_STR(0): > + if (udev->state == UIST_CREATED) { > + retval = -EINVAL; > + goto out; > + } > + > + uniq = strndup_user(p, size); > + if (IS_ERR(uniq)) { > + retval = PTR_ERR(uniq); > + goto out; > + } > + > + kfree(udev->dev->uniq); > + udev->dev->uniq = uniq; > + goto out; > + > } > > retval = -EINVAL; > diff --git a/include/uapi/linux/uinput.h b/include/uapi/linux/uinput.h > index c9e677e3af1d..84d4fa142830 100644 > --- a/include/uapi/linux/uinput.h > +++ b/include/uapi/linux/uinput.h > @@ -142,9 +142,14 @@ struct uinput_abs_setup { > #define UI_SET_LEDBIT _IOW(UINPUT_IOCTL_BASE, 105, int) > #define UI_SET_SNDBIT _IOW(UINPUT_IOCTL_BASE, 106, int) > #define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int) > + > +/* DEPRECATED: Data size is ambiguous. Use UI_SET_PHYS_STR instead. */ > #define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*) > + > #define UI_SET_SWBIT _IOW(UINPUT_IOCTL_BASE, 109, int) > #define UI_SET_PROPBIT _IOW(UINPUT_IOCTL_BASE, 110, int) > +#define UI_SET_PHYS_STR(len) _IOC(_IOC_WRITE, UINPUT_IOCTL_BASE, 111, len) > +#define UI_SET_UNIQ_STR(len) _IOC(_IOC_WRITE, UINPUT_IOCTL_BASE, 112, len) > > #define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload) > #define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload) > -- > 2.24.0.393.g34dc348eaf-goog > -- Dmitry