Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

udevadm verify: add more checks #26980

Merged
merged 8 commits into from Mar 28, 2023
Merged

udevadm verify: add more checks #26980

merged 8 commits into from Mar 28, 2023

Conversation

ldv-alt
Copy link
Contributor

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

  • extend the check for conflicting expressions
  • check token delimiters

@github-actions github-actions bot added tests udev please-review PR is ready for (re-)review by a maintainer labels Mar 25, 2023
@yuwata yuwata added the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Mar 25, 2023
@yuwata
Copy link
Member

yuwata commented Mar 25, 2023

2023-03-25T00:45:22.7436907Z  424/1519 systemd:dist-check / udev-rules-check                                                   FAIL             0.01s   exit status 1
2023-03-25T00:45:22.7531626Z ――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――
2023-03-25T00:45:22.7531907Z stdout:
2023-03-25T00:45:22.7532016Z 
2023-03-25T00:45:22.7532124Z 34 udev rules files have been checked.
2023-03-25T00:45:22.7532345Z   Success: 33
2023-03-25T00:45:22.7532534Z   Fail:    1
2023-03-25T00:45:22.7532707Z stderr:
2023-03-25T00:45:22.7533083Z rules.d/60-persistent-storage.rules:45 No whitespace after comma
2023-03-25T00:45:22.7533479Z rules.d/60-persistent-storage.rules:55 No whitespace after comma
2023-03-25T00:45:22.7533869Z rules.d/60-persistent-storage.rules: udev rules check failed

The failures are caused by c5ba7a2, maybe missing space before the line continuation?

src/udev/fuzz-udev-rules.c Outdated Show resolved Hide resolved
src/udev/udev-rules.c Outdated Show resolved Hide resolved
src/udev/udevadm-verify.c Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Mar 25, 2023
@ldv-alt
Copy link
Contributor Author

ldv-alt commented Mar 25, 2023

centos8 error nothing provides python3.11dist(iniconfig) needed by python3.11-pytest-7.2.0-1.el8.noarch is unrelated.

@ldv-alt
Copy link
Contributor Author

ldv-alt commented Mar 25, 2023

jammy-ppc64el errors are also unrelated:

TEST-29-PORTABLE:                   FAIL     (1212 s)
TEST-53-ISSUE-16347:                FAIL     (1202 s)
TEST-62-RESTRICT-IFACES:            FAIL     (1202 s)

src/udev/fuzz-udev-rules.c Outdated Show resolved Hide resolved
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. Several coding style comments.

src/udev/udev-rules.c Outdated Show resolved Hide resolved
src/udev/udev-rules.c Show resolved Hide resolved
src/udev/udev-rules.c Outdated Show resolved Hide resolved
src/udev/udev-rules.c Outdated Show resolved Hide resolved
src/udev/udev-rules.c Outdated Show resolved Hide resolved
src/udev/udev-rules.c Outdated Show resolved Hide resolved
src/udev/udev-rules.c Outdated Show resolved Hide resolved
src/udev/udev-rules.c Outdated Show resolved Hide resolved
@yuwata yuwata added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Mar 26, 2023
@github-actions github-actions bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Mar 26, 2023
@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 please-review PR is ready for (re-)review by a maintainer labels Mar 26, 2023
src/udev/udev-rules.c Outdated Show resolved Hide resolved
Copy link
Member

@keszybz keszybz left a comment

Choose a reason for hiding this comment

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

LGTM, two suggestions about wording.

test/units/testsuite-17.11.sh Show resolved Hide resolved
src/udev/udev-rules.c Outdated Show resolved Hide resolved
test/units/testsuite-17.11.sh Outdated Show resolved Hide resolved
@keszybz keszybz added good-to-merge/with-minor-suggestions and removed 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 labels Mar 27, 2023
Move udev_rules_parse_file() after udev_check_rule_line() as
the former us going to use the latter.
Move udev_check_rule_line() invocation from udev_rule_file_get_issues()
to udev_rules_parse_file(), invoke udev_check_rule_line() only when
udev_rules_parse_file() is called by udevadm verify.

Subsequent commits are going to perform more checks invoked from
udev_rules_parse_file().
When udev_rules_parse_file() is called by udevadm verify, issue warnings
about the following conditions in udev rules:
* the first token in the rule is preceded with a comma
* the last token in the rule is followed by a comma
* there is no comma between tokens
* there is no whitespace between tokens
* there is more than a single comma between tokens
* there is whitespace between a token and a comma
* there is no whitespace after comma
Log an error when a rule line contains the following kind of conflicting
match expressions:

  KEY=="foo*", KEY=="bar*"
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.

Still LGTM.

@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 27, 2023
@keszybz
Copy link
Member

keszybz commented Mar 27, 2023

LGTM too.

fix grammar

That's a bit too strong ;) It was grammatically correct, it was just a bit off semantically. But it's fine, let's merge this.

@yuwata yuwata merged commit 024ea9d into systemd:main Mar 28, 2023
41 of 47 checks passed
@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 28, 2023
@mwilck
Copy link
Contributor

mwilck commented May 22, 2023

I just received a multipath-tools PR for this. I have to say I'm irritated. This PR introduces new syntax restrictions to udev rules that didn't exist before, in particular the rule to add whitespace after a comma. The multipath-tools PR tries to enforce this rule for commas before a line continuation, where it's non-obvious to me that the readability of the rules is improved at all.

I have nothing against systemd improving the readability of its own rules files, and using a test tool for verifying the added syntax rules. But I find it questionable to enforce such additional restrictions on other projects without even mentioning that they are new.

Side note: I did a quick test and actually found that (contrary to what the man page says) the tokenizer doesn't even enforce a comma, as it uses the required closing quote of the "value" part of the token as token delimiter:

KERNEL=="sda"PROGRAM="/bin/echo no comma"

works (just a remark; I know that the man page demands the comma).

@keszybz
Copy link
Member

keszybz commented May 22, 2023

We're trying to make the rules as readable as possible for humans. The rules on what is actually accepted haven't changed. The changes that the verifier is suggesting should make the rules more readable.

That said, I think we could relax the check to accept a line continuation without a space. There is whitespace there, we just completely strip it off when consuming the continuation symbol.

@ldv-alt could we make the second patch in opensvc/multipath-tools#66 not necessary?

@mwilck
Copy link
Contributor

mwilck commented May 22, 2023

We're trying to make the rules as readable as possible for humans. The rules on what is actually accepted haven't changed. The changes that the verifier is suggesting should make the rules more readable.

Ok. I agree, of course, that human-readable rules are a good thing. But from the multipath-tools PR, it was neither obvious that this syntax verification was a new feature, nor that it was stricter than the parser itself, and mainly targeted at improving readability.

Also, past experience would at least make me suspect that a future change might actually change what the parser accepts. If that isn't the case, fine with me.

@ldv-alt
Copy link
Contributor Author

ldv-alt commented May 22, 2023

For the sake of completeness, here is the message I sent earlier to the mailing list:

As you probably know, udevd silently accepts much broader syntax, for
example, it doesn't need neither comma no whitespace between KEY=VALUE
expressions, and I doubt this will ever change in the future.

In contrast, `udevadm verify` is a tool that checks syntactic, semantic,
and style correctness of udev rules files.  It indeed expects whitespace
after a comma in udev rules - a style most of existing udev rules follow.

> Furthermore, there is actually whitespace after the comma in the code
> this patch changes, it just happens to be at the beginning of the
> following line, which your syntax check ignores.

When I saw the parser of udev rules used by udevd for the first time,
I was also surprised to find out that it discards all leading whitespace
regardless of line continuations.  As result, that whitespace is not
visible to the syntax check at all.  So yes, you are literally correct,
there is whitespace there, but most of existing udev rules add whitespace
between a comma and a backslash.

@ldv-alt
Copy link
Contributor Author

ldv-alt commented May 22, 2023

That said, I think we could relax the check to accept a line continuation without a space. There is whitespace there, we just completely strip it off when consuming the continuation symbol.

@ldv-alt could we make the second patch in opensvc/multipath-tools#66 not necessary?

@keszybz, I thought about this before. Unfortunately, this issue is not as obvious as it looks from the first glance.
For example, udevd parses

ACTION=="\
         remove", GOTO="end"

as an equivalent to

ACTION=="remove", GOTO="end"

Both line continuations and leading whitespace removal are processed by the parser before parsing the line itself,
so it cannot differentiate between the kind of line continuation that happens inside tokens and other kinds of line continuation.

I'd rather not step into these murky waters unnecessarily.

mwilck pushed a commit to openSUSE/multipath-tools that referenced this pull request May 24, 2023
Fix warnings reported by udevadm verify:

multipath/11-dm-mpath.rules:18 Whitespace after comma is expected.
...
multipath/11-dm-mpath.rules: udev rules check failed

Note (mwilck): technically, the syntax of the udev rules was correct;
they are parsed and executed by udev correctly, and this is unlikely
to change. But systemd has enabled stricter checks in "udevadm verify"
to ensure better readability of udev rules files
(systemd/systemd#26980). This commit
makes sure the multipath-tools rules comply with these checks.

Signed-off-by: Dmitry V. Levin <ldv@strace.io>
Reviewed-by: Martin Wilck <mwilck@suse.com>
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.

None yet

4 participants