Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(network-manager): ensure safe content of /tmp/dhclient."$ifname".…
…dhcpopts NetworkManager leaves state files behind in "/run/NetworkManager/devices". These files are in keyfile format (glib's GKeyFile API [1]). From the statefile, the dracut module writes a .dhcpopts file. And other users want to parse that file, for example anaconda ([2]). To be fair, anaconda seems to parse a different file, so I am a bit confused who uses this file how. In any case, it seems somebody might be tempted to execute this as a script. We need to write the .dhcpopts file in a format that is defined and easy to handle from a shell script. As already previously, this format is a bash script that sets certain variables. That means, to load the file, the user could execute it as bash script. But this is dangerous, as the file contains potentially untrusted data from the network. Optimally, users still don't trust the .dhcpopts file to be safe for executing! It would be better if users too try to parse the file instead of executing it. That is not trivial however because in face of special characters, as we use bash's `printf '%q'` to escape the values and parsing bash escaping is not trivial. Anyway, make sure we properly quote and handle the content so that also executing is safe. In the best case, there are no special characters that require escaping, and naive parsing can be done with `sed`. Otherwise, executing is now also supposed to be safe. In this case we parse DHCP options from the state file. They are themselves backslash escaped UTF-8 strings (C escape sequences), which then are stored via keyfile API. The properly parse them, we would first need to load the file with GKeyFile (which undoes one level of backslash escaping) and then use g_str_compress() (to undo the second level). We mimic that with shell. [1] https://github.com/rhinstaller/anaconda/blob/b3411d6780aa0d76ee1e81a38710ec05a2d1978b/dracut/fetch-kickstart-net.sh#L30 [2] https://developer.gnome.org/glib/stable/glib-Key-value-file-parser.html Signed-off-by: Thomas Haller <[email protected]>
- Loading branch information