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

Make usage of all configured interfaces safer #30

Conversation

jrmithdobbs
Copy link
Contributor

@jrmithdobbs jrmithdobbs commented Apr 17, 2021

Move the ifinit() calls into config.c's configure_interface() during parse
time. This removes dependence on UB and is safe across more systems. This also
removes the need to parse the config file twice and fixes a memory leak.

Fixes a memory leak of the entire config structure besides the interface list in main.
Fixes the same memory leak again that was duplicated into the HUP handler.

Fixes two use after free security issues. (one in main, one in HUP handler)
These use after frees cause crashes on OpenBSD with -O >0 but is a security issue
everywhere.

The use after free does not seem to exploitable as the only things done with the
free'ed pointers is dereferencing and access to the name member in ifinit when
calling strdup.

Additionally this simplifies SIGHUP behaviour and makes it not force reload all
configured interfaces if interfaces were originally passed on the command line.

Move the ifinit() calls into config.c's configure_interface() during parse
time. This removes dependence on UB and is safe across more systems. This also
removes the need to parse the config file twice.

Fixes use after free / crash on OpenBSD with -O >0.

Additionally this simplifies SIGHUP behaviour and makes it not force reload all
configured interfaces if interfaces were originally passed on the commandline.
@jrmithdobbs jrmithdobbs force-pushed the fix_hup_loading_all_interfaces branch from 2fe9379 to d72b0e6 Compare April 17, 2021 21:05
@jrmithdobbs jrmithdobbs changed the title Make SIGHUP work without loading all configured if Make usage of all configured interfaces safer Apr 17, 2021
@jrmithdobbs
Copy link
Contributor Author

This fixes both loading all interfaces on HUP when invoked with interfaces on the command line as well as a segfault that is described in #31 .

@jrmithdobbs
Copy link
Contributor Author

jrmithdobbs commented May 2, 2021

Updated the summary to clarify that this is a use after free security issue that should really be fixed.

It is not an issue with running on OpenBSD, that is a symptom.

The original code explicitly copies out a pointer to iflist_head in configure_interfaces from the config parser before it gets freed in configure_commit right after the call to configure_interfaces that get set to NULL by the original wide-dhcpv6 code since the interfaces are not already in the global list managed by ifinit at dhcp6_if before configure_commit is called.

This feature was implemented as an explicit use after free vulnerability by design.

I do not currently see an obvious way to use this to lead to code execution, or I would have already opened a CVE, but since users of the opnsense web interface with limited privileges can technically poke arbitrary binary data into memory using the raw option extension also added by opnsense it seems prudent to fix this.

Superpaul209 added a commit to Superpaul209/FreeBSD-ports that referenced this pull request Jul 29, 2022
Improvements include the following:

- Reload the client configuration on SIGHUP
- Removed all unused binaries except dhcp6c
- Raw option send and receive support
- PDINFO delegated prefix environment variable
- Accept interfaces from the configuration file

- Increased log verbosity.
- Fix socket leakage by setting FD_CLOEXEC.
- Call a configuration script after addresses and prefixes are set
  on an interface.
- Update ifid on interface restart, it may have changed.
- "-n" flag to prevent address release from being sent to the DHCP server
  upon restart.

- Merged PR : opnsense/dhcp6c#28
- Merged PR : opnsense/dhcp6c#29
- Merged PR : opnsense/dhcp6c#30
@fichtner fichtner self-assigned this May 10, 2023
@@ -196,33 +200,21 @@ main(int argc, char *argv[])
client6_init();

/*
* Doing away with the need for command line interfaces
* We need to read the config file to get the names of the interfaces.
* Doing away with the need for command line interfaces If this is set
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Doing away with the need for command line interfaces If this is set
* Doing away with the need for command line interfaces. If this is set

@fichtner fichtner closed this in db9f459 May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants