Skip to contentSkip to conversation

Revert "dns-hatchet: apply resolv.conf's selinux context to new resolv.conf"

PATCH In review Robert Frohl 3 participants 4 messages Jun 8 – Oct 5 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Revert "dns-hatchet: apply resolv.conf's selinux context to new resolv.conf"

This reverts commit 2ce4680bd34f371aacd3c09673c3c907274321cd.

selinux does not allow every domain to set file contexts and will raise relabelto/relabelfrom AVCs and block these changes if a domain tries to update the selinux context.

It is better to ignore selinux and leave the proper labeling to the selinux policy, which can add proper file transitions for the right context.

This also allows for a cleaner change in the selinux policy, because otherwise it will need infrastructure to hide the relabel AVCs as well.

For reference please see the selinux policy PR:
https://github.com/fedora-selinux/selinux-policy/pull/3030

---
 contrib/dns-hatchet/hatchet.bash | 2 --
 1 file changed, 2 deletions(-)
contrib/dns-hatchet/hatchet.bash +0 -2
index bc4d090..6f167cc 100644
@@ -20,11 +20,9 @@ set_dns() {
 		[[ ${#DNS_SEARCH[@]} -eq 0 ]] || printf 'search %s\n' "${DNS_SEARCH[*]}"
 		} | unshare -m --propagation shared bash -c "$(cat <<-_EOF
 			set -e
-			context="\$(stat -c %C /etc/resolv.conf 2>/dev/null)" || unset context
 			mount --make-private /dev/shm
 			mount -t tmpfs none /dev/shm
 			cat > /dev/shm/resolv.conf
-			[[ -z \$context || \$context == "?" ]] || chcon "\$context" /dev/shm/resolv.conf 2>/dev/null || true
 			mount -o remount,ro /dev/shm
 			mount -o bind,ro /dev/shm/resolv.conf /etc/resolv.conf
 		_EOF
Signature · 1 line
2.53.0
#1 lore raw
Quoted 9 lines · Robert Frohl

This reverts commit 2ce4680bd34f371aacd3c09673c3c907274321cd.

selinux does not allow every domain to set file contexts and will raise relabelto/relabelfrom AVCs and block these changes if a domain tries to update the selinux context.

It is better to ignore selinux and leave the proper labeling to the selinux policy, which can add proper file transitions for the right context.

Does any existent selinux policy have anything to handle this? Or is this purely speculative/future-facing?

Also, wondering if any distros are still shipping the hatchet.

#2 lore raw

Sorry about the delay, the message ended up in spam and I only found it today.

Quoted 7 lines · Jason A. Donenfeld
Quoted 6 lines · Robert Frohl

This reverts commit 2ce4680bd34f371aacd3c09673c3c907274321cd.

selinux does not allow every domain to set file contexts and will raise relabelto/relabelfrom AVCs and block these changes if a domain tries to update the selinux context.

Quoted 6 lines
Quoted 3 lines

It is better to ignore selinux and leave the proper labeling to the selinux policy, which can add proper file transitions for the right context.

Does any existent selinux policy have anything to handle this? Or is this purely speculative/future-facing?

The Fedora selinux policy (which is also the openSUSE upstream) does not have anything to handle the DNS hatchet [0]. I did also check the refpolicy. There a slightly different wireguard implementation exists [1], but the dns-hatchet is not yet covered. Beyond that I am not sure who else is maintaining a selinux policy and may have implemented a solution for wireguard. I briefly checked android's sepolicy and I could not find anything regarding wireguard.

More generically I do not think that the manual relabeling in hatchet.bash could have ever worked without a change in the respective selinux policies, because a process labeling files would need to have special privileges to do so. Which would mean in practice that it needs specific allow rules in the policy for changing the labels. At the same time a file transition could automatically assign the correct context to the new 'resolv.conf' and would be more concise, as it only needs one rule.
Meaning for both the SELinux policy needs to be adjusted.

Quoted 2 lines

Also, wondering if any distros are still shipping the hatchet.

We are shipping a slightly modified version with oS TW [2] and I just learned that Fedora disabled the hatchet with Fedora 33 [3].

In that case I would switch my approach to have the DNS hatchet policy addition only in our downstream SELinux policy, as it might also explain why Fedora was not to keen to have the policy change.

[0] https://github.com/fedora-selinux/selinux-policy/blob/rawhide/policy/modules/contrib/wireguard.te
[1] https://github.com/SELinuxProject/refpolicy/blob/main/policy/modules/services/wireguard.te
[2] https://build.opensuse.org/package/show/network:vpn:wireguard/wireguard-tools
[3] https://src.fedoraproject.org/rpms/wireguard-tools/blob/rawhide/f/wireguard-tools.spec#_33

Signature · 2 lines
SELinux Security Engineer, SUSE Software Solutions Germany GmbH, Frankenstraße 146, 90461 Nürnberg, Germany, GF: Jochen Jaser, Andrew McDonald, Werner Knoblich
GPG: D29F 82AA 9FD5 9D6E 74B1  6370 089E DB3D 230A 2404

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

In some cases you may have to rebuild the kernel. Distros may or may not include dns-hatchet. Tools like this are meant to be used by hand therefore it is quite possible the developers will exclude it from shipping in release.