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

deploy: Correctly use libmount unref() calls rather than free() #705

Closed
wants to merge 1 commit into from

Conversation

cgwalters
Copy link
Member

We saw a random ostree SEGV start popping up in our CI environment:
coreos/rpm-ostree#641 (comment)

Looking at this code more and comparing it to what util-linux does, I noticed we
had a write-after-free, since mnt_unref_table() will invoke
mnt_unref_cache() on its cache, and that function does:

	if (cache) {
		cache->rfcount--;

unconditionally.

Fix this by using unref().

We saw a random ostree SEGV start popping up in our CI environment:
coreos/rpm-ostree#641 (comment)

Looking at this code more and comparing it to what util-linux does, I noticed we
had a write-after-free, since `mnt_unref_table()` will invoke
`mnt_unref_cache()` on its cache, and that function does:

```
	if (cache) {
		cache->rfcount--;
```

unconditionally.

Fix this by using `unref()`.
@cgwalters
Copy link
Member Author

Though, perhaps based on #704 and #706 what we should really do is just revert 32d4369 for now?

@cgwalters
Copy link
Member Author

Eh, it's probably safest to just go with this - a revert would be messy and less obviously safe.

@jlebon
Copy link
Member

jlebon commented Feb 23, 2017

Yeah, had no luck at all reproducing coreos/rpm-ostree#641 (comment) locally. In re. to reverting 32d4369, we don't want to break people's setups if they started relying on it. So I'm +1 on just getting this in.

@rh-atomic-bot r+ 4c3ef23

@rh-atomic-bot
Copy link

⌛ Testing commit 4c3ef23 with merge 0817be6...

@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: jlebon
Pushing 0817be6 to master...

cgwalters added a commit to cgwalters/rpm-ostree that referenced this pull request Feb 23, 2017
cgwalters added a commit to cgwalters/rpm-ostree that referenced this pull request Feb 23, 2017
rh-atomic-bot pushed a commit to coreos/rpm-ostree that referenced this pull request Feb 23, 2017
cgwalters added a commit to cgwalters/ostree that referenced this pull request Feb 24, 2017
ostreedev#705 broke the build
on CentOS 7 which only has util-linux 2.23.

When I was thinking about this, I realized that there must really be a way to
make this safe even for older versions. Looking at that version of util-linux,
all we need to do is invert the order of frees so we `mnt_free_table()` *before*
`mnt_free_cache()`, like util-linux does:

https://github.com/karelzak/util-linux/blob/stable/v2.23/sys-utils/eject.c#L1131

We still use the `_unref()` versions if available.  I also fixed
the ordering there too for double plus redundant safety.
rh-atomic-bot pushed a commit that referenced this pull request Feb 24, 2017
#705 broke the build
on CentOS 7 which only has util-linux 2.23.

When I was thinking about this, I realized that there must really be a way to
make this safe even for older versions. Looking at that version of util-linux,
all we need to do is invert the order of frees so we `mnt_free_table()` *before*
`mnt_free_cache()`, like util-linux does:

https://github.com/karelzak/util-linux/blob/stable/v2.23/sys-utils/eject.c#L1131

We still use the `_unref()` versions if available.  I also fixed
the ordering there too for double plus redundant safety.

Closes: #712
Approved by: jlebon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants