Bug 120055

Summary: [linux] kdump(1) segfaults on freebsd6_mmap syscall
Product: Base System Reporter: Patrick Lamaiziere <patpr>
Component: binAssignee: attilio
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
kdump_segfault.diff none

Description Patrick Lamaiziere 2008-01-27 18:50:00 UTC
kdump crashs with a segfault when dumping the content of the syscall
freebsd6_mmap :

$ kdump
 69472 bash     CALL freebsd6_mmap(0x3,0xbfbfdeb8,<invalid>672202704,MAP_SHARED|[CUT],0,0,...
<SEGFAULT>

I've inserted some printf() in /usr/src/usr.bin/kdump/kdump.c and the
problem is that ktr->narg is equal to 3 when ktrsyscall() is called for
this syscall.

Line 305,/usr/src/usr.bin/kdump/kdump.c
void
ktrsyscall(struct ktr_syscall *ktr)
{
   int narg = ktr->ktr_narg;
   register_t *ip;
[CUT]
#ifdef SYS_freebsd6_mmap
   } else if (ktr->ktr_code == SYS_freebsd6_mmap) {
             print_number(ip,narg,c);
             print_number(ip,narg,c);
             (void)putchar(',');
             mmapprotname ((int)*ip);
             (void)putchar(',');
             ip++;
             narg--;
             mmapflagsname ((int)*ip);
             ip++;
             narg--;

Here narg = -1 because the macro print_number() decrements narg.
So a after, it loops until it segfaults:
[CUT]
  while (narg) {
                 print_number(ip,narg,c);
               }
 (void)putchar(')');

For a fix, a "while (narg>0)" will be safer but i don't know if this is
a bug on the call, a bug on ktrace or only a bug in kdump.

Regards.

How-To-Repeat: The krace.out (gziped) can be found here :

http://user.lamaiziere.net/patrick/ktrace.out.gz
Comment 1 Patrick Lamaiziere 2008-01-27 20:44:02 UTC
My apologies, i forgot to say that it was a kdump on a linux program
(acroread8)

Shall kdump work in this case ?
Comment 2 Jaakko Heinonen 2008-01-31 12:57:19 UTC
This is a duplicate of kern/119564. (You should use devel/linux_kdump
port for Linux binaries.) However I think that it might be reasonable to
commit the attached patch to avoid kdump segfaulting on "corrupted"
dumps.
Comment 3 Dmitry Chagin freebsd_committer freebsd_triage 2009-03-18 21:32:51 UTC
Responsible Changed
From-To: freebsd-bugs->dchagin

grab PR, I have solution
Comment 4 Alexander Best 2009-06-24 00:52:23 UTC
this patch isn't in HEAD yet. would be nice to have it there.
Comment 5 dfilter service freebsd_committer freebsd_triage 2009-11-07 21:46:43 UTC
Author: attilio
Date: Sat Nov  7 21:46:34 2009
New Revision: 199024
URL: http://svn.freebsd.org/changeset/base/199024

Log:
  Use a safety belt for cases where corrupted narg can be passed to the
  ktrsyscall(). print_number() does decrement the number of arguments,
  leading to infinite loops for negative values.
  
  Reported by:	Patrick Lamaiziere <patpr at davenulle dot org>,
  		Jonathan Pascal <jkpyvxmzsa at mailinator dot com>
  Submitted by:	jh
  PR:		bin/120055, kern/119564
  MFC:		1 week

Modified:
  head/usr.bin/kdump/kdump.c

Modified: head/usr.bin/kdump/kdump.c
==============================================================================
--- head/usr.bin/kdump/kdump.c	Sat Nov  7 21:28:21 2009	(r199023)
+++ head/usr.bin/kdump/kdump.c	Sat Nov  7 21:46:34 2009	(r199024)
@@ -799,7 +799,7 @@ ktrsyscall(struct ktr_syscall *ktr)
 				narg--;
 			}
 		}
-		while (narg) {
+		while (narg > 0) {
 			print_number(ip,narg,c);
 		}
 		(void)putchar(')');
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 6 Alexander Best 2009-11-07 21:58:00 UTC
committed to HEAD (r199024) by attilio@.

please set pr into patched state.

thanks.
alex
Comment 7 Mark Linimon freebsd_committer freebsd_triage 2009-11-10 08:18:16 UTC
State Changed
From-To: open->patched

A patch has been committed. 


Comment 8 Mark Linimon freebsd_committer freebsd_triage 2009-11-10 08:18:16 UTC
Responsible Changed
From-To: dchagin->attilio

Over to the committer of the patch.
Comment 9 Alexander Best 2010-02-13 01:15:13 UTC
patch is in all branches except 6.

cheers.
alex
Comment 10 Alexander Best freebsd_committer freebsd_triage 2010-11-13 10:02:04 UTC
State Changed
From-To: patched->closed

Fixed in RELENG_7, RELENG_8 and HEAD. RELENG_6 went EoL.