NetBSD Problem Report #35447

From christianbiere@gmx.de  Fri Jan 19 16:32:30 2007
Return-Path: <christianbiere@gmx.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id A306D63BA82
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 19 Jan 2007 16:32:29 +0000 (UTC)
Message-Id: <20070119163833.GA481@cyclonus>
Date: Fri, 19 Jan 2007 17:38:33 +0100
From: Christian Biere <christianbiere@gmx.de>
To: gnats-bugs@NetBSD.org
Subject: Panic by write to raw cgd device
X-Send-Pr-Version: 3.95

>Number:         35447
>Category:       kern
>Synopsis:       Panic by write to raw cgd device
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 19 16:35:01 +0000 2007
>Last-Modified:  Mon Jan 22 01:55:00 +0000 2007
>Originator:     Christian Biere
>Release:        NetBSD 4.99.7
>Environment:
System: NetBSD cyclonus 4.99.7 NetBSD 4.99.7 (STARSCREAM) #4: Wed Dec 27 02:37:42 CET 2006 src@cyclonus:/o/NetBSD/obj/sys/arch/i386/compile/STARSCREAM i386
Architecture: i386
Machine: i386
>Description:

cgd7: error 30

By setting ddb.onpanic to 1 I could at least see that the panic occurs
in BF_cbc_encrypt+0x3f movl 0(%esi)

The stacktrace is not very useful:
uvm_fault(0xc0366640, 0xc9fb7000, 1) -> 0xe
fatal page fault in supervisor mode
trap type 6 code 0 eip c027bbff cs 8 eflags 10212 cr2 c9fb7000 ilevel 6
panic: trap
Begin traceback...
uvm_fault(0xca9a8000, 0, 1) -> 0xe
fatal page fault in supervisor mode
trap type 6 code 0 eip c026d1ef cs 8 eflags 10246 cr2 6 ilevel 6
panic: trap
Faulted in mid-traceback; aborting...

>How-To-Repeat:

#! /bin/sh -x

set -e
mkdir /var/tmp/cgd_test
cd /var/tmp/cgd_test

dd if=/dev/zero bs=32k count=1k of=image
cgdconfig -g -o image.conf -V none blowfish-cbc 128
vnconfig -c vnd0 image
cgdconfig cgd0 /dev/vnd0d image.conf
echo > /dev/rcgd0d

The latter was just a test because disklabel -iI cgd0 kept
failing with this message:

disklabel: disklabel write (sector 0) size 8192 failed: Read-only file system

>Fix:

>Audit-Trail:
From: Christian Biere <christianbiere@gmx.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/35447: Panic by write to raw cgd device
Date: Mon, 22 Jan 2007 02:56:38 +0100

 The following patch fixes the problem for me. I've added one check from
 src/sys/dev/ata/wd.c to prevent write attempts with an amount of bytes that
 isn't a multiple of the sector size. This affects more than just cgd though,
 so I'm not sure whether this check was just forgotten or whether it's omitted
 for a good reason.

 --- src/sys/dev/dksubr.c.orig	2006-12-26 15:46:32.000000000 +0100
 +++ src/sys/dev/dksubr.c	2007-01-22 01:56:43.000000000 +0100
 @@ -195,10 +195,8 @@

  	if (!(dksc->sc_flags & DKF_INITED)) {
  		DPRINTF_FOLLOW(("dk_strategy: not inited\n"));
 -		bp->b_error  = ENXIO;
 -		bp->b_flags |= B_ERROR;
 -		biodone(bp);
 -		return;
 +		bp->b_error = ENXIO;
 +		goto bad;
  	}

  	/* XXX look for some more errors, c.f. ld.c */
 @@ -206,17 +204,18 @@
  	bp->b_resid = bp->b_bcount;

  	/* If there is nothing to do, then we are done */
 -	if (bp->b_bcount == 0) {
 -		biodone(bp);
 -		return;
 +	if (bp->b_bcount == 0)
 +		goto done;
 +
 +	if (bp->b_bcount % dksc->sc_dkdev.dk_label->d_secsize) {
 +		bp->b_error = EINVAL;
 +		goto bad;
  	}

  	wlabel = dksc->sc_flags & (DKF_WLABEL|DKF_LABELLING);
  	if (DISKPART(bp->b_dev) != RAW_PART &&
 -	    bounds_check_with_label(&dksc->sc_dkdev, bp, wlabel) <= 0) {
 -		biodone(bp);
 -		return;
 -	}
 +	    bounds_check_with_label(&dksc->sc_dkdev, bp, wlabel) <= 0)
 +		goto done;

  	blkno = bp->b_blkno;
  	if (DISKPART(bp->b_dev) != RAW_PART) {
 @@ -237,6 +236,10 @@
  	dk_start(di, dksc);
  	splx(s);
  	return;
 +bad:
 +	bp->b_flags |= B_ERROR;
 +done:
 +	biodone(bp);
  }

  void

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.