All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: Allen Webb <allenwebb@google.com>
Cc: Kees Cook <keescook@chromium.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Lucas De Marchi <lucas.de.marchi@gmail.com>,
	Nick Alcock <nick.alcock@oracle.com>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-modules@vger.kernel.org" <linux-modules@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	stable@vger.kernel.org, kernel test robot <lkp@intel.com>,
	Adam Manzanares <a.manzanares@samsung.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	mcgrof@kernel.org
Subject: Re: [PATCH v9 02/10] rockchip-mailbox: Fix typo
Date: Mon, 9 Jan 2023 16:25:46 -0800	[thread overview]
Message-ID: <Y7ywiu1fAdrbsxt0@bombadil.infradead.org> (raw)
In-Reply-To: <CAJzde04UfPMTxiUaGjSYZBVMfcpVz1S9fTiGWYnCB0_yM0MaQw@mail.gmail.com>

On Tue, Dec 27, 2022 at 11:42:36AM -0600, Allen Webb wrote:
> On Tue, Dec 20, 2022 at 5:09 PM Luis Chamberlain <mcgrof@kernel.org> wrote:
> > I think it would make sense then to be explicit about this for now, even
> > if it seems we can obsolete this. Right now the justification for having
> > this for built-in is *very* specific to this feature for USB, which
> > makes use of special USB sysfs attributes which as you explained, allows
> > to restrict probe of devices even though the respective driver is already
> > loaded.
> 
> The thing we might obsolete is limiting it to just the USB subsystem.
> I am fine with expanding the documentation and limiting the scope of
> the feature to USB/thunderbolt for now.

Great let's do that as otherwise it can leave a few folks scratchign
their head.

> > > There are sysfs attributes called  authorized and authorized_default
> > > that together can prevent devices from being fully enumerated and
> > > probed.
> >
> > Although these attributes are USB specfic today it gets me wondering if
> > other subsystems may benefit from a similar feature.
> 
> The subsystems that would likely benefit the most are ones that are
> externally reachable. 

Makes sense.

> The external ports that come to mind are USB /
> thunderbolt, firewire, PCMCIA / expresscard, eSATA, serial and
> parallel ports. Supporting PCMCIA / expresscard seems like it would
> require adding the authorized sysfs attribute to pci. eSATA would be
> covered by ata.

Makes sense, I'd personally ignore anything legacy such as PCMCIA though.

> > > authorized_default gets set to 0 for the hub and any devices
> > > connected after that will show in sysfs, but not fully enumerate or
> > > probe until the device's authorized attribute is set to 1. There are
> > > some edge cases like internal devices which have some extra
> > > complexity.
> > >
> > > As for documentation, I wasn't able to find much other than:
> > > https://github.com/torvalds/linux/blob/v6.1/drivers/usb/core/hcd.c#L370
> > > /* authorized_default behaviour:
> > > * -1 is authorized for all devices except wireless (old behaviour)
> > > * 0 is unauthorized for all devices
> > > * 1 is authorized for all devices
> > > * 2 is authorized for internal devices
> > > */
> > > ...
> > > and
> > > https://github.com/torvalds/linux/blob/v6.1/Documentation/admin-guide/kernel-parameters.txt#L6424
> > > usbcore.authorized_default=
> > >    [USB] Default USB device authorization:
> > >    (default -1 = authorized except for wireless USB,
> > >    0 = not authorized, 1 = authorized, 2 = authorized
> > >    if device connected to internal port)
> > > ...
> > > The feature looks like it was originally introduced for wireless USB in:
> > > https://www.mail-archive.com/linux-usb-devel@lists.sourceforge.net/msg54289.html
> > > and later adapted for use cases like USBGuard here:
> > > https://github.com/torvalds/linux/commit/c4fc2342cb611f945fa468e742759e25984005ad
> >
> > Thanks for digging all this up. Can you extend the docs on
> > Documentation/driver-api/usb/ somewhere about this attribute as part of
> > your changes so its clear the motivation, *then* you make your changes.
> > The documentation for MODULE_DEVICE_TABLE() can just say:
> >
> > The only use-case for built-in drivers today is enable userspace to
> > prevent / allow probe for devices on certain subsystems even if the
> > driver is already loaded. An example is the USB subsystem with its
> > authorized_default sysfs attribute. For more details refer to the
> > kernel's Documentation for USB about authorized_default.
> >
> > That should be clear enough for both USB driver writers and others.
> >
> > Please also extend the docs for MODULE_DEVICE_TABLE() on
> > Documentation/driver-api/usb/writing_usb_driver.rst or where you see
> > fit for your changes. That can go into depth about the USBGuard stuff.
> >
> >   Luis
> 
> How do you feel about only having one version of the macro for both
> cases and merging the documentation so things are kept simple? Here is
> what I have locally for the macro without the ifdef and the updated
> documentation:
> 
> /*
>  * Creates an alias so file2alias.c can find device table.
>  *
>  * Use this in cases where a device table is used to match devices because it
>  * surfaces match-id based module aliases to userspace for:
>  *   - Automatic module loading through modules.alias.
>  *   - Tools like USBGuard which allow or block devices based on policy such as
                                 ^ allow to

>  *     which modules match a device.
>  *
>  * The only use-case for built-in drivers today is enable userspace to prevent /

                                                ^ is to

>  * allow probe for devices on certain subsystems even if the driver is already
>  * loaded. An example is the USB subsystem with its authorized_default sysfs
>  * attribute. For more details refer to the kernel's Documentation for USB about
>  * authorized_default.
>  *
>  * The module name is included in the alias for two reasons:
>  *   - It avoids creating two aliases with the same name for built-in modules.
>  *     Historically MODULE_DEVICE_TABLE was a no-op for built-in modules, so
>  *     there was nothing to stop different modules from having the same device
>  *     table name and consequently the same alias when building as a module.
>  *   - The module name is needed by files2alias.c to associate a particular
>  *     device table with its associated module for built-in modules since
>  *     files2alias would otherwise see the module name as `vmlinuz.o`.

Yeah sure this reads much better.

>  */
> #define MODULE_DEVICE_TABLE(type, name) \
> extern void *CONCATENATE( \
> CONCATENATE(__mod_##type##__##name##__, \
> __KBUILD_MODNAME), \
> _device_table) \
> __attribute__ ((unused, alias(__stringify(name))))
> 
> 
> Here is a draft version for an updated to
> Documentation/driver-api/usb/ (I will add the 80 char line breaks
> later) in case you have feedback:
> 
> 
> # Authorization
> 
> Authorization provides userspace a way to allow or block configuring
> devices early during enumeration before any modules are probed for the
> device. While it is possible to block a device by not loading the
> required modules, this also prevents other devices from using the
> module as well. For example someone might have an unattended computer
> downloading installation media to a USB drive. Presumably this
> computer would be locked to make it more difficult for a bad actor to
> access the computer. Since USB storage devices are not needed to
> interact with the lock screen, the authorized_default sysfs attribute
> can be set to not authorize new USB devices by default. A userspace
> tool like USBGuard can then vet the devices. Mice, keyboards, etc can
> be allowed by writing to their authorized sysfs attribute so that the
> lock screen can still be used (this important in cases like
> suspend+resume or docks) while other devices can be blocked as long as
> the lock screen is shown.
> 
> ## Sysfs Attributes
> 
> Userspace can control USB device authorization through the
> authorized_default and authorized sysfs attributes.
> 
> ### authorized_default
> 
> .. kernel-doc:: drivers/usb/core/hcd.c
>    :export:
> 
> The authorized_default sysfs attribute is only present for host
> controllers. It determines the initial state of the authorized sysfs
> attribute of USB devices newly connected to the corresponding host
> controller. It can take on the following values:
> 
> +---------------------------------------------------+
> | Value | Behavior                                  |
> +=======+===========================================+
> |    -1 | Authorize all devices except wireless USB |
> +-------+-------------------------------------------+
> |     0 | Do not authorize new devices              |
> +-------+-------------------------------------------+
> |     1 | Authorize new devices                     |
> +-------+-------------------------------------------+
> |     2 | Authorize new internal devices only       |
> +---------------------------------------------------+
> 
> Note that firmware platform code determines if a device is internal or
> not and this is reported as the connect_type sysfs attribute of the
> USB port. This is currently supported by ACPI, but device tree still
> needs an implementation. Authorizing new internal devices only can be
> useful to work around issues with devices that misbehave if there are
> delays in probing their module.
> 
> ### authorized
> 
> .. kernel-doc:: drivers/usb/core/sysfs.c
>    :export:
> 
> Every USB device has an authorized sysfs attribute which can take the
> values 0 and 1. When authorized is 0, the device still is present in
> sysfs, but none of its interfaces can be associated with drivers and
> modules will not be probed. When authorized is 1 (or set to one) a
> configuration is chosen for the device and its interfaces are
> registered allowing drivers to bind to them.

Good stuff!

  Luis

  reply	other threads:[~2023-01-10  0:26 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAJzde06+FXNpyBzT+NfS2GCfqEERMkGDpdsmHQj=v1foLJW4Cw@mail.gmail.com>
2022-11-29 22:43 ` [PATCH v3] modules: add modalias file to sysfs for modules Allen Webb
2022-11-30  7:06   ` Greg Kroah-Hartman
2022-11-30 22:14     ` [PATCH v4] " Allen Webb
2022-12-01  4:33       ` kernel test robot
2022-12-01  6:06       ` Greg Kroah-Hartman
2022-12-01  9:46       ` kernel test robot
2022-12-08  2:34   ` [PATCH v3] " Luis Chamberlain
2022-12-08 14:22     ` Allen Webb
2022-12-08 15:20       ` Greg Kroah-Hartman
2022-12-16 22:16         ` [PATCH v7 0/5] Generate modules.builtin.alias from match ids Allen Webb
2022-12-16 22:16           ` [PATCH v7 1/5] module.h: MODULE_DEVICE_TABLE for built-in modules Allen Webb
2022-12-17  3:49             ` kernel test robot
2022-12-17  3:59             ` kernel test robot
2022-12-17  4:50             ` kernel test robot
2022-12-17 10:05             ` Christophe Leroy
2022-12-19 15:56               ` Allen Webb
2022-12-16 22:17           ` [PATCH v7 2/5] modpost: Track module name " Allen Webb
2022-12-17 10:08             ` Christophe Leroy
2022-12-16 22:17           ` [PATCH v7 3/5] modpost: Add -b option for emitting built-in aliases Allen Webb
2022-12-17 10:10             ` Christophe Leroy
2022-12-16 22:17           ` [PATCH v7 4/5] file2alias.c: Implement builtin.alias generation Allen Webb
2022-12-17  0:47             ` kernel test robot
2022-12-17  3:09             ` kernel test robot
2022-12-17 10:13             ` Christophe Leroy
2022-12-16 22:17           ` [PATCH v7 5/5] build: Add modules.builtin.alias Allen Webb
2022-12-19 19:18           ` [PATCH v8 0/9] Generate modules.builtin.alias from match ids Allen Webb
2022-12-19 19:18             ` [PATCH v8 1/9] imx: Fix typo Allen Webb
2022-12-19 19:21               ` Greg Kroah-Hartman
2022-12-19 19:55                 ` Allen Webb
2022-12-19 19:18             ` [PATCH v8 2/9] rockchip-mailbox: " Allen Webb
2022-12-19 19:18             ` [PATCH v8 3/9] scsi/BusLogic: Always include device id table Allen Webb
2022-12-19 19:18             ` [PATCH v8 4/9] stmpe-spi: Fix typo Allen Webb
2022-12-19 19:18             ` [PATCH v8 5/9] module.h: MODULE_DEVICE_TABLE for built-in modules Allen Webb
2022-12-19 19:18             ` [PATCH v8 6/9] modpost: Track module name " Allen Webb
2022-12-19 19:18             ` [PATCH v8 7/9] modpost: Add -b option for emitting built-in aliases Allen Webb
2022-12-19 19:18             ` [PATCH v8 8/9] file2alias.c: Implement builtin.alias generation Allen Webb
2022-12-19 19:18             ` [PATCH v8 9/9] build: Add modules.builtin.alias Allen Webb
2022-12-19 20:06             ` [PATCH v8 0/9] Generate modules.builtin.alias from match ids Luis Chamberlain
2022-12-19 20:42               ` Allen Webb
2022-12-19 20:46             ` [PATCH v9 00/10] " Allen Webb
2022-12-19 20:46               ` [PATCH v9 01/10] imx: Fix typo Allen Webb
2022-12-19 21:23                 ` Luis Chamberlain
2022-12-20  6:42                 ` Greg Kroah-Hartman
2022-12-20 14:26                   ` Allen Webb
2022-12-20 14:32                     ` Greg Kroah-Hartman
2022-12-20 14:45                       ` Allen Webb
2022-12-19 20:46               ` [PATCH v9 02/10] rockchip-mailbox: " Allen Webb
2022-12-20  6:46                 ` Greg Kroah-Hartman
2022-12-20 14:58                   ` Allen Webb
2022-12-20 18:12                     ` Luis Chamberlain
2022-12-20 18:19                       ` Allen Webb
2022-12-20 18:47                         ` Luis Chamberlain
2022-12-20 19:49                           ` Allen Webb
2022-12-20 20:03                             ` Luis Chamberlain
2022-12-20 21:57                               ` Allen Webb
2022-12-20 23:09                                 ` Luis Chamberlain
2022-12-27 17:42                                   ` Allen Webb
2023-01-10  0:25                                     ` Luis Chamberlain [this message]
2023-01-09 11:54                           ` Nick Alcock
2023-01-10 18:20                             ` Allen Webb
2022-12-19 20:46               ` [PATCH v9 03/10] scsi/BusLogic: Always include device id table Allen Webb
2022-12-19 20:46               ` [PATCH v9 04/10] stmpe-spi: Fix typo Allen Webb
2022-12-19 20:46               ` [PATCH v9 05/10] module.h: MODULE_DEVICE_TABLE for built-in modules Allen Webb
2022-12-20  6:45                 ` Greg Kroah-Hartman
2022-12-20 16:36                   ` Allen Webb
2022-12-19 20:46               ` [PATCH v9 06/10] modpost: Track module name " Allen Webb
2022-12-19 20:46               ` [PATCH v9 07/10] modpost: Add -b option for emitting built-in aliases Allen Webb
2022-12-20  6:43                 ` Greg Kroah-Hartman
2022-12-20 17:32                   ` Allen Webb
2022-12-19 20:46               ` [PATCH v9 08/10] file2alias.c: Implement builtin.alias generation Allen Webb
2022-12-19 20:46               ` [PATCH v9 09/10] build: Add modules.builtin.alias Allen Webb
2022-12-19 20:46               ` [PATCH v9 10/10] docs: Include modules.builtin.alias Allen Webb
2022-12-19 20:49                 ` Allen Webb
2022-12-19 21:23                 ` Luis Chamberlain
2022-12-19 21:40                   ` Allen Webb
2022-12-19 22:07                     ` Luis Chamberlain
2022-12-19 22:20                       ` Allen Webb
2022-12-19 22:51                         ` Luis Chamberlain
2022-12-19 20:46               ` [PATCH v9 10/10] Documentation: " Allen Webb
2023-04-06 19:00               ` [PATCH v10 00/11] Generate modules.builtin.alias from match ids Allen Webb
2023-04-06 19:00                 ` [PATCH v10 01/11] rockchip-mailbox: Remove unneeded MODULE_DEVICE_TABLE Allen Webb
2023-04-06 19:00                 ` [PATCH v10 02/11] scsi/BusLogic: Always include device id table Allen Webb
2023-04-06 19:00                 ` [PATCH v10 03/11] stmpe-spi: Fix MODULE_DEVICE_TABLE entries Allen Webb
2023-05-24  6:52                   ` Luis Chamberlain
2023-05-24  6:52                   ` Luis Chamberlain
2023-04-06 19:00                 ` [PATCH v10 04/11] module.h: MODULE_DEVICE_TABLE for built-in modules Allen Webb
2023-05-24  6:44                   ` Luis Chamberlain
2023-04-06 19:00                 ` [PATCH v10 05/11] modpost: Track module name " Allen Webb
2023-04-20  9:47                   ` Greg KH
2023-05-24  6:50                   ` Luis Chamberlain
2023-04-06 19:00                 ` [PATCH v10 06/11] modpost: Add -b option for emitting built-in aliases Allen Webb
2023-05-24  6:54                   ` Luis Chamberlain
2023-04-06 19:00                 ` [PATCH v10 07/11] file2alias.c: Implement builtin.alias generation Allen Webb
2023-05-24  7:00                   ` Luis Chamberlain
2023-04-06 19:00                 ` [PATCH v10 08/11] build: Add modules.builtin.alias Allen Webb
2023-05-24  7:02                   ` Luis Chamberlain
2023-07-19 19:51                     ` Allen Webb
2023-07-26 18:30                       ` Luis Chamberlain
2023-04-06 19:00                 ` [PATCH v10 09/11] Documentation: Include modules.builtin.alias Allen Webb
2023-04-06 19:00                 ` [PATCH v10 10/11] Documentation: Update writing_usb_driver for built-in modules Allen Webb
2023-04-06 19:00                 ` [PATCH v10 11/11] Documentation: add USB authorization document to driver-api Allen Webb
2023-04-20  9:51                   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y7ywiu1fAdrbsxt0@bombadil.infradead.org \
    --to=mcgrof@kernel.org \
    --cc=a.manzanares@samsung.com \
    --cc=allenwebb@google.com \
    --cc=dave@stgolabs.net \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=lucas.de.marchi@gmail.com \
    --cc=masahiroy@kernel.org \
    --cc=nick.alcock@oracle.com \
    --cc=rafael@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.