scsi_ch issues

Henry Miller hank at blackhole.com
Tue Mar 22 08:35:05 PST 2005


I posted a summery of this to -questions earlier this morning (you
can read it there if you want background), I've dug into it more, and
I think there is a bug in  
cam/scsi/scsi_ch.c
function chgetelemstatus.

The short summery is my tape changer says that PVOLTAG in pg_hdr is 
FALSE, (or zeroed latter) in the first request of 
scsi_read_element_status() (which freeBSD uses only to get the length
of the data) on one of my changers, and thus chio(1) will not show
the bar code label.   pg_hdr is not updated to reflect the location
of result of the second call, when this flag is set.  Worse, it looks
like the results of the first call is a dead pointer by the time it
checks anyway.  Unless free/malloc work different in the kernel from
userland this is a problem.

I've sniped out a lot of extra code so you can see what I mean.  


data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK);
  --- Fill data to get size
pg_hdr = \* data + some offset *\
        /*
         * Reallocate storage for descriptors and get them from the
         * device.
         */
        free(data, M_DEVBUF);
        data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK);
  --- Fill data 
copy_element_status(softc, pg_hdr->flags, desc, ces);

Note that pg_hdr is not valid at this point anyway.

This more or less happens in 4.x, 5.x and current if I read the code
correctly.

Can someone who knows kernel code better than I look at this.  
Should I send a pr?

Here is a patch against 4.9 (where I first found this problem) that
might help to understand the fix.  I think it needs to be ported to
all versions.  (and perhaps netbsd if there is where we get the
code?)   


*** scsi_ch.c.old       Tue Mar 22 11:16:15 2005
--- scsi_ch.c   Tue Mar 22 11:09:13 2005
***************
*** 1184,1189 ****
--- 1184,1192 ----
         * Fill in the user status array.
         */
        st_hdr = (struct read_element_status_header *)data;
+         pg_hdr = (struct read_element_status_page_header
*)((uintptr_t)st_hdr
+
+                   sizeof(struct read_element_status_header));
+
        avail = scsi_2btoul(st_hdr->count);

        if (avail != cesr->cesr_element_count) {





More information about the freebsd-scsi mailing list