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

Fix sinfoCmp to order signatures correctly #3194

Closed
wants to merge 2 commits into from

Conversation

ffesti
Copy link
Contributor

@ffesti ffesti commented Jul 4, 2024

This requires adjusting a number of test that reflect the ordering. The changes in tests/rpmsigdig.at look straight forward and correct - just changing the order in which the signatures and checksums are presented.

The changes in tests/rpmi.at seem to drop the relevant information. This might be accidental as the code just returns the first issue found. But "no signature" seems kinda weird result when before it complaint about a specific signature. May be someone with more clue about this should ahve a second look before merging.

Resolves: #3185,#1057

@ffesti ffesti added bug DONT DO NOT merge, for whatever reason labels Jul 4, 2024
This requires adjusting a number of test that reflect the ordering. The
changes in tests/rpmsigdig.at look straight forward and correct - just
changing the order in which the signatures and checksums are presented.

The changes in tests/rpmi.at seem to drop the relevant information. This
might be accidental as the code just returns the first issue found. But
"no signature" seems kinda weird result when before it complaint about a
specific signature. The next patch tries to fix that.

Resolves: rpm-software-management#3185
@ffesti ffesti removed the DONT DO NOT merge, for whatever reason label Jul 19, 2024
@ffesti
Copy link
Contributor Author

ffesti commented Jul 19, 2024

Ok, now the error reporting is better. It probably still should use the most secure hash / signature that is broken but at least it will no longer report "no signature"

vd->type[sinfo->type] = sinfo->rc;
for (int type=0; type < 3; type++) {
if (type != sinfo->type && vd->type[type] >= sinfo->rc)
return 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

We will still fall through (to the switch below and thus potentially replace the error message) if the current error in sinfo->rc is the same or lower than what we have stored for this type so far.

vd->type[sinfo->type] = res;
if (sinfo->rc > vd->type[sinfo->type]) {
vd->type[sinfo->type] = sinfo->rc;
for (int type=0; type < 3; type++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just use sizeof(vd->type) here?

Don't rely on the fist issue found being the most meaningful. Always
return 1 to loop through all signatures / hashes. Use the first error of
the highest severity.

Using the severity in vd->type[] is a bit of a hack but OK as it is only
checked for == RPMRC_OK (aka 0) in verifyPackageFiles.

Related: rpm-software-management#3185
@ffesti
Copy link
Contributor Author

ffesti commented Jul 26, 2024

OK, this was a bit more involved than the 2 line fix this originally looked like.

I kept the "Legacy compat" behavior in vfyCb the same: It keeps the actual check in rpmvsVerify passing while still issuing an error so that verified in verifyPackageFiles does not get set.

if (res > vd->type[sinfo->type])
vd->type[sinfo->type] = res;
if (severity > vd->type[sinfo->type]) {
vd->type[sinfo->type] = severity;
Copy link
Member

@pmatilai pmatilai Jul 30, 2024

Choose a reason for hiding this comment

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

Don't. Don't abuse a completely unrelated field when there's no reason to do so, just because you think you might get away with it. It only achieves making fairly complicated logic even more confusing and that's not what you want in security sensitive code. This is an internal struct, if you need a severity field then add it. And since it can then be used to aid sorting these items, maybe it'll all fall into place more naturally that way. For one, using a nicer data structure (now that we have plenty available) might make it all much saner.

This verification callback fubar was written under RHEL deadline pressure six years ago and isn't exactly one of my pridest moments...

Copy link
Member

Choose a reason for hiding this comment

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

Ehm, okay so vd->type is something entirely different (a field badly named by me), I first thought this was abusing the data contained in sinfo->type. This is more harmless but also there's nothing saved by avoiding an extra field for the purpose, this code is bad enough as it is 😆

@pmatilai
Copy link
Member

I wonder if there isn't a saner way to handle the legacy compat thing of allowing unsigned packages.
Especially going forward to a future where unsigned packages are only installable with --nosignature. It's not like we have to have this fixed in 4.20, it's been there six years already...

@pmatilai
Copy link
Member

pmatilai commented Jul 30, 2024

Other remarks found from the dusty archives while poking around this area in my head:

IIRC the reason the transaction verify reports the first issue found is that in that context, there's no point continuing. And so, you can just abort on the first error found. Or so the theory goes, clearly the existing code gets it wrong in the case of NOTFOUND encountered first which is more likely to happen with the sinfo sorting fixed. Makes me think the NOTFOUND handling is basically in the wrong place, the verify callback is not interested whether the signature is RSA or DSA or whatever, it just wants to know if there was a signature that we could verify. Which I think should really be hidden inside rpmvs. There's a Finnish idiom "juosten kustu", basically "peed while running" that seems appropriate for the existing signature callback mess - it's just the kind of thing you get when you're think you're in hurry and don't stop to think properly 😄 I do quite vividly remember thinking this is klunky as hell but it'll have to do for now...

@pmatilai
Copy link
Member

So ... maybe we're better off looking at this in the context of other signature changes coming for v6, and concentrate on those 4.20 matters just now instead.

@pmatilai
Copy link
Member

pmatilai commented Jul 30, 2024

Yet another thought: maybe what the existing code unintentionally does is not so bad: it basically fades out the phony "X is better than Y" comparison between RSA and (EC)DSA, which is particularly silly when only type will ever be present in a single package. Ie you just fix the hashalgo comparison and drop the sigalgo comparison entirely (although it'd warrant a comment), the test-suite still passes with zero modifications...

@ffesti
Copy link
Contributor Author

ffesti commented Aug 6, 2024

Closing this here and dropping the ticket back into the ToDo pile. This needs a fresh start and not use up more time befort the 4.20 release.

@ffesti ffesti closed this Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sb in lhs and rhs
3 participants