Date: Fri, 25 Mar 2005 22:02:45 -0700 From: "Kenneth D. Merry" <ken@kdm.org> To: Henry Miller <hank@blackhole.com> Cc: freebsd-scsi@freebsd.org Subject: Re: scsi_ch issues Message-ID: <20050326050245.GA59378@nargothrond.kdm.org> In-Reply-To: <380-220053222163355859@blackhole.com> References: <380-220053222163355859@blackhole.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Mar 22, 2005 at 10:33:55 -0600, Henry Miller wrote: > > 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) { I just checked this in as rev 1.42 of scsi_ch.c in -current. I put in a MFC request for RELENG_5, maybe it'll get in in time for 5.4. Thanks for the fix. Ken -- Kenneth Merry ken@kdm.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050326050245.GA59378>