Linux Input Archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Jason Andryuk <jandryuk@gmail.com>
Cc: linux-input@vger.kernel.org, Hans de Goede <hdegoede@redhat.com>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	linux-kernel@vger.kernel.org,
	Peter Hutterer <peter.hutterer@who-t.net>
Subject: Re: [PATCH] Input: try trimming too long modalias strings
Date: Mon, 29 Apr 2024 15:01:54 -0700	[thread overview]
Message-ID: <ZjAY0uFxeglmMagh@google.com> (raw)
In-Reply-To: <CAKf6xpv76BO_n2VSAcbRfWowceXjiBSKHjx1nGakXzFHUiS6+Q@mail.gmail.com>

On Sun, Apr 28, 2024 at 07:43:52PM -0400, Jason Andryuk wrote:
> Hi Dmitry,
> 
> On Sat, Apr 27, 2024 at 10:06 PM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> >
> > If an input device declares too many capability bits then modalias
> > string for such device may become too long and not fit into uevent
> > buffer, resulting in failure of sending said uevent. This, in turn,
> > may prevent userspace from recognizing existence of such devices.
> >
> > This is typically not a concern for real hardware devices as they have
> > limited number of keys, but happen with synthetic devices such as
> > ones created by xen-kbdfront driver, which creates devices as being
> > capable of delivering all possible keys, since it doesn't know what
> > keys the backend may produce.
> >
> > To deal with such devices input core will attempt to trim key data,
> > in the hope that the rest of modalias string will fit in the given
> > buffer. When trimming key data it will indicate that it is not
> > complete by placing "+," sign, resulting in conversions like this:
> >
> > old: k71,72,73,74,78,7A,7B,7C,7D,8E,9E,A4,AD,E0,E1,E4,F8,174,
> > new: k71,72,73,74,78,7A,7B,7C,+,
> >
> > This should allow existing udev rules continue to work with existing
> > devices, and will also allow writing more complex rules that would
> > recognize trimmed modalias and check input device characteristics by
> > other means (for example by parsing KEY= data in uevent or parsing
> > input device sysfs attributes).
> 
> I think adding these links may be useful for cross referencing:
> [1] https://github.com/systemd/systemd/issues/22944
> [2] https://lore.kernel.org/xen-devel/87o8dw52jc.fsf@vps.thesusis.net/T/
> 
> > Reported-by: Jason Andryuk <jandryuk@gmail.com>
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
> Thank you for looking at this.  I think this idea of truncating the
> modalias is better than just dropping keys.
> 
> cat-ing the individual sysfs files works, but there is still an issue:
> 
> # sudo udevadm trigger --action=change
> [  601.379977] ------------[ cut here ]------------
> [  601.395959] add_uevent_var: buffer size too small
> [  601.412009] WARNING: CPU: 0 PID: 630 at lib/kobject_uevent.c:671
> add_uevent_var+0x11c/0x130

...

> Another path needs to truncate the buffer?  Or the problem is that the
> total uevent buffer size is what matters - not just the keys modalias?

Yes, exactly right - the driver core may add more environment variables,
such as SEQNUM=, HOME=, PATH=.

I created v2 of the patch that tries to leave some space at the end for
these additional variables.

> 
> My other thought is wondering whether the presence of '+' will cause
> parsing errors?  Has '+' been used before - or will it be an
> unexpected character?

I hope not. It is after "," and not a hex digit, so old code parsing
keys hopefully considers it as a separate part of modalias. I.e. it was
coping with:

	...-e0,1,2,4,k110,111,112,113,114,115,r0,1,8,...

so I believe it should cope with

	...-e0,1,2,4,k110,111,112,113,114,115,+,r0,1,8,...

But let's see Peter and Benjamin will say...

Thanks.

-- 
Dmitry

      reply	other threads:[~2024-04-29 22:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-28  2:06 [PATCH] Input: try trimming too long modalias strings Dmitry Torokhov
2024-04-28 23:43 ` Jason Andryuk
2024-04-29 22:01   ` Dmitry Torokhov [this message]

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=ZjAY0uFxeglmMagh@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=hdegoede@redhat.com \
    --cc=jandryuk@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.hutterer@who-t.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).