kernel/5235: reading from /dev/cd0c returns incorrect data

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

kernel/5235: reading from /dev/cd0c returns incorrect data

Paul Stoeber
>Number:         5235
>Category:       kernel
>Synopsis:       reading from /dev/cd0c returns incorrect data
>Confidential:   yes
>Severity:       serious
>Priority:       medium
>Responsible:    bugs
>State:          open
>Quarter:        
>Keywords:      
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 11 15:40:01 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Paul Stoeber
>Release:        4.0-current
>Organization:
net
>Environment:
        System      : OpenBSD 4.0
        Architecture: OpenBSD.i386
        Machine     : i386
>Description:
Insert a CD-ROM and compare
        file -s /dev/rcd0c
with
        file -s /dev/cd0c
or try
        for i in rcd0c cd0c; do dd if=/dev/$i bs=2048 count=1000 | sha1; done
or read
        http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=3261
or
        http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=14026

>How-To-Repeat:
>Fix:
This patch against spec_vnops.c rev 1.35 is based on
        http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/miscfs/specfs/spec_vnops.c.diff?r1=1.58&r2=1.59
and it appears to work.

--- /usr/src/sys/miscfs/specfs/spec_vnops.c.orig Mon Sep 11 13:00:54 2006
+++ /usr/src/sys/miscfs/specfs/spec_vnops.c Mon Sep 11 13:03:10 2006
@@ -237,7 +237,7 @@
  struct proc *p = uio->uio_procp;
  struct buf *bp;
  daddr_t bn, nextbn;
- long bsize, bscale, ssize;
+ long bsize, bscale;
  struct partinfo dpart;
  int n, on, majordev;
  int (*ioctl)(dev_t, u_long, caddr_t, int, struct proc *);
@@ -267,7 +267,6 @@
  if (uio->uio_offset < 0)
  return (EINVAL);
  bsize = BLKDEV_IOSIZE;
- ssize = DEV_BSIZE;
  if ((majordev = major(vp->v_rdev)) < nblkdev &&
     (ioctl = bdevsw[majordev].d_ioctl) != NULL &&
     (*ioctl)(vp->v_rdev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0) {
@@ -275,12 +274,10 @@
     dpart.part->p_frag != 0 && dpart.part->p_fsize != 0)
  bsize = dpart.part->p_frag *
     dpart.part->p_fsize;
- if (dpart.disklab->d_secsize != 0)
- ssize = dpart.disklab->d_secsize;
  }
- bscale = bsize / ssize;
+ bscale = bsize >> DEV_BSHIFT;
  do {
- bn = (uio->uio_offset / ssize) &~ (bscale - 1);
+ bn = (uio->uio_offset >> DEV_BSHIFT) &~ (bscale - 1);
  on = uio->uio_offset % bsize;
  n = min((unsigned)(bsize - on), uio->uio_resid);
  if (vp->v_lastr + bscale == bn) {
@@ -338,7 +335,7 @@
  struct proc *p = uio->uio_procp;
  struct buf *bp;
  daddr_t bn;
- long bsize, bscale, ssize;
+ long bsize, bscale;
  struct partinfo dpart;
  int n, on, majordev;
  int (*ioctl)(dev_t, u_long, caddr_t, int, struct proc *);
@@ -366,7 +363,6 @@
  if (uio->uio_offset < 0)
  return (EINVAL);
  bsize = BLKDEV_IOSIZE;
- ssize = DEV_BSIZE;
  if ((majordev = major(vp->v_rdev)) < nblkdev &&
     (ioctl = bdevsw[majordev].d_ioctl) != NULL &&
     (*ioctl)(vp->v_rdev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0) {
@@ -374,12 +370,10 @@
     dpart.part->p_frag != 0 && dpart.part->p_fsize != 0)
  bsize = dpart.part->p_frag *
     dpart.part->p_fsize;
- if (dpart.disklab->d_secsize != 0)
- ssize = dpart.disklab->d_secsize;
  }
- bscale = bsize / ssize;
+ bscale = bsize >> DEV_BSHIFT;
  do {
- bn = (uio->uio_offset / ssize) &~ (bscale - 1);
+ bn = (uio->uio_offset >> DEV_BSHIFT) &~ (bscale - 1);
  on = uio->uio_offset % bsize;
  n = min((unsigned)(bsize - on), uio->uio_resid);
  error = bread(vp, bn, bsize, NOCRED, &bp);


>Release-Note:
>Audit-Trail:
>Unformatted:

Reply | Threaded
Open this post in threaded view
|

Re: kernel/5235: reading from /dev/cd0c returns incorrect data

Pedro Martelletto
The following reply was made to PR kernel/5235; it has been noted by GNATS.

From: Pedro Martelletto <[hidden email]>
To: Paul Stoeber <[hidden email]>
Cc: [hidden email]
Subject: Re: kernel/5235: reading from /dev/cd0c returns incorrect data
Date: Tue, 12 Sep 2006 00:09:11 -0300

 The sad true is that our kernel can't cope with physical sector sizes
 different than DEV_BSIZE bytes. Your diff is correct, although I would
 prefer if it used btodb() instead of explicitly shifting by DEV_BSHIFT.
 
 -p.

Reply | Threaded
Open this post in threaded view
|

Re: kernel/5235: reading from /dev/cd0c returns incorrect data

Pedro Martelletto
More like 'sad truth' here, sorry. I should get some sleep (or coffee).

On Mon, Sep 11, 2006 at 09:15:02PM -0600, Pedro Martelletto wrote:
>  The sad true is that our kernel can't cope with physical sector sizes
>  different than DEV_BSIZE bytes. Your diff is correct, although I would
>  prefer if it used btodb() instead of explicitly shifting by DEV_BSHIFT.