From nobody Mon Feb 9 10:30:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652196031; cv=none; d=zohomail.com; s=zohoarc; b=HJJGxV+ydf64bjEopdE5lOvB6db+ddOtF7sIsYbVD9VWFjPg/Rt1OyZ3JHdhLzM5c7q8zHNsBMraUCcNmcaHabuasLqsn+AlPP2oBmreXNgT7ohLRbhdnquDKUDrUE4Au9VLBIouu5SHuqmroFM2ru8T21YHLJfPNFCySMEiGEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652196031; 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=2uv82aPVNpvWt496u+aBX/4V/GJQj3E+eem4lkdrom8=; b=Pb7cfwW/NMluvJsqOyZfN8xnas3epom3bKW6a3HjPuO+9SRfJc61Sg4jcJ8Qo8gIlbSTUFwhO+DKNGg6eHus8UruahJr3L0vXoiTtcqYQxFkZGsLicaLKT2G5Nu+7FH/KOQNsqjyi+iWvCYK1r5sbvJ1e93uWI9RqDrV9WY2Yaw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1652196031603633.5463568826273; Tue, 10 May 2022 08:20:31 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-283-JOAEObWTP8afHrRom_SLdQ-1; Tue, 10 May 2022 11:20:24 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D1153C8AD0C; Tue, 10 May 2022 15:20:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC5DDC28107; Tue, 10 May 2022 15:20:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 783801947076; Tue, 10 May 2022 15:20:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4171B194706A for ; Tue, 10 May 2022 15:20:17 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 32AFD202699A; Tue, 10 May 2022 15:20:17 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF5842024CBB for ; Tue, 10 May 2022 15:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652196030; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2uv82aPVNpvWt496u+aBX/4V/GJQj3E+eem4lkdrom8=; b=eBZOrdLyTGzGV4Bu97b8RetEfdEgDyCltvHIUB0/ZDhJPQ80+sxbKp7FUcFfvMbndN3GlH O1LtmM25DKkkmExpg2Jld5ohEQiSz05zY7z4gHn+BbUgCHYYj7/LQoDUFX0J2b8Q0rYqgp SpN2RpoIGxF/lgaxrWdJyPH67XWjdGQ= X-MC-Unique: JOAEObWTP8afHrRom_SLdQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/37] qemu_fd: Add validation before transferring file descriptors Date: Tue, 10 May 2022 17:19:38 +0200 Message-Id: <0cffcea59e484877765f836c90e3375243bca32b.1652195735.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652196032066100003 Content-Type: text/plain; charset="utf-8" Add validation to the transfer step to make the adding step more simple for easier cleanup paths. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_fd.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/qemu/qemu_fd.c b/src/qemu/qemu_fd.c index 1af8932bdd..284e77ba2b 100644 --- a/src/qemu/qemu_fd.c +++ b/src/qemu/qemu_fd.c @@ -65,6 +65,30 @@ qemuFDPassFree(qemuFDPass *fdpass) } +static int +qemuFDPassValidate(qemuFDPass *fdpass) +{ + size_t i; + + if (!fdpass->useFDSet && + fdpass->nfds > 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("direct FD passing supports only 1 file descripto= r")); + return -1; + } + + for (i =3D 0; i < fdpass->nfds; i++) { + if (fdpass->fds[i].fd < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("invalid file descriptor")); + return -1; + } + } + + return 0; +} + + /** * qemuFDPassNew: * @prefix: prefix used for naming the passed FDs @@ -186,6 +210,9 @@ qemuFDPassTransferCommand(qemuFDPass *fdpass, if (!fdpass) return 0; + if (qemuFDPassValidate(fdpass) < 0) + return -1; + for (i =3D 0; i < fdpass->nfds; i++) { virCommandPassFD(cmd, fdpass->fds[i].fd, VIR_COMMAND_PASS_FD_CLOSE= _PARENT); @@ -229,6 +256,9 @@ qemuFDPassTransferMonitor(qemuFDPass *fdpass, if (!fdpass) return 0; + if (qemuFDPassValidate(fdpass) < 0) + return -1; + for (i =3D 0; i < fdpass->nfds; i++) { if (fdpass->useFDSet) { qemuMonitorAddFdInfo fdsetinfo; @@ -274,6 +304,9 @@ qemuFDPassTransferMonitorFake(qemuFDPass *fdpass) if (!fdpass) return 0; + if (qemuFDPassValidate(fdpass) < 0) + return -1; + if (fdpass->useFDSet) { fdpass->path =3D g_strdup_printf("/dev/fdset/monitor-fake"); } else { --=20 2.35.1