NetBSD Problem Report #5553

Received: (qmail 15824 invoked from network); 7 Jun 1998 22:41:23 -0000
Message-Id: <xofzpforg1j.fsf@blubb.pdc.kth.se>
Date: 08 Jun 1998 00:41:12 +0200
From: joda@pdc.kth.se (Johan Danielsson)
Sender: joda@pdc.kth.se
To: gnats-bugs@gnats.netbsd.org
Cc: port-i386@NetBSD.ORG
In-Reply-To: joda@pdc.kth.se's message of "06 Jun 1998 05:15:59 +0200"
Subject: Re: Adaptec 2940 and `more than N DMA segs'
References: <xofemx3rzio.fsf@blubb.pdc.kth.se>

>Number:         5553
>Category:       kern
>Synopsis:       ahc_scsi_cmd gets called with too big datalen
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bouyer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jun 07 15:50:01 +0000 1998
>Closed-Date:    Wed Feb 10 12:37:23 +0000 1999
>Last-Modified:  Wed Feb 10 12:39:20 +0000 1999
>Originator:     Johan Danielsson
>Release:        1.3.2
>Organization:
>Environment:
System: NetBSD buoy.pdc.kth.se 1.3.2 NetBSD 1.3.2 (BUOY) #4: Sat Jun  6 01:36:45 CEST 1998     root@buoy.pdc.kth.se:/usr/src/sys/arch/i386/compile/BUOY i386

>Description:

If you open a raw scsi disk-device, seek to a negative position,
ahc_scsi_cmd sometime gets called with a too big datalen. The call
chain is as follows:

In vn_read(), fp->f_offset is, say, -2135932928, and uio->uio_offset
gets this value also. Then in physio(), bp->b_blkno (which is an int)
gets set to uio->uio_offset >> 9, which is -4171744 (int). In
bounds_check_with_label(), the usual signed/unsigned comparison
breakage occurs, and bp->b_bcount gets set to 2134972928 (with
p->p_size == 8386733). This broken buf, is later picked up by
sdstart().

>How-To-Repeat:

Try this program on a raw scsi device attached to an Adaptec
controller (I have tried it on 2940AU/UW); read() will never
return. Running this on an (some) IDE controller, read returns EINVAL.

#include <fcntl.h>
#include <unistd.h>
#include <sys/param.h>
#include <err.h>

int
main(int argc, char **argv)
{
    char buf[DEV_BSIZE];
    int fd = open(argv[1], O_RDONLY);
    if(fd < 0)
	err(1, "open");
    /* doesn't work with any negative value here */
    if(lseek(fd, (off_t)0xffffffff80000000LL, SEEK_SET) == (off_t)-1)
	err(1, "lseek");
    if(read(fd, buf, sizeof(buf)) != sizeof(buf))
	err(1, "read");
    close(fd);
    exit(0);
}

>Fix:

Left as an ex[eo]rcise to the reader.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: kern-bug-people->bouyer 
Responsible-Changed-By: bouyer 
Responsible-Changed-When: Thu Dec 3 11:14:10 PST 1998 
Responsible-Changed-Why:  
Sounds like a problem to solve at scsipi level. I'll look at this. 
State-Changed-From-To: open->closed 
State-Changed-By: bouyer 
State-Changed-When: Wed Feb 10 04:37:23 PST 1999 
State-Changed-Why:  
The problem was in the sd driver, which allowed requests with b_blkno < 0. 
Fixed in sd.c, cd.c, st.c and ss.c. 
(fixing this in bounds_check_with_label is not a good idea because it's  
not called for raw partition). 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.