From nobody Mon Feb 9 05:40:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585142294; cv=none; d=zohomail.com; s=zohoarc; b=VZFagGB4WApSXNlvyhXn3npjUeln/XA5lYCIkQ7bUnDNyD3wU3eGc0lGrlxguFtZPsN8jzLw/JUh0y3o2eCnIKm9xc7U7FBqHMgmByZbhOgwZxIOmUVgrHWXlYn0SR1dC5rNVHqy2IvpJ7nxdl6h3NoFbs51blggM/LGqlT8+q8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585142294; h=Content-Type:Content-Transfer-Encoding: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; bh=umvOk8bwq+bQkl8WN+BspP5KPXkvD7/fipNx/LETqDE=; b=J9g/ZGucnBTFQJ7cAHzLnmoMVDfyVxsgo4Rn+SVd0rs6Jrw2X2JelOssuJrW81fZvk/KfHiziP0vSFgQ5fjcPvOqdxoaLcegLkyJfGc+CllI7QnZCWuy7SVOmpJaMk9nddtI+LGh6sd5BonzJx9NX3dLnXXu9DAz7Q5bZ2+YNwM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass 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 158514229437020.78296000537125; Wed, 25 Mar 2020 06:18:14 -0700 (PDT) Received: from localhost ([::1]:36116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jH5vB-0008Pm-6S for importer@patchew.org; Wed, 25 Mar 2020 09:18:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53030) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jH5tt-0006iV-9N for qemu-devel@nongnu.org; Wed, 25 Mar 2020 09:16:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jH5ts-00069J-8f for qemu-devel@nongnu.org; Wed, 25 Mar 2020 09:16:53 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:36927) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jH5ts-00068M-50 for qemu-devel@nongnu.org; Wed, 25 Mar 2020 09:16:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-jb9rWO4tNNCW1xB_mJtJhA-1; Wed, 25 Mar 2020 09:16:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 800FD1922960; Wed, 25 Mar 2020 13:16:48 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-213.ams2.redhat.com [10.36.114.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC0D35C298; Wed, 25 Mar 2020 13:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585142211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=umvOk8bwq+bQkl8WN+BspP5KPXkvD7/fipNx/LETqDE=; b=GrHr0CoZq3HbuoiUmahSfybxvnCPGaazLEiZrmgncgN+PkkaQDxI8zQy7X9dxZNcruGgSV zga+EHz9DiNkDTYHBgACqDDVJY3M5oweEf12Au0cszzIelPTWjkdToNW0x/PBTqJLjwMHG EL/S5MiymoLNT0kpUjnWoHWH7XizzL4= X-MC-Unique: jb9rWO4tNNCW1xB_mJtJhA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, pannengyuan@huawei.com, maozhongyi@cmss.chinamobile.com, vsementsov@virtuozzo.com, imammedo@redhat.com, philmd@redhat.com Subject: [PULL 5/9] tools/virtiofsd/passthrough_ll: Fix double close() Date: Wed, 25 Mar 2020 13:16:28 +0000 Message-Id: <20200325131632.311034-6-dgilbert@redhat.com> In-Reply-To: <20200325131632.311034-1-dgilbert@redhat.com> References: <20200325131632.311034-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 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" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 On success, the fdopendir() call closes fd. Later on the error path we try to close an already-closed fd. This can lead to use-after-free. Fix by only closing the fd if the fdopendir() call failed. Cc: qemu-stable@nongnu.org Fixes: b39bce121b (add dirp_map to hide lo_dirp pointers) Reported-by: Coverity (CID 1421933 USE_AFTER_FREE) Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20200321120654.7985-1-philmd@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 4f259aac70..4c35c95b25 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -1520,8 +1520,7 @@ out_err: if (d) { if (d->dp) { closedir(d->dp); - } - if (fd !=3D -1) { + } else if (fd !=3D -1) { close(fd); } free(d); --=20 2.25.1