Page MenuHomeFreeBSD

MAC/do: Fix double-free on parse error after "executable paths" feature
ClosedPublic

Authored by olce on Mon, Jun 1, 9:08 AM.
Tags
None
Referenced Files
F159404620: D57376.id179050.diff
Sat, Jun 13, 7:14 PM
Unknown Object (File)
Sat, Jun 13, 4:02 AM
Unknown Object (File)
Mon, Jun 8, 7:38 AM
Unknown Object (File)
Mon, Jun 8, 7:27 AM
Unknown Object (File)
Mon, Jun 8, 3:30 AM
Unknown Object (File)
Mon, Jun 8, 3:21 AM
Unknown Object (File)
Sat, Jun 6, 4:15 PM
Unknown Object (File)
Sat, Jun 6, 4:11 PM
Subscribers
None

Details

Summary

parse_rules() has been calling toast_rules() in case of a parse error in
order to deallocate the 'struct rule' objects it has constructed up to
that point.

toast_rules() would take a pointer to a full 'struct rules' object, and
besides freeing all 'struct rule' referenced by it, would also free the
holding 'struct rules' itself.

With the introduction of the "executable paths" feature, and the
embedding of 'struct rules' into 'struct conf', meaning that the
lifecycle for 'struct rules' was no longer independent, toast_rules()
was changed not to free the passed 'struct rules' (as it was a field of
a 'struct conf' object). Unfortunately, this change was not completed
with a reinitialization of the rules list head, so the 'struct conf'
object would continue to reference just-freed rules, which then would be
freed a second time on destruction of that container.

So, make toast_rules() re-initialize the rules list in 'struct rules',
which it logically has been having to do since not freeing the enclosing
'struct rules'. This alone is enough to fix the bug, but let's use the
occasion to change the contract of parse_rules() and bring its herald
comment up-to-date: On error, parse_rules() now simply leaves already
constructed 'struct rule' objects in 'conf'. The latter is eventually
destroyed and the rule objects reclaimed at that point.

Reported by: impost0r(ret2plt) <impostor@ret2p.lt>
Fixes: 9818224174c4 ("MAC/do: Executable paths feature (GSoC 2025's final state)")
Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 73606
Build 70489: arc lint + arc unit

Event Timeline

olce held this revision as a draft.
olce published this revision for review.Mon, Jun 1, 9:10 AM
olce added reviewers: markj, secteam.
olce changed the visibility from "Public (No Login Required)" to "Subscribers".
olce edited subscribers, added: markj, secteam; removed: imp.

Is it possible to add a regression test?

This revision is now accepted and ready to land.Mon, Jun 1, 12:45 PM

Is it possible to add a regression test?

Sure, it's actually done already, I did it shortly after uploading this, forgot to update this revision.

olce removed a reviewer: cperciva.
olce changed the visibility from "Subscribers" to "Public (No Login Required)".
olce removed subscribers: cperciva, secteam, markj.

(Closing by hand, forgot to tag the commit properly.)

This revision is now accepted and ready to land.Mon, Jun 1, 3:32 PM

(Update to the diff that was committed.)

This revision now requires review to proceed.Mon, Jun 1, 3:32 PM
This revision is now accepted and ready to land.Mon, Jun 1, 3:33 PM