From patchwork Thu Aug 24 23:42:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 9921111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4C76D600C5 for ; Thu, 24 Aug 2017 23:43:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C1F820090 for ; Thu, 24 Aug 2017 23:43:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30D0C2022C; Thu, 24 Aug 2017 23:43:32 +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=-6.9 required=2.0 tests=BAYES_00,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 9266D20090 for ; Thu, 24 Aug 2017 23:43:30 +0000 (UTC) Received: from localhost ([::1]:50867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dl1ma-0001W6-6h for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Aug 2017 19:43:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dl1lw-0001Vp-Li for qemu-devel@nongnu.org; Thu, 24 Aug 2017 19:42:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dl1lt-0007ER-Iv for qemu-devel@nongnu.org; Thu, 24 Aug 2017 19:42:48 -0400 Received: from sonata.ens-lyon.org ([140.77.166.138]:59873) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dl1lt-0007Du-Bp for qemu-devel@nongnu.org; Thu, 24 Aug 2017 19:42:45 -0400 Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id E189E200E1; Fri, 25 Aug 2017 01:42:42 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iJB86lhOu7yu; Fri, 25 Aug 2017 01:42:42 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (LFbn-1-16213-205.w86-234.abo.wanadoo.fr [86.234.6.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 8BBCB200DA; Fri, 25 Aug 2017 01:42:42 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.89) (envelope-from ) id 1dl1lp-0003tR-Se; Fri, 25 Aug 2017 01:42:41 +0200 Date: Fri, 25 Aug 2017 01:42:41 +0200 From: Samuel Thibault To: P J P Message-ID: <20170824234241.5cfnuic3lmcea6xc@var.youpi.perso.aquilenet.fr> References: <20170823202728.dsmitbqt7bsezfgq@var.youpi.perso.aquilenet.fr> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Organization: I am not organized User-Agent: NeoMutt/20170113 (1.7.2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 140.77.166.138 Subject: Re: [Qemu-devel] A use-after-free in slirp 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: Jan Kiszka , thuth@redhat.com, wjjzhang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Hello, Thanks for the reproducer you sent me offline. Here is a fix which makes a lot of sense and fixes the reproducer. Could you try it with your whole testcase? Could somebody also review the patch? Samuel commit 1a3a763509fad895c907e6978ea034a5c19ee370 Author: Samuel Thibault Date: Fri Aug 25 01:35:53 2017 +0200 slirp: fix clearing ifq_so from pending packets The if_fastq and if_batchq contain not only packets, but queues of packets for the same socket. When sofree frees a socket, it thus has to clear ifq_so from all the packets from the queues, not only the first. Signed-off-by: Samuel Thibault Acked-by: Philippe Mathieu-Daudé diff --git a/slirp/socket.c b/slirp/socket.c index ecec0295a9..4203b80542 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -66,21 +66,29 @@ void sofree(struct socket *so) { Slirp *slirp = so->slirp; - struct mbuf *ifm; - - for (ifm = (struct mbuf *) slirp->if_fastq.qh_link; - (struct quehead *) ifm != &slirp->if_fastq; - ifm = ifm->ifq_next) { - if (ifm->ifq_so == so) { - ifm->ifq_so = NULL; + struct mbuf *ifq; + + for (ifq = (struct mbuf *) slirp->if_fastq.qh_link; + (struct quehead *) ifq != &slirp->if_fastq; + ifq = ifq->ifq_next) { + if (ifq->ifq_so == so) { + struct mbuf *ifm; + ifq->ifq_so = NULL; + for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) { + ifm->ifq_so = NULL; + } } } - for (ifm = (struct mbuf *) slirp->if_batchq.qh_link; - (struct quehead *) ifm != &slirp->if_batchq; - ifm = ifm->ifq_next) { - if (ifm->ifq_so == so) { - ifm->ifq_so = NULL; + for (ifq = (struct mbuf *) slirp->if_batchq.qh_link; + (struct quehead *) ifq != &slirp->if_batchq; + ifq = ifq->ifq_next) { + if (ifq->ifq_so == so) { + struct mbuf *ifm; + ifq->ifq_so = NULL; + for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) { + ifm->ifq_so = NULL; + } } }