From nobody@FreeBSD.org  Wed Feb 25 07:45:08 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 1407616A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Feb 2004 07:45:08 -0800 (PST)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id EA86643D2D
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Feb 2004 07:45:07 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.10/8.12.10) with ESMTP id i1PFj772042360
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Feb 2004 07:45:07 -0800 (PST)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.10/8.12.10/Submit) id i1PFj76E042358;
	Wed, 25 Feb 2004 07:45:07 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200402251545.i1PFj76E042358@www.freebsd.org>
Date: Wed, 25 Feb 2004 07:45:07 -0800 (PST)
From: Aaron Peterson <aaron@alpete.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: bcwipe does not act successfully on raw devices
X-Send-Pr-Version: www-2.3
X-GNATS-Notify: crow@nektor.hu

>Number:         63354
>Category:       ports
>Synopsis:       security/bcwipe does not act successfully on raw devices
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lawrance
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 25 07:50:11 PST 2004
>Closed-Date:    Tue Apr 19 12:10:11 GMT 2005
>Last-Modified:  Tue Apr 19 12:10:11 GMT 2005
>Originator:     Aaron Peterson
>Release:        5.2
>Organization:
KY Cabinet for Health Services
>Environment:
FreeBSD fbsd52.state.ky.us 5.2-RELEASE FreeBSD 5.2-RELEASE #0: Sun Jan 11 04:21:45 GMT 2004     root@wv1u.btc.adaptec.com:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
the bcwipe port seems to work as expected on files, but errors when asked to act on a raw device. Discussion on freebsd-current mailing list suggests this has to do with bcwipe expecting to act on a block device, when freebsd 5.2 no longer has block devices, only character devices. I don't even know the difference between the two, so I'm just repeating here. the subject of mail in this thread on freebsd-current was "bcwipe won't wipe a block device"
>How-To-Repeat:
ask bcwipe to wipe a block device per the example in the man page:

bcwipe -bvmd /dev/fd0

or in my case, acting on a portable usb drive:

bcwipe -bvmd /dev/da0

kdump/ktrace of this command on my system can be found here:

http://alpete.com/bcwipe.kdump.txt


>Fix:
The final post in this thread on freebsd-current suggested the following:

On Fri, 20 Feb 2004, John-Mark Gurney wrote:

> Peter Jeremy wrote this message on Fri, Feb 20, 2004 at 18:23 +1100:
> > Summary: bcwipe is trying to read 1 byte from an offset of 2^N-1.
> > FreeBSD no longer has block devices (since 4.0) - /dev/da0 is a
> > character device.  Character devices can only be read in blocksize
> > units (typically 512 bytes for disks).  You need to fix bcwipe to
> > handle character devices.
>
> this can be done by using the fstat call on the device node.. it will
> provide both the proper block size (so it'll work w/ md swap backed
> devices that have a 4k block size) and device size...

Um, this can not be done by using the fstat call on the device node.
fstat() on devices always gives 0 for the device size and is little
better for the block size.  The block size is always the nominal
value PAGE_SIZE for non-disk devices and is not always the nominal
value BLKDEV_IOSIZE for disk devices.  From vfs_vnops.c:

%         } else if (vn_isdisk(vp, NULL)) {
%                 sb->st_blksize = vp->v_rdev->si_bsize_best;
%                 if (sb->st_blksize < vp->v_rdev->si_bsize_phys)
%                         sb->st_blksize = vp->v_rdev->si_bsize_phys;
%                 if (sb->st_blksize < BLKDEV_IOSIZE)
%                         sb->st_blksize = BLKDEV_IOSIZE;
%         } else {
%                 sb->st_blksize = PAGE_SIZE;
%         }

Here si_bsize_phys is the sector size of drivers or GEOM set it, else
it is defaulted to DEV_BSIZE in spec_open().  si_bsize_bestt is fully
rotted garbage -- it is only used above, but never set except using
bzero() to 0.  Since sector sizes are normally smaller than BLKDEV_IOSIZE
and BLKDEV_IOSIZE is normally PAGE_SIZE, the above normally sets
st_blksize to PAGE_SIZE for all devices.

Bruce
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->suspended 
State-Changed-By: linimon 
State-Changed-When: Sat Jul 3 13:20:50 GMT 2004 
State-Changed-Why:  
Mark as suspended until someone can come up with some patches. 

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

From: Danny Koenig <lists-fbsd-ports@bsdberlin.org>
To: freebsd-gnats-submit@FreeBSD.org, aaron@alpete.com
Cc:  
Subject: Re: ports/63354: security/bcwipe does not act successfully on raw
 devices
Date: Sun, 13 Mar 2005 22:30:04 +0100

 After updating to 1.5.3, is this problem still present as described in
 this PR?
Responsible-Changed-From-To: freebsd-ports-bugs->lawrance 
Responsible-Changed-By: lawrance 
Responsible-Changed-When: Tue Apr 19 01:41:21 GMT 2005 
Responsible-Changed-Why:  
Grab 

http://www.freebsd.org/cgi/query-pr.cgi?pr=63354 
State-Changed-From-To: suspended->closed 
State-Changed-By: lawrance 
State-Changed-When: Tue Apr 19 12:06:35 GMT 2005 
State-Changed-Why:  
The license for bcwipe forbids modifying the software, so 
we can't fix it.  I will report the problem upstream. 

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