Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4b57e08 authored by Michal Feix's avatar Michal Feix Committed by Linus Torvalds
Browse files

[PATCH] nbd: Check magic before doing anything else



We should check magic sequence in reply packet before trying to find
request with it's request handle.  This also solves the problem with
"Unexpected reply" message beeing logged, when packet with invalid magic is
received.

Signed-off-by: default avatarMichal Feix <michal@feix.cz>
Acked-by: default avatarPaul Clements <paul.clements@steeleye.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 8e185d83
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -300,6 +300,15 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
				lo->disk->disk_name, result);
		goto harderror;
	}

	if (ntohl(reply.magic) != NBD_REPLY_MAGIC) {
		printk(KERN_ERR "%s: Wrong magic (0x%lx)\n",
				lo->disk->disk_name,
				(unsigned long)ntohl(reply.magic));
		result = -EPROTO;
		goto harderror;
	}

	req = nbd_find_request(lo, reply.handle);
	if (unlikely(IS_ERR(req))) {
		result = PTR_ERR(req);
@@ -312,13 +321,6 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
		goto harderror;
	}

	if (ntohl(reply.magic) != NBD_REPLY_MAGIC) {
		printk(KERN_ERR "%s: Wrong magic (0x%lx)\n",
				lo->disk->disk_name,
				(unsigned long)ntohl(reply.magic));
		result = -EPROTO;
		goto harderror;
	}
	if (ntohl(reply.error)) {
		printk(KERN_ERR "%s: Other side returned error (%d)\n",
				lo->disk->disk_name, ntohl(reply.error));