Bug 1371914

Summary: rpm: glob() off-by-one stack write
Product: [Other] Security Response Reporter: Stefan Cornelius <scorneli>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED WONTFIX QA Contact:
Severity: low Docs Contact:
Priority: low    
Version: unspecifiedCC: ffesti, lkardos, novyjindrich, packaging-team-maint, pknirsch
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-08-31 12:47:25 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On: 1371926    
Bug Blocks: 1270711    

Description Stefan Cornelius 2016-08-31 12:25:02 UTC
An off-by-one NULL byte write on the stack has been reported in rpm.

This is caused by an off-by-one within the glob() function in rpmio/rpmglob.c.
It allocates space of a certain size on the stack using alloca(), then uses
mempcpy() to copy data into it, and finally tries to write a terminating NULL.
This NULL byte is not accounted for when allocating the stack memory, thus
it's written one byte after the allocated memory.

> 	else {
> 	    char *end_name = strchr(dirname, '/');
> 	    const char *user_name;
> 	    const char *home_dir;
> 
> 	    if (end_name == NULL)
> 		user_name = dirname + 1;
> 	    else {
> 		char *newp;
> 		newp = (char *) alloca(end_name - dirname);
> 		*((char *) mempcpy(newp, dirname + 1, end_name - dirname))
> 		    = '\0';
> 		user_name = newp;
> 	    }
 
    

How exploitable this really is depends on a lot of factors, including
the exact implementation of alloca(), the architecture, stack layout, etc.
For the majority of scenarios, this doesn't even cause a crash. For the
remaining scenarios, triggering a crash may be possible. Exploiting this
for code execution under normal conditions seems unlikely.

Acknowledgments:

Name: Hanno Boeck

Comment 2 Stefan Cornelius 2016-08-31 12:43:58 UTC
Created rpm tracking bugs for this issue:

Affects: fedora-all [bug 1371926]