Skip to content

udev-rules: fix matching of token types that support alternative patterns#26886

Merged
yuwata merged 3 commits intosystemd:mainfrom
ldv-alt:udevadm-verify
Mar 20, 2023
Merged

udev-rules: fix matching of token types that support alternative patterns#26886
yuwata merged 3 commits intosystemd:mainfrom
ldv-alt:udevadm-verify

Conversation

@ldv-alt
Copy link
Contributor

@ldv-alt ldv-alt commented Mar 19, 2023

For those token types that support matching of alternative patterns,
their token values are interpreted as nulstr, so make sure the parser
does the right thing and makes these token values terminated by two
subsequent NULs so they could be safely interpreted as nulstr.

Before this fix, the following rules would result to "echo foo" invocation:

  ENV{foo}=", RUN"
  ENV{foo}=="bar", RUN+="echo foo"

because the value of ENV{foo} is treated as nulstr, and it used to match
against alternative patterns, in this case bar, , RUN, and ="echo foo.

@github-actions github-actions bot added tests udev util-lib please-review PR is ready for (re-)review by a maintainer labels Mar 19, 2023
@github-advanced-security

This comment was marked as off-topic.

@ldv-alt ldv-alt changed the title udev-rules: fix matching of token types that support alternative pattern udev-rules: fix matching of token types that support alternative patterns Mar 19, 2023
@yuwata
Copy link
Member

yuwata commented Mar 19, 2023

Before this fix, the following rules would result to "echo foo" invocation:

ENV{foo}=", RUN"
ENV{foo}=="bar", RUN+="echo foo"

How the example was parsed previously?
Could you extend the commit message?

@ldv-alt
Copy link
Contributor Author

ldv-alt commented Mar 19, 2023

Before this fix, the following rules would result to "echo foo" invocation:
ENV{foo}=", RUN"
ENV{foo}=="bar", RUN+="echo foo"

How the example was parsed previously? Could you extend the commit message?

The value of ENV{foo} is treated as nulstr, and it was matching against alternative patterns, in this case bar, , RUN, and ="echo foo.

@yuwata
Copy link
Member

yuwata commented Mar 19, 2023

Before this fix, the following rules would result to "echo foo" invocation:
ENV{foo}=", RUN"
ENV{foo}=="bar", RUN+="echo foo"

How the example was parsed previously? Could you extend the commit message?

The value of ENV{foo} is treated as nulstr, and it was matching against alternative patterns, in this case bar, , RUN, and ="echo foo.

Oh,,, terrible...

Copy link
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But please extend the commit message of the first commit.

@yuwata yuwata added good-to-merge/with-minor-suggestions and removed please-review PR is ready for (re-)review by a maintainer labels Mar 19, 2023
ldv-alt added 3 commits March 19, 2023 11:32
…erns

For those token types that support matching of alternative patterns,
their token values are interpreted as nulstr, so make sure the parser
does the right thing and makes these token values terminated by two
subsequent NULs so they could be safely interpreted as nulstr.

Before this fix, the following rules would result to "echo foo" invocation:
  ENV{foo}=", RUN"
  ENV{foo}=="bar", RUN+="echo foo"
because the value of `ENV{foo}` is treated as nulstr, and it used to match
against alternative patterns, in this case `bar`, `, RUN`, and `="echo foo`.

Fixes: 25de7aa ("udev: modernize udev-rules.c")
This reverts commit cd3c8a1 which was
papering over the bug instead of a proper fix made by the previous
commit.
Fix check for conflicting and duplicate expressions of types that
support alternative patterns.

Fixes: 3ec58d0 ("udev-rules: check for conflicting and duplicate expressions")
@ldv-alt
Copy link
Contributor Author

ldv-alt commented Mar 19, 2023

LGTM. But please extend the commit message of the first commit.

Done, please take a look.

@yuwata
Copy link
Member

yuwata commented Mar 19, 2023

From the commit message:

in this case bar, , RUN, and +="echo foo.

Maybe, "+" is mistakenly inserted?

@ldv-alt
Copy link
Contributor Author

ldv-alt commented Mar 19, 2023

btw, this might obsolete commit cd3c8a1 which seems to paper over this bug.

@yuwata
Copy link
Member

yuwata commented Mar 19, 2023

btw, this might obsolete commit cd3c8a1 which seems to paper over this bug.

Indeed. Yeah, I agree. Feel free to revert it.

@ldv-alt
Copy link
Contributor Author

ldv-alt commented Mar 19, 2023

From the commit message:

in this case bar, , RUN, and +="echo foo.

Maybe, "+" is mistakenly inserted?

It was a typo, fixed, thanks!

@ldv-alt
Copy link
Contributor Author

ldv-alt commented Mar 19, 2023

btw, this might obsolete commit cd3c8a1 which seems to paper over this bug.

Indeed. Yeah, I agree. Feel free to revert it.

Added a revert commit to this series.

Copy link
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

@yuwata yuwata added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels Mar 19, 2023
@yuwata yuwata merged commit a9b402e into systemd:main Mar 20, 2023
@github-actions github-actions bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Mar 20, 2023
@keszybz
Copy link
Member

keszybz commented Mar 28, 2023

The first two commits backported to v253-stable. I assume the last one is not needed.

@mbiebl
Copy link
Contributor

mbiebl commented Jul 15, 2023

This seems to have caused a regression, see
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1040956

@ldv-alt can you please take a look?

@yuwata yuwata mentioned this pull request Jul 15, 2023
@yuwata
Copy link
Member

yuwata commented Jul 15, 2023

@mbiebl Filed as #28411. Please open a new issue instead of commenting on an already merged PR, otherwise we can easily forget the comment.

@mbiebl
Copy link
Contributor

mbiebl commented Jul 15, 2023

Thanks @yuwata .
Wasn't entirely sure yet, whether it is really a regression or a deliberate change in behaviour which is why I wanted to ask first.

@yuwata
Copy link
Member

yuwata commented Jul 15, 2023

Even if you are not sure, opening issue is fine. Especially, when the issue is in such a core part of systemd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants