First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 102520
Alias:
Product:
Component:
Status: RESOLVED
Resolution: FIXED
Assigned To: Gentoo's Team for Core System packages <base-system@gentoo.org>
Hardware:
OS:
Version:
Priority:
Severity:
Reporter: Daniel Drake <dsd@gentoo.org>
Add CC:
CC:
URL:
Summary:
Status Whiteboard:
Keywords:
Flags: Requestee:
 
 
  ()

Filename Description Type Creator Created Size Actions
file.patch Fix patch Daniel Drake 2005-08-14 11:00 0000 450 bytes Details | Diff
badfile Sample file patch Daniel Drake 2005-08-14 11:04 0000 250.00 KB Details | Diff
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 102520 depends on: Show dependency tree
Show dependency graph
Bug 102520 blocks:

Additional Comments: (this is where you put emerge --info)







View Bug Activity   |   Format For Printing   |   XML   |   Clone This Bug


Description:   Opened: 2005-08-14 10:58 0000
I've found and identified a bug in file which causes it to read beyond the end
of a buffer. Not sure if this is a security issue (as its only a 'read
overflow') but I thought I should check with you first.

mget() in softmagic.c will perform a memcpy operation and in some circumstances
will attempt to read beyond the end of the source buffer.

It does do *some* bounds checking but in the case of FILE_SEARCH this is wrong.
(approx line 1125)
		case FILE_STRING:
		case FILE_PSTRING:
		case FILE_SEARCH:
			if (nbytes < (offset + m->vallen))
				return 0;

(approx line 1135)
	if (m->type == FILE_SEARCH) {
		p->buf = malloc(m->mask + m->vallen);
		if (p->buf == NULL) {
			file_error(ms, errno, "Cannot allocate search buffer");
			return 0;
		}
		(void)memcpy(p->buf, s + offset, m->mask + m->vallen);
	}

You can see it will read mask+vallen bytes starting at s+offset. However there
is no check that s+offset+mask+vallen (i.e. the end of the data being copied) is
still within the bounds of s.

'nbytes' refers to the size of s.

------- Comment #1 From Daniel Drake 2005-08-14 11:00:07 0000 -------
Created an attachment (id=65949) [edit]
Fix

------- Comment #2 From Daniel Drake 2005-08-14 11:04:31 0000 -------
Created an attachment (id=65950) [edit]
Sample file

This file will cause the read overflow.

An unpatched file-4.14 tries to read 12292 bytes starting at offset 255488 from
s. s is just an in-memory copy of this file, 256000 bytes, so it obviously goes
much too far.

Even without the patch, file still happily works on this on my x86. However on
amd64 it seems much easier to reproduce - you get a Segmentation fault.

------- Comment #3 From Daniel Drake 2005-08-14 11:05:17 0000 -------
*** Bug 102504 has been marked as a duplicate of this bug. ***

------- Comment #4 From Tavis Ormandy (RETIRED) 2005-08-14 13:26:40 0000 -------
Does not appear to be any security impact, reassigning to base-system.

------- Comment #5 From Daniel Drake 2005-08-15 10:33:02 0000 -------
Sent patch upstream

------- Comment #6 From Daniel Drake 2005-08-15 14:35:14 0000 -------
Upstream maintainer confirms the problem and says it exists in other places
too.
Expect a 4.15 release soon.

------- Comment #7 From SpanKY 2005-08-18 15:27:16 0000 -------
file-4.15 now in portage

First Last Prev Next    No search results available      Search page      Enter new bug