From: Lou Langholtz <ldl@aros.net>
To: Andrew Morton <akpm@digeo.com>,
axboe@suse.de, viro@parcelfarce.linux.theplanet.co.uk,
linux-kernel@vger.kernel.org
Subject: [PATCH] nbd driver 2.5+: fix for incorrect struct bio usage
Date: Sat, 21 Jun 2003 17:09:29 -0600 [thread overview]
Message-ID: <3EF4E5A9.5010802@aros.net> (raw)
In-Reply-To: <20030621151818.081139fc.akpm@digeo.com>
[-- Attachment #1: Type: text/plain, Size: 594 bytes --]
Here's a possible patch #2... I believe the address pointed to by
bio_data(bio) is not always contiguous over the length of bio->bi_size
and was responsible for locking my machine up sometimes. My biggest
reason for apprehension on believeing that I'm 100% correct on this is
that there's still what appears to be a source of memory corruption in
the patchlet modified nbd driver even after this patch. I know the
driver is still not correctly notifying processes of the bytesize on
open but the size reported appears to be big enough. Anyway, thanks for
all of the feedback so far!!!!
[-- Attachment #2: nbd-patch2 --]
[-- Type: text/plain, Size: 2444 bytes --]
diff -urN linux-2.5.72-p1/drivers/block/nbd.c linux-2.5.72-p2/drivers/block/nbd.c
--- linux-2.5.72-p1/drivers/block/nbd.c 2003-06-21 15:30:17.860967573 -0600
+++ linux-2.5.72-p2/drivers/block/nbd.c 2003-06-21 16:42:00.865099598 -0600
@@ -28,7 +28,10 @@
* the transmit lock. <steve@chygwyn.com>
* 02-10-11 Allow hung xmit to be aborted via SIGKILL & various fixes.
* <Paul.Clements@SteelEye.com> <James.Bottomley@SteelEye.com>
- * 03-06-21 Fix memory corruption from module removal. <ldl@aros.net>
+ * 03-06-21 Make nbd work with linux 2.5 block layer code. This fixes memory
+ * corruption from module removal too. <ldl@aros.net>
+ * 03-06-21 Fix incorrect bio struct access that could have lead to memory
+ * corruption on receiving disk data. <ldl@aros.net>
*
* possible FIXME: make set_sock / set_blksize / set_size / do_it one syscall
* why not: would need verify_area and friends, would share yet another
@@ -256,6 +259,12 @@
return NULL;
}
+static inline int sock_recv_bvec(struct socket *sock, struct bio_vec *bvec)
+{
+ return nbd_xmit(0, sock, page_address(bvec->bv_page) + bvec->bv_offset,
+ bvec->bv_len, MSG_WAITALL);
+}
+
#define HARDFAIL( s ) { printk( KERN_ERR "NBD: " s "(result %d)\n", result ); lo->harderror = result; return NULL; }
struct request *nbd_read_stat(struct nbd_device *lo)
/* NULL returned = something went wrong, inform userspace */
@@ -263,10 +272,11 @@
int result;
struct nbd_reply reply;
struct request *req;
+ struct socket *sock = lo->sock;
DEBUG("reading control, ");
reply.magic = 0;
- result = nbd_xmit(0, lo->sock, (char *) &reply, sizeof(reply), MSG_WAITALL);
+ result = nbd_xmit(0, sock, (char *) &reply, sizeof(reply), MSG_WAITALL);
if (result <= 0)
HARDFAIL("Recv control failed.");
req = nbd_find_request(lo, reply.handle);
@@ -280,14 +290,17 @@
FAIL("Other side returned error.");
if (nbd_cmd(req) == NBD_CMD_READ) {
- struct bio *bio = req->bio;
+ int i;
+ struct bio *bio;
DEBUG("data, ");
- do {
- result = nbd_xmit(0, lo->sock, bio_data(bio), bio->bi_size, MSG_WAITALL);
- if (result <= 0)
- HARDFAIL("Recv data failed.");
- bio = bio->bi_next;
- } while(bio);
+ rq_for_each_bio(bio, req) {
+ struct bio_vec *bvec;
+ bio_for_each_segment(bvec, bio, i) {
+ result = sock_recv_bvec(sock, bvec);
+ if (result <= 0)
+ HARDFAIL("Recv data failed.");
+ }
+ }
}
DEBUG("done.\n");
return req;
next prev parent reply other threads:[~2003-06-21 22:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-21 21:48 [PATCH] nbd driver for 2.5+: fix for module removal & new block device layer Lou Langholtz
2003-06-21 22:55 ` viro
2003-06-21 23:16 ` Lou Langholtz
2003-06-22 10:03 ` Jens Axboe
[not found] ` <20030621151818.081139fc.akpm@digeo.com>
2003-06-21 23:09 ` Lou Langholtz [this message]
2003-06-22 8:50 ` [PATCH] nbd driver 2.5+: fix for incorrect struct bio usage Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3EF4E5A9.5010802@aros.net \
--to=ldl@aros.net \
--cc=akpm@digeo.com \
--cc=axboe@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox