Skip to content

Conversation

@jsynacek
Copy link
Contributor

@jsynacek jsynacek commented Jan 2, 2017

Easily reproducible:

  1. systemctl mask foo
  2. systemctl unmask foo foo

The problem here is that the *i that is put into todo[] is later freed
in strv_uniq(), which is not directly visible from this patch. Somewhere
further in the code, the string that *i pointed to is freed again. That
happens only when multiple services with the same name/path are specified.

On my system, the memory corruption revealed itself a lot later in the
program, which resulted in backtraces that were pretty much misleading
and useless.

Easily reproducible:
1) systemctl mask foo
2) systemctl unmask foo foo

The problem here is that the *i that is put into todo[] is later freed
in strv_uniq(), which is not directly visible from this patch. Somewhere
further in the code, the string that *i pointed to is freed again. That
happens only when multiple services with the same name/path are specified.

On my system, the memory corruption revealed itself a lot later in the
program, which resulted in backtraces that were pretty much misleading
and useless.
@evverx evverx added bug 🐛 Programming errors, that need preferential fixing pid1 labels Jan 2, 2017
@evverx
Copy link
Contributor

evverx commented Jan 2, 2017

BTW: there is another double free:

touch hola.service
systemctl link $(pwd)/hola.service $(pwd)/hola.service

https://gist.github.com/evverx/d06954ba17cf54c08cbb28b462b9495e#file-link-double-free-md

I didn't check other install operations

@martinpitt
Copy link
Contributor

While not complete yet, this looks correct, so the other double-free that @evverx found can be fixed in a separate PR. Thanks!

return -ENOMEM;

todo[n_todo++] = *i;
todo[n_todo++] = strdup(*i);
Copy link
Contributor

Choose a reason for hiding this comment

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

we should check if (!todo[n_todo-1]) return -ENOMEM

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in d054eae

whot pushed a commit to whot/systemd that referenced this pull request Oct 10, 2017
Easily reproducible:
1) systemctl mask foo
2) systemctl unmask foo foo

The problem here is that the *i that is put into todo[] is later freed
in strv_uniq(), which is not directly visible from this patch. Somewhere
further in the code, the string that *i pointed to is freed again. That
happens only when multiple services with the same name/path are specified.

(cherry picked from commit dc7dd61)
Resolves: #1409997
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 Programming errors, that need preferential fixing pid1

Development

Successfully merging this pull request may close these issues.

3 participants