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

RDKCOM-5108 RDKBDEV-2972: use sysctl_iface_set() to write to /proc files #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pradeeptakdas
Copy link
Contributor

Reason for change:
This function enhances code reusability, promotes safety through buffer overflow prevention and error handling.
Test Procedure: Sanity.
Risks: None.
Signed-off-by: Andre McCurdy [email protected]

@pradeeptakdas
Copy link
Contributor Author

Internal ticket for tracking https://ccp.sys.comcast.net/browse/RDKCOM-5108

@pradeeptakdas pradeeptakdas requested a review from guto86 October 22, 2024 18:08
@pradeeptakdas pradeeptakdas changed the title RDKBDEV-2972: use sysctl_iface_set() to write to /proc files RDKCOM-5108 RDKBDEV-2972: use sysctl_iface_set() to write to /proc files Nov 12, 2024
@pradeeptakdas
Copy link
Contributor Author

Based on @guto86 input I have requested Security team to review and approve the changes
Currently review in progress with @venugoapal Naik, @david John, and @douglas Bodden

@dxjones
Copy link

dxjones commented Jan 29, 2025

I added 2 comments to the code that are security-related. Both would be easy to address with simple additional checks.

armcc and others added 2 commits January 29, 2025 13:29
Reason for change:
This function enhances code reusability, promotes safety through
buffer overflow prevention and error handling.
Test Procedure: Sanity.
Risks: None.
Signed-off-by: Andre McCurdy <[email protected]>
Fixed the compilation issue.
int fd;

if (ifname) {
snprintf(buf, sizeof(buf), path, ifname);
Copy link

Choose a reason for hiding this comment

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

This code silently truncates the filename if the combined length of path and ifname exceed the size of buf.

This scenario could be detected easily by checking the return value of snprintf. If it is 127 (or greater) the result exactly fills buf or else exceeded it and was truncated.

The safest thing to do in this scenario is log an error message and return -1.

Since interface names can be manipulated through TR-181 parameters, this represents an attack surface, so we should defend against a truncated result, even if we expect it to be rare in practice.

@@ -1508,13 +1539,13 @@ static INT EthLink_Hal_BridgeConfigBcm(WAN_MODE_BRIDGECFG *pCfg)
v_secure_system("ip link set %s name %s", pCfg->wanPhyName,ETHWAN_DOCSIS_INF_NAME);
v_secure_system("brctl addbr %s", pCfg->wanPhyName);
v_secure_system("brctl addif %s %s", pCfg->wanPhyName,pCfg->ethwan_ifname);
sysctl_iface_set("/proc/sys/net/ipv6/conf/%s/autoconf", pCfg->ethwan_ifname, "0");
sysctl_iface_set("/proc/sys/net/ipv6/conf/%s/disable_ipv6", pCfg->ethwan_ifname, "1");
Copy link

Choose a reason for hiding this comment

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

Just an observation, not a bug, ...

Notice that pCfg->ethwan_ifname is a variable that presumably is connected to a TR-181 parameter.

If a hacker somehow changes the interface name to "../../../../../../../any/path/here/filename" ... they can force writing "0" or "1" to an arbitrary file.

This is a rare scenario, but I notice there is no input validation on the interface name. Simply checking for "/" in the interface name might be a sufficient check, since this should never occur with a valid interface name.

@armcc
Copy link
Contributor

armcc commented Feb 7, 2025

Let's abandon the change.

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.

4 participants