NetBSD Problem Report #41819

From riastradh@joule.t.continuation.org  Tue Aug  4 22:03:43 2009
Return-Path: <riastradh@joule.t.continuation.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id C635C63B879
	for <gnats-bugs@gnats.NetBSD.org>; Tue,  4 Aug 2009 22:03:43 +0000 (UTC)
Message-Id: <20090804220342.1A51B11BC@joule.t.continuation.org>
Date: Tue,  4 Aug 2009 22:03:42 +0000 (UTC)
From: Taylor R Campbell <campbell@mumble.net>
Reply-To: Taylor R Campbell <campbell@mumble.net>
To: gnats-bugs@gnats.NetBSD.org
Subject: kernel incorrectly records iovec data for ktrace
X-Send-Pr-Version: 3.95

>Number:         41819
>Category:       kern
>Synopsis:       kernel incorrectly records iovec data for ktrace
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 04 22:05:00 +0000 2009
>Closed-Date:    Wed Aug 05 19:56:00 +0000 2009
>Last-Modified:  Sat Sep 05 13:50:06 +0000 2009
>Originator:     Taylor R Campbell <campbell@mumble.net>
>Release:        NetBSD 5.0_STABLE
>Organization:
>Environment:
System: NetBSD joule.t.continuation.org 5.0_STABLE NetBSD 5.0_STABLE (RIAGATE) #0: Sun Jun 14 17:49:06 EDT 2009 riastradh@Oberon.local:/Users/riastradh/os/netbsd/5/obj/sys/arch/i386/compile/RIAGATE i386
Architecture: i386
Machine: i386
>Description:

	In sys/kern/kern_ktrace.c, ktr_io advances through the array
	of iovecs to copy their data into a contiguous buffer, but
	fails to update the pointer into the buffer.  Thus ktrace
	output for I/O with iovecs has later iovec buffers clobbering
	earlier ones, and garbage where later ones should go.

>How-To-Repeat:

	Ktracing the following program should show that it writes
	`one\ntwo\n', but instead it shows

		  4412      1 foo      GIO   fd 1 wrote 8 bytes
		       "two\n\M-4\M-T\M-?\M-?"

	Contents of foo.c:

#include <err.h>
#include <unistd.h>
#include <sys/uio.h>

int
main(int argc, char *argv[])
{
        struct iovec iov[2] =
                {
                        { .iov_base = "one\n", .iov_len = 4 },
                        { .iov_base = "two\n", .iov_len = 4 },
                };
        ssize_t written;

        written = writev(STDOUT_FILENO, iov, 2);
        if (written != 8)
        {
                if (written < 0)
                        err(1, "writev");
                else
                        errx(1, "writev wrote too few bytes: %zd", written);
        }

        return 0;
}

>Fix:

	Apply the following patch to sys/kern/kern_ktrace.c to fix the
	ktr_io function:

--- kern_ktrace.c	14 May 2009 01:58:26 +0000	1.147
+++ kern_ktrace.c	04 Aug 2009 21:54:33 +0000	
@@ -684,6 +684,7 @@
 		if (copyin(iov->iov_base, cp, cnt) != 0)
 			goto out;
 		kte->kte_kth.ktr_len += cnt;
+		cp += cnt;
 		buflen -= cnt;
 		resid -= cnt;
 		iov->iov_len -= cnt;

	Please also pull up a similar change to netbsd-4 to fix the
	ktrgenio function:

--- kern_ktrace.c	11 Apr 2008 06:35:02 +0000	1.112.2.1
+++ kern_ktrace.c	04 Aug 2009 21:55:42 +0000	
@@ -545,6 +545,7 @@
 		if (copyin(iov->iov_base, cp, cnt) != 0)
 			goto out;
 		kth->ktr_len += cnt;
+		cp += cnt;
 		buflen -= cnt;
 		resid -= cnt;
 		iov->iov_len -= cnt;

>Release-Note:

>Audit-Trail:
From: David Laight <dsl@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41819 CVS commit: src/sys/kern
Date: Wed, 5 Aug 2009 19:53:42 +0000

 Module Name:	src
 Committed By:	dsl
 Date:		Wed Aug  5 19:53:42 UTC 2009

 Modified Files:
 	src/sys/kern: kern_ktrace.c

 Log Message:
 Fix ktrace of data from iovec based system calls.
 Fixes PR/41819


 To generate a diff of this commit:
 cvs rdiff -u -r1.148 -r1.149 src/sys/kern/kern_ktrace.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: dsl@NetBSD.org
State-Changed-When: Wed, 05 Aug 2009 19:56:00 +0000
State-Changed-Why:
fixed on head and pullup requests send fornetbsd 4 and netbsd 5


From: Manuel Bouyer <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41819 CVS commit: [netbsd-5] src/sys/kern
Date: Sat, 5 Sep 2009 11:37:21 +0000

 Module Name:	src
 Committed By:	bouyer
 Date:		Sat Sep  5 11:37:21 UTC 2009

 Modified Files:
 	src/sys/kern [netbsd-5]: kern_ktrace.c

 Log Message:
 Pull up following revision(s) (requested by dsl in ticket #901):
 	sys/kern/kern_ktrace.c: revision 1.149
 Fix ktrace of data from iovec based system calls.
 Fixes PR/41819


 To generate a diff of this commit:
 cvs rdiff -u -r1.147 -r1.147.4.1 src/sys/kern/kern_ktrace.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Manuel Bouyer <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41819 CVS commit: [netbsd-4-0] src/sys/kern
Date: Sat, 5 Sep 2009 13:45:28 +0000

 Module Name:	src
 Committed By:	bouyer
 Date:		Sat Sep  5 13:45:28 UTC 2009

 Modified Files:
 	src/sys/kern [netbsd-4-0]: kern_exec.c

 Log Message:
 Pull up following revision(s) (requested by dsl in ticket #1352):
 	sys/kern/kern_exec.c: patch
 Fix ktrace of data from iovec based system calls.
 Fixes PR/41819


 To generate a diff of this commit:
 cvs rdiff -u -r1.232.2.2 -r1.232.2.2.6.1 src/sys/kern/kern_exec.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Manuel Bouyer <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41819 CVS commit: [netbsd-4] src/sys/kern
Date: Sat, 5 Sep 2009 13:45:43 +0000

 Module Name:	src
 Committed By:	bouyer
 Date:		Sat Sep  5 13:45:43 UTC 2009

 Modified Files:
 	src/sys/kern [netbsd-4]: kern_exec.c

 Log Message:
 Pull up following revision(s) (requested by dsl in ticket #1352):
 	sys/kern/kern_exec.c: patch
 Fix ktrace of data from iovec based system calls.
 Fixes PR/41819


 To generate a diff of this commit:
 cvs rdiff -u -r1.232.2.2 -r1.232.2.3 src/sys/kern/kern_exec.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.