603
FILE* data = fopen(argv[1], "r+");
...
Constraining the process inside the application's home directory before opening any files is a
valuable security measure. However, the absence of a call to setuid() with some non-zero value
means the application is continuing to operate with unnecessary root privileges. Any successful
exploit carried out by an attacker against the application can now result in a privilege escalation
attack because any malicious operations will be performed with the privileges of the superuser.
If the application drops to the privilege level of a non-root user, the potential for damage is
substantially reduced.
Example 3:
This application intends to use a user's location to determine the timezone the user is in:
Example Language: Java (Bad)
locationClient = new LocationClient(this, this, this);
locationClient.connect();
Location userCurrLocation;
userCurrLocation = locationClient.getLastLocation();
setTimeZone(userCurrLocation);
This is unnecessary use of the location API, as this information is already available using the
Android Time API. Always be sure there is not another way to obtain needed information before
resorting to using the location API.
Example 4:
This code uses location to determine the user's current US State location.
First the application must declare that it requires the ACCESS_FINE_LOCATION permission in the
application's manifest.xml:
Example Language: XML (Bad)
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
During execution, a call to getLastLocation() will return a location based on the application's
location permissions. In this case the application has permission for the most accurate location
possible:
Example Language: Java (Bad)
locationClient = new LocationClient(this, this, this);
locationClient.connect();
Location userCurrLocation;
userCurrLocation = locationClient.getLastLocation();
deriveStateFromCoords(userCurrLocation);
While the application needs this information, it does not need to use the
ACCESS_FINE_LOCATION permission, as the ACCESS_COARSE_LOCATION permission will
be sufficient to identify which US state the user is in.
Observed Examples
Reference Description
CVE-2007-4217 FTP client program on a certain OS runs with setuid privileges and has a buffer
overflow. Most clients do not need extra privileges, so an overflow is not a
vulnerability for those clients.
https://www.cve.org/CVERecord?id=CVE-2007-4217
CWE Version 4.14
CWE-250: Execution with Unnecessary Privileges
CWE-250: Execution with Unnecessary Privileges