From nobody@FreeBSD.org  Tue Nov 25 11:03:16 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E016C1065672
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 25 Nov 2008 11:03:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id D07318FC23
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 25 Nov 2008 11:03:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id mAPB3GTC047380
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 25 Nov 2008 11:03:16 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id mAPB3Ghj047379;
	Tue, 25 Nov 2008 11:03:16 GMT
	(envelope-from nobody)
Message-Id: <200811251103.mAPB3Ghj047379@www.freebsd.org>
Date: Tue, 25 Nov 2008 11:03:16 GMT
From: Steven Hartland <steven.hartland@multiplay.co.uk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: truss segv for unknown syscall
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         129170
>Category:       bin
>Synopsis:       [patch] fix truss(1) segv for unknown syscall
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 25 11:10:04 UTC 2008
>Closed-Date:    Sun Jun 28 02:46:26 UTC 2009
>Last-Modified:  Sun Jun 28 02:46:26 UTC 2009
>Originator:     Steven Hartland
>Release:        FreeBSD 7.0
>Organization:
Multiplay
>Environment:
FreeBSD loncore0.multiplay.co.uk 7.0-RELEASE-p3 FreeBSD 7.0-RELEASE-p3 #8: Sat Nov 22 18:46:41 GMT 2008     root@loncore0.multiplay.co.uk:/usr/src/sys/amd64/compile/MULTIPLAY  amd64
>Description:
If an application calls an unknown syscall truss will segfault due to an
invalid range check on nsyscalls
>How-To-Repeat:
Run an application which calls a syscall that truss doesnt know of e.g. a
linux application which calls a syscall >= 311 on FreeBSD 7.0.
>Fix:
Apply the attached patch or derivative there of.

Patch attached with submission follows:

--- amd64-fbsd.c.orig	2008-11-22 03:22:33.000000000 +0000
+++ amd64-fbsd.c	2008-11-22 03:24:57.000000000 +0000
@@ -143,5 +143,5 @@
   fsc.number = syscall_num;
   fsc.name =
-    (syscall_num < 0 || syscall_num > nsyscalls) ?  NULL : syscallnames[syscall_num];
+    (syscall_num < 0 || syscall_num >= nsyscalls) ?  NULL : syscallnames[syscall_num];
   if (!fsc.name) {
     fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
--- amd64-fbsd32.c.orig	2008-11-22 03:22:41.000000000 +0000
+++ amd64-fbsd32.c	2008-11-22 03:24:52.000000000 +0000
@@ -153,5 +153,5 @@
   fsc.number = syscall_num;
   fsc.name =
-    (syscall_num < 0 || syscall_num > nsyscalls) ? NULL :
+    (syscall_num < 0 || syscall_num >= nsyscalls) ? NULL :
       freebsd32_syscallnames[syscall_num];
   if (!fsc.name) {
--- amd64-linux32.c.orig	2008-11-22 03:20:58.000000000 +0000
+++ amd64-linux32.c	2008-11-22 03:21:59.000000000 +0000
@@ -125,5 +125,5 @@
   fsc.number = syscall_num;
   fsc.name =
-    (syscall_num < 0 || syscall_num > nsyscalls) ? NULL : linux32_syscallnames[syscall_num];
+    (syscall_num < 0 || syscall_num >= nsyscalls) ? NULL : linux32_syscallnames[syscall_num];
   if (!fsc.name) {
     fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
--- i386-fbsd.c.orig	2008-11-22 03:22:50.000000000 +0000
+++ i386-fbsd.c	2008-11-22 03:24:42.000000000 +0000
@@ -148,5 +148,5 @@
   fsc.number = syscall_num;
   fsc.name =
-    (syscall_num < 0 || syscall_num > nsyscalls) ? NULL : syscallnames[syscall_num];
+    (syscall_num < 0 || syscall_num >= nsyscalls) ? NULL : syscallnames[syscall_num];
   if (!fsc.name) {
     fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
--- i386-linux.c.orig	2008-11-21 14:11:22.000000000 +0000
+++ i386-linux.c	2008-11-25 10:33:43.000000000 +0000
@@ -125,5 +125,5 @@
   fsc.number = syscall_num;
   fsc.name =
-    (syscall_num < 0 || syscall_num > nsyscalls) ? NULL : linux_syscallnames[syscall_num];
+    (syscall_num < 0 || syscall_num >= nsyscalls) ? NULL : linux_syscallnames[syscall_num];
   if (!fsc.name) {
     fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
--- ia64-fbsd.c.orig	2008-11-22 03:22:57.000000000 +0000
+++ ia64-fbsd.c	2008-11-22 03:24:31.000000000 +0000
@@ -136,5 +136,5 @@
 
   fsc.number = syscall_num;
-  fsc.name = (syscall_num < 0 || syscall_num > nsyscalls)
+  fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls)
       ? NULL : syscallnames[syscall_num];
   if (!fsc.name) {
--- powerpc-fbsd.c.orig	2008-11-22 03:23:04.000000000 +0000
+++ powerpc-fbsd.c	2008-11-22 03:24:17.000000000 +0000
@@ -150,5 +150,5 @@
   fsc.number = syscall_num;
   fsc.name =
-    (syscall_num < 0 || syscall_num > nsyscalls) ? NULL : syscallnames[syscall_num];
+    (syscall_num < 0 || syscall_num >= nsyscalls) ? NULL : syscallnames[syscall_num];
   if (!fsc.name) {
     fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
--- sparc64-fbsd.c.orig	2008-11-25 10:35:56.000000000 +0000
+++ sparc64-fbsd.c	2008-11-25 10:35:45.000000000 +0000
@@ -146,5 +146,5 @@
   fsc.number = syscall_num;
   fsc.name =
-    (syscall_num < 0 || syscall_num >= nsyscalls) ? NULL : syscallnames[syscall_num];
+    (syscall_num < 0 || syscall_num > nsyscalls) ? NULL : syscallnames[syscall_num];
   if (!fsc.name) {
     fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->keramida 
Responsible-Changed-By: keramida 
Responsible-Changed-When: Fri Jan 23 14:17:28 UTC 2009 
Responsible-Changed-Why:  
This looks interesting. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=129170 

From: Giorgos Keramidas <keramida@freebsd.org>
To: Steven Hartland <steven.hartland@multiplay.co.uk>
Cc: Dag-Erling Smorgrav <des@freebsd.org>
Subject: Re: bin/129170: truss segv for unknown syscall
Date: Sun, 08 Feb 2009 10:20:07 +0200

 ## Adding a few bits to the bug's audit trail.
 
 Running truss on the following program on today's 8.0-CURRENT is
 sufficient to reproduce the SIGSEGV crash in truss itself:
 
   #include <sys/syscall.h>
 
   #include <errno.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include <unistd.h>
 
   int
   main(void)
   {
           char errbuf[1024];
           int rc;
 
           rc = syscall(506, (void *)NULL);
           (void)strerror_r(errno, errbuf, sizeof(errbuf));
           printf("rc=%d errno=%d (%s)\n", rc, errno, errbuf);
           return EXIT_SUCCESS;
   }
 
 I have adapted the patch to sparc64-fbsd.c too (it needed a few changes
 to apply cleanly on current sources), and emailed des@ about it.  He
 seems to be active around the area, so with his help we can fix this :)
 
State-Changed-From-To: open->closed 
State-Changed-By: keramida 
State-Changed-When: Sun Jun 28 02:43:20 UTC 2009 
State-Changed-Why:  
delphij has fixed this in /head r192943 and merged it to 
stable/7 r193965.  My local tree only has whitespace diffs 
for truss now. 


Responsible-Changed-From-To: keramida->delphij 
Responsible-Changed-By: keramida 
Responsible-Changed-When: Sun Jun 28 02:43:20 UTC 2009 
Responsible-Changed-Why:  
Change owner to committer who really fixed this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=129170 
>Unformatted:
