Bug 1371914 - rpm: glob() off-by-one stack write
Summary: rpm: glob() off-by-one stack write
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
low
low
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
URL:
Whiteboard:
Depends On: 1371926
Blocks: 1270711
TreeView+ depends on / blocked
 
Reported: 2016-08-31 12:25 UTC by Stefan Cornelius
Modified: 2021-02-17 03:24 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-08-31 12:47:25 UTC


Attachments (Terms of Use)

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]


Note You need to log in before you can comment on or make changes to this bug.