From nobody Sun Apr 28 18:57:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1589195728; cv=none; d=zohomail.com; s=zohoarc; b=lmo7yX3HiOESebQRhH/5Xhrs9SnAj4+e2eb7f6wdF/9/MOVhc5d7CEPGsCiMoEWSKYFIHE5UT3hluJXwZfuo6dRJnqChzSY03DPNNhTvwKnwf4iF9StWf4djrSnVfASIJy4VY478gwqve1VqhOeyzdv6DlUQNp+a2bX70Ck3oEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589195728; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=CJYzYU7Eu4MZyFKm0AFL+JzazZ8FVVFPHj3/2ZKjQVE=; b=g0tupoMGMoiSZVKv1vfqaBXrwodvIf67qcq2+a2Bn4dlmLMLsnQwZCJtECuQVfp7pmJ/KSxDoENwotxtkFxCed0WkIOVjxg3KJfKF/G+R5njBm/NAsjnv1oe9T7dcKGd1JF6RWo2FRy0kw5m9T7caZ7p4KgqMbz/WzJiUqZupHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1589195728597200.45758268003; Mon, 11 May 2020 04:15:28 -0700 (PDT) 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-356-836qUE8PO2ejn-52Om9RAw-1; Mon, 11 May 2020 07:15:24 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6477E879514; Mon, 11 May 2020 11:15:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 368B71001920; Mon, 11 May 2020 11:15:18 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 78AD11809557; Mon, 11 May 2020 11:15:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04BBFGJY018102 for ; Mon, 11 May 2020 07:15:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id F210E5C1D3; Mon, 11 May 2020 11:15:15 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E8D35C1B2 for ; Mon, 11 May 2020 11:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589195726; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=CJYzYU7Eu4MZyFKm0AFL+JzazZ8FVVFPHj3/2ZKjQVE=; b=ZiGhvgS/FyrZq90HvEgaWlv7t586K01lMsFuFVn3yhW+EvH7Qnl/ZTXw43DugkAMMQrxoe p5ctrl79HDKYiAmtjiJRIEqwpiA7Bu6BMG5G8fmzbLG/mjN856j59h9BL42Cv2FZF/HFpW betpMx+xNQ/TJrqXa0Jd6/HhfZdro5E= X-MC-Unique: 836qUE8PO2ejn-52Om9RAw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virDevMapperGetTargetsImpl: quit early if device is not a devmapper target Date: Mon, 11 May 2020 13:15:10 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" As suggested in the linked bug, libvirt should firstly check whether the major number of the device is device mapper major. Because if it isn't subsequent DM_DEVICE_DEPS task may not only fail, but also yield different results. In the bugzilla this is demonstrated by creating a devmapper target named 'loop0' and then creating loop target /dev/loop0. When the latter is then passed to a domain, our virDevMapperGetTargetsImpl() function blindly asks devmapper to provide target dependencies for /dev/loop0 and because of the way devmapper APIs work, it will 'sanitize' the input by using the last component only which is 'loop0' and thus return different results than expected. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1823976 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virdevmapper.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index feb5982315..ee026d502e 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -64,6 +64,7 @@ virDevMapperGetTargetsImpl(const char *path, char ***devPaths_ret, unsigned int ttl) { + struct stat sb; struct dm_task *dmt =3D NULL; struct dm_deps *deps; struct dm_info info; @@ -82,6 +83,15 @@ virDevMapperGetTargetsImpl(const char *path, return ret; } =20 + if (stat(path, &sb) < 0) { + if (errno =3D=3D ENOENT) + ret =3D 0; + return ret; + } + + if (!dm_is_dm_major(major(sb.st_dev))) + return 0; + if (!(dmt =3D dm_task_create(DM_DEVICE_DEPS))) { if (errno =3D=3D ENOENT || errno =3D=3D ENODEV) { /* It's okay. Kernel is probably built without --=20 2.26.2