From nobody Mon Apr 29 11:29:19 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566485551; cv=none; d=zoho.com; s=zohoarc; b=LWhrWqsfgyLKoqQ9sDg235HuYNLbOQIfd4AUehkekfQaK+g+cw/zMBipqrUE5JMCqlvIBX3DCFrsAoc2NNbXV8cJEPBu+MBGnRb7TuQE/p2wf45jLgiJtutS0ZccIvuJW5uGmEootZUAKsIzZ75D8hSVGj5YQOrArExAmiTu9sw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566485551; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=v06YZJ4cQXyJLUOAHq5myYO0Fimn5UzRzcbxzrH5Mgs=; b=bjEJhbFnSIAWfliHo22a72SpjzFxg41SoE08gqxY9ZoBZ9dYI1376cvcxThxf5Okp6eRnPGF/SZcF3z+44xFLBY47sCjweODfNRjreGWaejw/n6SIihjMu4po9d1gNkzXAYtlHNHEk75ECnU5sUoalGCPvLk8niFJyvBkz6QroQ= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566485551029199.71463002510075; Thu, 22 Aug 2019 07:52:31 -0700 (PDT) Received: from localhost ([::1]:44080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0oRx-0005dE-SQ for importer@patchew.org; Thu, 22 Aug 2019 10:52:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34369) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0oHc-00041V-Rp for qemu-devel@nongnu.org; Thu, 22 Aug 2019 10:41:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0oHb-0002lN-9E for qemu-devel@nongnu.org; Thu, 22 Aug 2019 10:41:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38392) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0oHa-0002jd-UQ; Thu, 22 Aug 2019 10:41:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3011C3082A98; Thu, 22 Aug 2019 14:41:46 +0000 (UTC) Received: from x1w.redhat.com (unknown [10.40.205.175]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6EDD15D6A7; Thu, 22 Aug 2019 14:41:42 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: slirp@lists.freedesktop.org Date: Thu, 22 Aug 2019 16:41:33 +0200 Message-Id: <20190822144134.23521-2-philmd@redhat.com> In-Reply-To: <20190822144134.23521-1-philmd@redhat.com> References: <20190822144134.23521-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 22 Aug 2019 14:41:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 1/2] Do not reassemble fragments pointing outside of the original payload 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: , Cc: Petr Matousek , Vishnu Dev TJ , qemu-stable@nongnu.org, qemu-devel@nongnu.org, Prasad J Pandit , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The vulnerability CVE-2019-14378 is well explained in [1]: The bug is triggered when large IPv4 fragmented packets are reassembled for processing. For the NAT translation if the incoming packets are fragmented they should be reassembled before they are edited and re-transmitted. This reassembly is done by the ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp) function. ip contains the current IP packet data, fp is a link list containing the fragmented packets. ip_reass() does the following: * If first fragment to arrive (fp=3D=3DNULL), create a reassembly queue and insert ip into this queue. * Check if the fragment is overlapping with previous received fragments, then discard it. * If all the fragmented packets are received reassemble it. Create header for new ip packet by modifying header of first packet. The bug is at the calculation of the variable delta. The code assumes that the first fragmented packet will not be allocated in the external buffer (m_ext). The calculation q - m->dat is valid when the packet data is inside mbuf->m_dat (q will be inside m_dat) (q is structure containing link list of fragments and packet data). Otherwise if m_ext buffer was allocated, then q will be inside the external buffer and the calculation of the delta will be wrong. Later the newly calculated pointer q is converted into ip structure and values are modified, Due to the wrong calculation of the delta, ip will be pointing to incorrect location and ip_src and ip_dst can be used to write controlled data onto the calculated location. This may also crash qemu if the calculated ip is located in unmaped area. Do not queue fragments pointing out of the original payload to avoid to calculate the variable delta. [1] https://vishnudevtj.github.io/notes/qemu-vm-escape-cve-2019-14378 Fixes: CVE-2019-14378 Reported-by: Vishnu Dev TJ Signed-off-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- src/ip_input.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ip_input.c b/src/ip_input.c index 7364ce0..ee52085 100644 --- a/src/ip_input.c +++ b/src/ip_input.c @@ -304,6 +304,19 @@ static struct ip *ip_reass(Slirp *slirp, struct ip *ip= , struct ipq *fp) ip_deq(q->ipf_prev); } =20 + /* + * If we received the first fragment, we know the original + * payload size. Verify fragments are within our payload. + */ + for (q =3D fp->frag_link.next; q !=3D (struct ipasfrag*)&fp->frag_link; + q =3D q->ipf_next) { + if (!q->ipf_off && q->ipf_len) { + if (ip->ip_off + ip->ip_len >=3D q->ipf_len) { + goto dropfrag; + } + } + } + insert: /* * Stick new segment in its place; --=20 2.20.1 From nobody Mon Apr 29 11:29:19 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; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566485028; cv=none; d=zoho.com; s=zohoarc; b=Y06wNTnY6c6T0QTDvZN3fueEbKIiNB/fx9kW4VHNbKTGMm18xyVNHb3lHqm69+fyvZ6Pzf8TWI+TgE9Nq0HgdR4AMGaIcICPFXa0A7hd5kfkUlMf8JqY5yPEAV45LwUH4PNfQkVbJ/ABRNAndhGQn5+df/Ye5FFaT4Mruaq5sR4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566485028; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LuBF0RzNFrVkslVViIjunLnpqGMWb1qsj9Mo+oXbh4Q=; b=nmShVo9qMI99lgkZJWy4apOPHSIJ4IJmlrzI7pI8ehXbQO5BHZyfAJ17g/8E2ko5jqy0Gwtb43LoH/gGhVik3Q7CQDepjL9/uCA0nDonuTv1AwzJRD9jdzTbJIgxcWuPXQKeKNyx/MhQPHQmiAk/GQUPFGWnn5koJZ70EOTE7Dg= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566485028423317.6330946235746; Thu, 22 Aug 2019 07:43:48 -0700 (PDT) Received: from localhost ([::1]:44016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0oJU-0005r1-NZ for importer@patchew.org; Thu, 22 Aug 2019 10:43:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34424) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0oHf-00045l-3p for qemu-devel@nongnu.org; Thu, 22 Aug 2019 10:41:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0oHe-0002oz-5w for qemu-devel@nongnu.org; Thu, 22 Aug 2019 10:41:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0oHd-0002oD-Vw; Thu, 22 Aug 2019 10:41:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44544308FC4E; Thu, 22 Aug 2019 14:41:49 +0000 (UTC) Received: from x1w.redhat.com (unknown [10.40.205.175]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BECCB5D6A7; Thu, 22 Aug 2019 14:41:46 +0000 (UTC) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: slirp@lists.freedesktop.org Date: Thu, 22 Aug 2019 16:41:34 +0200 Message-Id: <20190822144134.23521-3-philmd@redhat.com> In-Reply-To: <20190822144134.23521-1-philmd@redhat.com> References: <20190822144134.23521-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 22 Aug 2019 14:41:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [RFC PATCH 2/2] Delay crash when mbufs are corrupted 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: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org, Petr Matousek , qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If the mbufs linked list is corrupted, give the application a chance to properly shutdown itself without causing dataloss. For now, this means slowly leaking the heap. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- src/ip_input.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ip_input.c b/src/ip_input.c index ee52085..36962b5 100644 --- a/src/ip_input.c +++ b/src/ip_input.c @@ -185,6 +185,15 @@ void ip_input(struct mbuf *m) if (ip =3D=3D NULL) return; m =3D dtom(slirp, ip); + if (m =3D=3D NULL) { + /* The mbufs linked list is corrupted, we + * should properly shutdown the application. + * We prefer to leak a mbuf on the heap + * rather than allowing null dereference + * and eventual crash (data corruption). + */ + return; /* TODO warn the library consumer! */ + } } else if (fp) ip_freef(slirp, fp); =20 --=20 2.20.1