All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wilken Gottwalt <wilken.gottwalt@posteo.net>
To: Aleksandr Mezin <mezin.alexander@gmail.com>
Cc: Guenter Roeck <linux@roeck-us.net>,
	Marius Zachmann <mail@mariuszachmann.de>,
	linux-hwmon@vger.kernel.org
Subject: Re: corsair-cpro and hidraw
Date: Fri, 18 Jun 2021 05:45:00 +0000	[thread overview]
Message-ID: <20210618074500.7215532b@monster.powergraphx.local> (raw)
In-Reply-To: <CADnvcf+W0fLJ8Yh-=dktVR63TXECNKtk5BvUfCBxazkLTw1N6g@mail.gmail.com>

On Fri, 18 Jun 2021 05:56:29 +0600
Aleksandr Mezin <mezin.alexander@gmail.com> wrote:

> I've looked through corsair-psu sources, and I think filtering in
> raw_event won't be enough.
> 
> For example, in corsairpsu_request, there are 2 commands, and they
> should be executed consecutively:
> 1) corsairpsu_usb_cmd(priv, 2, PSU_CMD_SELECT_RAIL, rail, NULL);
> 2) corsairpsu_usb_cmd(priv, 3, cmd, 0, data);
> 
> If the userspace will squeeze another PSU_CMD_SELECT_RAIL between (1)
> and (2), the driver will get data for a wrong rail (and with the
> current code won't even notice it).
> 
> So unless there is a way to "lock" hidraw (and it seems that there
> isn't - looking at the code, hidraw calls the low-level hid driver
> directly, as far as I understand), it won't work correctly.
> 
> And if a driver can't work correctly with hidraw enabled - maybe it
> shouldn't enable hidraw? So that the user can 1) notice that something
> is wrong 2) blacklist or unbind the driver (or userspace tools that
> use hidraw can unbind automatically). Otherwise everything seems to be
> silently broken.
> 
> On the other hand, maybe races between the kernel driver and userspace
> tools are unlikely, because the driver doesn't talk to the device
> continuously - only when sysfs reads happen.

I never noticed any issues of that kind. I actually did quite a lot of
userspace testing. A result of this a userspace tool you can find here:
https://github.com/wgottwalt/corsair-psu/tree/main/tools/rmi-hxi-query

Though, if you find a way to trigger such a race condition I have no
problem to remove the hidraw part.

greetings
Will

> Added corsair-psu maintainer to Cc:
> 
> On Thu, Jun 17, 2021 at 7:14 PM Guenter Roeck <linux@roeck-us.net> wrote:
> >
> > On Thu, Jun 17, 2021 at 01:11:38PM +0600, Aleksandr Mezin wrote:
> > > On Thu, Jun 17, 2021 at 12:27 PM Marius Zachmann <mail@mariuszachmann.de> wrote:
> > > ...
> > > > I do not know, what your device is doing
> > >
> > > Actually, NZXT devices (at least grid/"smart device" and "smart device
> > > v2"/rgb&fan controller) don't have such issues - they use report ids,
> > > and don't even expect request-reply communication pattern. I've just
> > > noticed that something seems to be wrong with corsair-cpro (but
> > > somehow didn't notice the comment) and decided to ask.
> > >
> > > > This device uses an echo of the command
> > > > in the answer and if they don't match it returns an error. This could
> > > > maybe lead to a false error when the replies are switched, but is
> > > > probably preferable.
> > >
> > > Hm... If the response includes the id of the request, it should be
> > > possible to filter reports in raw_event, i. e. don't signal completion
> > > if the report doesn't match, and wait more. Yes, there is a corner
> > > case, "if a command is not supported, the length value in the reply is
> > > okay, but the command value is set to 0". But timing out (250 ms) in
> > > this case should probably be fine... Actually I have a compatible
> > > Corsair PSU so maybe I'll send a patch.
> >
> > Patches to improve the situation are welcome. My understanding is
> > that with the current driver users should disable the kernel driver
> > if they plan to use userspace tools to access the device.
> >
> > Guenter


  reply	other threads:[~2021-06-18  5:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-17  3:11 corsair-cpro and hidraw Aleksandr Mezin
2021-06-17  4:33 ` Aleksandr Mezin
2021-06-17  6:27 ` Marius Zachmann
2021-06-17  7:11   ` Aleksandr Mezin
2021-06-17 13:14     ` Guenter Roeck
2021-06-17 23:56       ` Aleksandr Mezin
2021-06-18  5:45         ` Wilken Gottwalt [this message]
2021-06-18  6:18           ` Marius Zachmann
2021-06-18  6:47             ` Wilken Gottwalt
2021-06-18  7:06               ` Marius Zachmann
2021-06-18 12:13                 ` Guenter Roeck
2021-06-18 12:22                   ` Marius Zachmann
2021-06-18 19:41                     ` Guenter Roeck
2021-06-18 12:10               ` Guenter Roeck

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=20210618074500.7215532b@monster.powergraphx.local \
    --to=wilken.gottwalt@posteo.net \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mail@mariuszachmann.de \
    --cc=mezin.alexander@gmail.com \
    /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.