Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2637848ybh; Mon, 9 Mar 2020 09:52:16 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt1U7L1vLcowVsRVYCUP6c/adK4NZCz/0Qv7N1l+Douex+0sR34gKt64QCCUhoLo80RjrCB X-Received: by 2002:aca:c488:: with SMTP id u130mr169135oif.154.1583772736365; Mon, 09 Mar 2020 09:52:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583772736; cv=none; d=google.com; s=arc-20160816; b=eTKXC8SEnzxS1AQA/cTWImkbJEidJe45hlYp7cS1vtH4GEtu7nwVTJPYpuxf3XZGMG DsjvPUJdfgKpZihj0uwbvkyZgBgBbasUEGD84TwrNej0cAbqgnZ2cpKsXV2ZN+hyclww UWOresfgoj8vrwhWJcKj+4lsord06RDyC/fubypbHJTQSFcKg2Nox0ihOwt5FYUtgeSU DDr44A83rbn1BMsuMK95XQzAPCeqLMaPv0zFm1ED/D8BUtwr5p0ROMjSiE5WXhFNMXQb CVg3UDwWFVwJa/si0wETES7+465/45T2x7Mv+IhBwJJZi4F3N16NvB4dCtzaN5Da77wP qK+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=xHZH9VPoV7Aw9k1SYgU1P5fuT1bpUuCxKis+NgkeAi4=; b=XYVeSe7ojmZ/ebvwNs4xeHij6jxUrMrlK30+9kM3EUwgzQrhwqwAgd62JbEeVAwNMV REw5BcRea52zqM+kjGdIyib0ATAyYtWLoU56BE/BnTxD1zM+IplCyAiFrvLCHTw17d8M QDbpQm5BsZv+e2YPACPdm737GUS/NgLSMinYQ+01ao7xuBBj1drqD+lGus4d7yU6S354 mYwGBAKb3nuNKLhkFdolQ1d9uF2oeWM89j35vhC1XvdhKAiiCGihfVblkUHN5IhGyfuC 6YVFhvDwXEuvRB7RDtWy9GEY5PilvhECX2MJxWlFe7ZRc6xae1/IW3w0U9l0uAVpv8wo Ze1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SAQB+ReX; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l14si6160446otn.157.2020.03.09.09.52.04; Mon, 09 Mar 2020 09:52:16 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=SAQB+ReX; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727194AbgCIQvc (ORCPT + 99 others); Mon, 9 Mar 2020 12:51:32 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43869 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726922AbgCIQvc (ORCPT ); Mon, 9 Mar 2020 12:51:32 -0400 Received: by mail-pf1-f195.google.com with SMTP id c144so5066918pfb.10 for ; Mon, 09 Mar 2020 09:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xHZH9VPoV7Aw9k1SYgU1P5fuT1bpUuCxKis+NgkeAi4=; b=SAQB+ReXBf03G48PPlwT/2/hiTQS/zA919hfI+DABNqfxCBHhfS2gaRAnqvf2zBCfK k3lgQldAhd1zjiz42r44pfx/dTYu2E/TXw63gXqHKNqavk3qPITmhxdbPQPyI+I6xjfI uuL9ycD/ULdCCi5f884HNw089C2R3zOlMiMPpN1rlgiUoE+KRIUBFrSJo38SFGnbFnhF J3+auI54wolvsaQ8TeS4lJaFYJe7tSf1g1TCvuhusdAAWV9f+UmZmoDMfomHacIODQi0 mN9WUhn7T/TRBykNv9iU33nVwZtL/kWKJ54E0c1PkBf4LRQbv86unsPLE9cBqXp2D7WE xO+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xHZH9VPoV7Aw9k1SYgU1P5fuT1bpUuCxKis+NgkeAi4=; b=LtKYOCn45yUISyd2Q5l4OteaeGMeFSCSbhWKweGF12bkh50lXJ8uQpZjTnyf1I9tHl nHWTttAR0+CeVniaAYljRYN9cc/P0Em91kVLu9eZBipMupIR4iOlcfA+uNPx4IHkbwNz pw0esdPx1znfYgF1JOI7OliGipskwygAKYcC7FXeMIOdrYl32m6HBHBjsh+aFET3UUJP I45e44EZAD1ZRLcNjPQX0Iq2Ky2+ljf1Mb1E+x+cq13t1xnM6Bxj7Wg6H+pjOGm8Oc5L /f8qjm2wdfpyoxcQY4GJ6sm2CEi2zQ8hV0kkDDylndGkK06e5UyLx+tuKFboDGFJMFxz 1Y/g== X-Gm-Message-State: ANhLgQ2tTtZkLW4AAo64a6BPVqid9pdfR2VG7puemoe6HuTgOgxu2gdc 2rQTteLkF6cDYoVK4O4xOMwQikznuQkMeTx3SGp0MD2ILAA= X-Received: by 2002:a63:b52:: with SMTP id a18mr17406821pgl.130.1583772690379; Mon, 09 Mar 2020 09:51:30 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrey Konovalov Date: Mon, 9 Mar 2020 17:51:19 +0100 Message-ID: Subject: Re: [PATCH v6 0/1] usb: gadget: add raw-gadget interface To: Felipe Balbi , Alan Stern , Greg Kroah-Hartman Cc: Jonathan Corbet , Dmitry Vyukov , Alexander Potapenko , Marco Elver , USB list , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 24, 2020 at 5:17 PM Andrey Konovalov wrote: > > On Mon, Feb 24, 2020 at 5:13 PM Andrey Konovalov wrote: > > > > This patchset (currently a single patch) adds a new userspace interface > > for the USB Gadget subsystem called USB Raw Gadget. This is what is > > currently being used to enable coverage-guided USB fuzzing with syzkaller: > > > > https://github.com/google/syzkaller/blob/master/docs/linux/external_fuzzing_usb.md > > > > Initially I was using GadgetFS (together with the Dummy HCD/UDC module) > > to perform emulation of USB devices for fuzzing, but later switched to a > > custom written interface. The incentive to implement a different interface > > was to provide a somewhat raw and direct access to the USB Gadget layer > > for the userspace, where every USB request is passed to the userspace to > > get a response. See documentation for the list of differences between > > Raw Gadget and GadgetFS. > > > > Currently Raw Gadget only supports blocking I/O mode, that synchronously > > waits for the result of each operation to allow collecting coverage per > > operation. > > > > This patchset has been pushed to the public Linux kernel Gerrit instance: > > > > https://linux-review.googlesource.com/c/linux/kernel/git/torvalds/linux/+/2144 > > > > Changes v5 -> v6: > > - Prevent raw_process_ep_io() racing with raw_ioctl_ep_disable() by > > checking urb_queued flag in the latter. > > - Use GFP_KERNEL instead of GFP_ATOMIC where possible. > > - Reject opening raw-gadget with O_NONBLOCK to allow future extensions to > > support nonblocking IO. > > - Reduce RAW_EVENT_QUEUE_SIZE to 16. > > Hi Felipe! I'm still hoping for a review :) > > (Forgot to add a link to the example that emulates a USB keyboard via > Raw Gadget into the cover letter: > > https://github.com/xairy/raw-gadget/blob/master/examples/keyboard.c) Hi Greg, Felipe, and Alan, I was wondering if there's a way to move forward with this patch? Alan, since you have a very good knowledge of the USB subsystem, could I ask you to take a look at the patch, while Felipe is busy? Thanks! > > > > > Changes v4 -> v5: > > - Specified explicit usb_raw_event_type enum values for all entries. > > - Dropped pointless locking in gadget_unbind(). > > > > Changes v3 -> v4: > > - Print debug message when maxpacket check fails. > > - Use module_misc_device() instead of module_init/exit(). > > - Reuse DRIVER_NAME macro in raw_device struct definition. > > - Don't print WARNING in raw_release(). > > - Add comment that explains locking into raw_event_queue_fetch(). > > - Print a WARNING when event queue size is exceeded. > > - Rename raw.c to raw_gadget.c. > > - Mention module name in Kconfig. > > - Reworked logging to use dev_err/dbg() instead of pr_err/debug(). > > > > Changes v2 -> v3: > > - Updated device path in documentation. > > - Changed usb_raw_init struct layout to make it the same for 32 bit compat > > mode. > > - Added compat_ioctl to raw_fops. > > - Changed raw_ioctl_init() to return EINVAL for invalid USB speeds, except > > for USB_SPEED_UNKNOWN, which defaults to USB_SPEED_HIGH. > > - Reject endpoints with maxpacket = 0 in raw_ioctl_ep_enable(). > > > > Changes v1 -> v2: > > - Moved raw.c to legacy/. > > - Changed uapi header to use __u* types. > > - Switched from debugfs entry to a misc device. > > - Changed raw_dev from refcount to kref. > > - Moved UDC_NAME_LENGTH_MAX to uapi headers. > > - Used usb_endpoint_type() and usb_endpoint_dir_in/out() functions instead > > of open coding them. > > - Added "WITH Linux-syscall-note" to SPDX id in the uapi header. > > - Removed pr_err() if case dev_new() fails. > > - Reduced the number of debugging messages. > > > > Andrey Konovalov (1): > > usb: gadget: add raw-gadget interface > > > > Documentation/usb/index.rst | 1 + > > Documentation/usb/raw-gadget.rst | 61 ++ > > drivers/usb/gadget/legacy/Kconfig | 11 + > > drivers/usb/gadget/legacy/Makefile | 1 + > > drivers/usb/gadget/legacy/raw_gadget.c | 1078 ++++++++++++++++++++++++ > > include/uapi/linux/usb/raw_gadget.h | 167 ++++ > > 6 files changed, 1319 insertions(+) > > create mode 100644 Documentation/usb/raw-gadget.rst > > create mode 100644 drivers/usb/gadget/legacy/raw_gadget.c > > create mode 100644 include/uapi/linux/usb/raw_gadget.h > > > > -- > > 2.25.0.265.gbab2e86ba0-goog > >