From nobody Wed May 1 15:37:36 2024 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=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584792476; cv=none; d=zohomail.com; s=zohoarc; b=QxqH9I+ZSm+hxX7k8xC4NPU22jk7qWYuLXvRX2Bf1UyXhNPBm8SrYle9oEPyRIGtQpqEJRbHgn1g0HuT+t0p5MQk4QhbdcToRHnxS+M2ZE4kYZ9SW0rYI86LlFD+kyrvVE0WTnpOUycaHVKXoUJ/2iv57oJJZ4mSH9O61X0TTf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584792476; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=zZrhKz3u83FapzjTI2PhSDcr87b8tpaT6o8iRS52yek=; b=cYjcPp3o/5gSbZgv1UxsLZfqEMESVLxWofM5zkUr7D1weRY0i9J2RX3Q/pURGI3fkYTK1ufkW9j9rkawUTUckpD8HPwFTDHsYRY2mKMZ0nh5I5mhqsbjJLMJOs2HJoJdePI6x6yC3LRppylKIi5Qm7hmW4PwD0+bJmidhcdQPjM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1584792476849792.7034171014504; Sat, 21 Mar 2020 05:07:56 -0700 (PDT) Received: from localhost ([::1]:36112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFcuw-0007BE-U9 for importer@patchew.org; Sat, 21 Mar 2020 08:07:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38733) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFcu7-0006Py-6h for qemu-devel@nongnu.org; Sat, 21 Mar 2020 08:07:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFcu5-0006Zy-8J for qemu-devel@nongnu.org; Sat, 21 Mar 2020 08:07:02 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:23294) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jFcu5-0006ZW-5K for qemu-devel@nongnu.org; Sat, 21 Mar 2020 08:07:01 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-stvARVJmPUm70g1z1mLHeQ-1; Sat, 21 Mar 2020 08:06:59 -0400 Received: by mail-wr1-f69.google.com with SMTP id v7so4246587wrp.0 for ; Sat, 21 Mar 2020 05:06:58 -0700 (PDT) Received: from localhost.localdomain (37.red-83-52-54.dynamicip.rima-tde.net. [83.52.54.37]) by smtp.gmail.com with ESMTPSA id u5sm5450516wrp.81.2020.03.21.05.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 05:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584792420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zZrhKz3u83FapzjTI2PhSDcr87b8tpaT6o8iRS52yek=; b=Pp8jMwCmkKfrJ89F48WtY3DoMhXsubjFCMA5ZVsIk5O0I4klR8lE5nsYpRbkVRM4bXpWAg 2Tyo4fIQw0AEQimgotwJvPNoOaoQQiZc6JlXEn2i/RunZUmUhq6bYFnW2tJKSU5/phseSW B7tjayitoJs23FNFA2x4PS7RVjiOhw4= X-MC-Unique: stvARVJmPUm70g1z1mLHeQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=c+ODi2pX71vXFX/hS6ufzKlC/YUkXmAqowyc+WHVWO4=; b=f/97RlWc857/xQpyEXgtkLuNS0zXZS762C3JPiEMkB9+eR2RUxkJnUOzPb7yokZFNB t5pY0FwLyFMBwxE1KKOEvJIRSDZJK60DQ32j+nVjdAppjynK2hDp1t2kmRAZ5jFN2yJj Qr6DeThh+7FaHfAswV3xS5jNSIr57AY532lEJcxCjSecY+GIEQRKOfEVdqZJuseEV5Oc haeZNDYYP3RXJSpPcI2ot80tlppoqE4o52MdzIKQ7AUA/wopDi17XF7FD06Bo6th5Bud U7LXwFF1DSoHOeftTQWaXHxf98fgMyuCwuYWSkM/gAZP5Kbsw5QZEl9kJJ3nkI3/vPEh 36Bg== X-Gm-Message-State: ANhLgQ0k9sVd7X5IYNI1wYzTRCTttR3wnDwQtYEavXhe7UX3X83ZlaVe 83O2kNVGDYpd82a382E8v3w39syF5e/qcuWLuvmRrYvuhbswxI9qMLXCUzxlU18peNGVTLWCqE8 EtDaUwqKZ+b8bwhY= X-Received: by 2002:a1c:a78a:: with SMTP id q132mr16043930wme.107.1584792417713; Sat, 21 Mar 2020 05:06:57 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsH41NaM0XzEQGhJDWy4Q640I+hQ1/eupWIfpECtSG65DE5nmbN83S3haqU5r7+Tdw381Q71A== X-Received: by 2002:a1c:a78a:: with SMTP id q132mr16043906wme.107.1584792417354; Sat, 21 Mar 2020 05:06:57 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH-for-5.0] tools/virtiofsd/passthrough_ll: Fix double close() Date: Sat, 21 Mar 2020 13:06:54 +0100 Message-Id: <20200321120654.7985-1-philmd@redhat.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 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: , Cc: Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr. David Alan Gilbert" , Stefan Hajnoczi , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" 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: 7c6b66027 (Import passthrough_ll from libfuse fuse-3.8.0) Reported-by: Coverity (CID 1421933 USE_AFTER_FREE) Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- 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.21.1