From patchwork Thu Oct 11 11:24:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 10636559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1CD4B15E2 for ; Thu, 11 Oct 2018 11:44:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AB6F2B170 for ; Thu, 11 Oct 2018 11:44:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2EE92B25C; Thu, 11 Oct 2018 11:44:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9FAAF2B170 for ; Thu, 11 Oct 2018 11:44:02 +0000 (UTC) Received: from localhost ([::1]:33680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAZNp-0004uh-WF for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Oct 2018 07:44:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAZ7O-00087r-HM for qemu-devel@nongnu.org; Thu, 11 Oct 2018 07:27:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAZ7J-0000MW-Ft for qemu-devel@nongnu.org; Thu, 11 Oct 2018 07:27:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45664) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gAZ7F-00007y-Lj for qemu-devel@nongnu.org; Thu, 11 Oct 2018 07:26:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C705830832CE; Thu, 11 Oct 2018 11:26:44 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-220.phx2.redhat.com [10.3.116.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 838306B8E1; Thu, 11 Oct 2018 11:26:39 +0000 (UTC) From: P J P To: QEMU Developers Date: Thu, 11 Oct 2018 16:54:36 +0530 Message-Id: <20181011112436.9305-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 11 Oct 2018 11:26:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] ccid-card-passthru: check buffer size parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , Gerd Hoffmann , Arash TC Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit While reading virtual smart card data, if buffer 'size' is negative it would lead to memory corruption errors. Add check to avoid it. Reported-by: Arash TC Signed-off-by: Prasad J Pandit --- hw/usb/ccid-card-passthru.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 0a6c657228..63ed78f4c6 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -275,6 +275,7 @@ static void ccid_card_vscard_read(void *opaque, const uint8_t *buf, int size) PassthruState *card = opaque; VSCMsgHeader *hdr; + assert(0 <= size && size < VSCARD_IN_SIZE); if (card->vscard_in_pos + size > VSCARD_IN_SIZE) { error_report("no room for data: pos %u + size %d > %" PRId64 "." " dropping connection.",