From nobody Fri Apr 19 18:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531130187988458.9229931030595; Mon, 9 Jul 2018 02:56:27 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A98AE30820D1; Mon, 9 Jul 2018 09:56:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 00BDA1001918; Mon, 9 Jul 2018 09:56:24 +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 53E724A465; Mon, 9 Jul 2018 09:56:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w699uK09001024 for ; Mon, 9 Jul 2018 05:56:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4A03E111E3EB; Mon, 9 Jul 2018 09:56:20 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2E02111E3E8 for ; Mon, 9 Jul 2018 09:56:19 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 11:56:09 +0200 Message-Id: <9861f561a2950b3ce424b8a1770a2619186fc251.1531129992.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/6] qemuBuildSCSIiSCSIHostdevDrvStr: Don't leak @netsource and @srcprops 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 09 Jul 2018 09:56:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" After 6b770f9a3bdabb1 both @netsource and @srcprops are leaked because of early return introduced in the commit. =3D=3D1812=3D=3D 644 bytes in 4 blocks are definitely lost in loss record 8= 35 of 885 =3D=3D1812=3D=3D at 0x4C2F12F: realloc (vg_replace_malloc.c:785) =3D=3D1812=3D=3D by 0x8846393: xmlSaveUriRealloc (in /usr/lib64/libxml2.= so.2.9.8) =3D=3D1812=3D=3D by 0x8846B1C: xmlSaveUri (in /usr/lib64/libxml2.so.2.9.= 8) =3D=3D1812=3D=3D by 0x5DDA619: virURIFormat (viruri.c:256) =3D=3D1812=3D=3D by 0x56E941B: qemuBuildNetworkDriveURI (qemu_command.c:= 781) =3D=3D1812=3D=3D by 0x56E979A: qemuBuildNetworkDriveStr (qemu_command.c:= 859) =3D=3D1812=3D=3D by 0x56F3A0B: qemuBuildSCSIiSCSIHostdevDrvStr (qemu_com= mand.c:4664) =3D=3D1812=3D=3D by 0x56F3D1F: qemuBuildSCSIHostdevDrvStr (qemu_command.= c:4732) =3D=3D1812=3D=3D by 0x56F57F7: qemuBuildHostdevCommandLine (qemu_command= .c:5337) =3D=3D1812=3D=3D by 0x570303A: qemuBuildCommandLine (qemu_command.c:1037= 6) =3D=3D1812=3D=3D by 0x57604EE: qemuProcessCreatePretendCmd (qemu_process= .c:6649) =3D=3D1812=3D=3D by 0x11352A: testCompareXMLToArgv (qemuxml2argvtest.c:5= 66) Signed-off-by: Michal Privoznik --- src/qemu/qemu_command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 32eb59b6ab..86970f3d91 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4644,8 +4644,8 @@ static char * qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev, virQEMUCapsPtr qemuCaps) { + char *ret =3D NULL; virBuffer buf =3D VIR_BUFFER_INITIALIZER; - char *netsource =3D NULL; virJSONValuePtr srcprops =3D NULL; virDomainHostdevSubsysSCSIPtr scsisrc =3D &dev->source.subsys.u.scsi; @@ -4672,13 +4672,13 @@ qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDef= Ptr dev, if (virBufferCheckError(&buf) < 0) goto cleanup; =20 - return virBufferContentAndReset(&buf); + ret =3D virBufferContentAndReset(&buf); =20 cleanup: VIR_FREE(netsource); virJSONValueFree(srcprops); virBufferFreeAndReset(&buf); - return NULL; + return ret; } =20 char * --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 18:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531130208147246.60929513041526; Mon, 9 Jul 2018 02:56:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 865C681DE1; Mon, 9 Jul 2018 09:56:46 +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 4A117177B9; Mon, 9 Jul 2018 09:56:46 +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 EACB91800B6C; Mon, 9 Jul 2018 09:56:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w699uKSG001029 for ; Mon, 9 Jul 2018 05:56:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id DF7B7111E3EB; Mon, 9 Jul 2018 09:56:20 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84520111E3E8 for ; Mon, 9 Jul 2018 09:56:20 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 11:56:10 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/6] qemuxml2argvtest: Don't spawn session daemon 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 09 Jul 2018 09:56:47 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" After f14c37ce4c2ccd111 the cleanup path for qemuBuildInterfaceCommandLine() and qemuBuildNetCommandLine() tries to connect to nwfilter driver in order to tear down any NWFilter that was brought up during cmd line construction. Since we also have negative test cases where errors during cmd line build are expected the cleanup paths are executed and NWFilter removal is attempted. Fortunately, there is another bug that by pure luck prevented us from actually spawning the daemon and thus modifying actual user data. See next commit for explanation. Signed-off-by: Michal Privoznik --- src/driver.h | 2 +- tests/qemuxml2argvmock.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/driver.h b/src/driver.h index 0b1f7a2269..0a0d8facee 100644 --- a/src/driver.h +++ b/src/driver.h @@ -113,7 +113,7 @@ int virDriverLoadModule(const char *name, =20 virConnectPtr virGetConnectInterface(void); virConnectPtr virGetConnectNetwork(void); -virConnectPtr virGetConnectNWFilter(void); +virConnectPtr virGetConnectNWFilter(void) ATTRIBUTE_NOINLINE; virConnectPtr virGetConnectNodeDev(void); virConnectPtr virGetConnectSecret(void); virConnectPtr virGetConnectStorage(void); diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index 4df92cf396..13ccfb855d 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -233,3 +233,10 @@ qemuOpenChrChardevUNIXSocket(const virDomainChrSourceD= ef *dev ATTRIBUTE_UNUSED) abort(); return 1729; } + + +virConnectPtr +virGetConnectNWFilter(void) +{ + return NULL; +} --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 18:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531130208332690.6980838636645; Mon, 9 Jul 2018 02:56:48 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 7DFC93082A3C; Mon, 9 Jul 2018 09:56:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E2A41001918; Mon, 9 Jul 2018 09:56:46 +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 E01EB41091; Mon, 9 Jul 2018 09:56:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w699uL0D001035 for ; Mon, 9 Jul 2018 05:56:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80F8D111E3EB; Mon, 9 Jul 2018 09:56:21 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2591F111E3E8 for ; Mon, 9 Jul 2018 09:56:21 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 11:56:11 +0200 Message-Id: <0ff7874692aec681e563238aaf9ea2af4d46c0de.1531129992.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/6] Forget last daemon/ dir artefacts 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 09 Jul 2018 09:56:47 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The most important part is LIBVIRTD_PATH env var fix. It is used in virFileFindResourceFull() from tests. The libvirtd no longer lives under daemon/. Then, libvirtd-fail test was still failing (as expected) but not because of missing config file but because it was trying to execute (nonexistent) top_builddir/daemon/libvirtd which fulfilled expected outcome and thus test did not fail. Thirdly, lcov was told to generate coverage for daemon/ dir too. Signed-off-by: Michal Privoznik --- Makefile.am | 2 +- run.in | 2 +- tests/libvirtd-fail | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 1926e21b7a..709064c6a6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -80,7 +80,7 @@ check-access: cov: clean-cov $(MKDIR_P) $(top_builddir)/coverage $(LCOV) -c -o $(top_builddir)/coverage/libvirt.info.tmp \ - -d $(top_builddir)/src -d $(top_builddir)/daemon \ + -d $(top_builddir)/src \ -d $(top_builddir)/tests $(LCOV) -r $(top_builddir)/coverage/libvirt.info.tmp \ -o $(top_builddir)/coverage/libvirt.info diff --git a/run.in b/run.in index cbef61a674..06ad54b62b 100644 --- a/run.in +++ b/run.in @@ -63,7 +63,7 @@ export PKG_CONFIG_PATH export LIBVIRT_DRIVER_DIR=3D"$b/src/.libs" export LIBVIRT_LOCK_MANAGER_PLUGIN_DIR=3D"$b/src/.libs" export VIRTLOCKD_PATH=3D"$b/src" -export LIBVIRTD_PATH=3D"$b/daemon" +export LIBVIRTD_PATH=3D"$b/src" =20 # This is a cheap way to find some use-after-free and uninitialized # read problems when using glibc. diff --git a/tests/libvirtd-fail b/tests/libvirtd-fail index 6c61b892cb..f9e927b61f 100755 --- a/tests/libvirtd-fail +++ b/tests/libvirtd-fail @@ -5,12 +5,12 @@ =20 if test "$VERBOSE" =3D yes; then set -x - $abs_top_builddir/daemon/libvirtd --version + $abs_top_builddir/src/libvirtd --version fi =20 fail=3D0 =20 -$abs_top_builddir/daemon/libvirtd --config=3Dno-such-conf --timeout=3D5 2>= log +$abs_top_builddir/src/libvirtd --config=3Dno-such-conf --timeout=3D5 2> log RET=3D$? =20 test "$RET" !=3D "0" && exit 0 || exit 1 --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 18:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531130215525111.24810569271006; Mon, 9 Jul 2018 02:56:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E96FF30820E9; Mon, 9 Jul 2018 09:56:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A789E308BDB4; Mon, 9 Jul 2018 09:56:53 +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 444433FCC3; Mon, 9 Jul 2018 09:56:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w699uMZe001047 for ; Mon, 9 Jul 2018 05:56:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2264A111E3EB; Mon, 9 Jul 2018 09:56:22 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB4A5111E3E8 for ; Mon, 9 Jul 2018 09:56:21 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 11:56:12 +0200 Message-Id: <6383a1dc8c9637d210e047228c9d94fc6d7358aa.1531129992.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/6] virtestmock: Track connect() too 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 09 Jul 2018 09:56:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The aim of this mock is to track if a test doesn't touch anything in live system. Well, connect() definitely falls into that category. Signed-off-by: Michal Privoznik --- tests/virtestmock.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/virtestmock.c b/tests/virtestmock.c index 9b91adec77..654af24a10 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -27,6 +27,10 @@ #include #include #include +#include +#ifdef HAVE_SYS_UN_H +# include +#endif =20 #include "internal.h" #include "configmake.h" @@ -61,6 +65,7 @@ static int (*real_lstat)(const char *path, struct stat *s= b); static int (*real_lstat64)(const char *path, void *sb); static int (*real___lxstat)(int ver, const char *path, struct stat *sb); static int (*real___lxstat64)(int ver, const char *path, void *sb); +static int (*real_connect)(int fd, const struct sockaddr *addr, socklen_t = addrlen); =20 static const char *progname; const char *output; @@ -79,6 +84,7 @@ static void init_syms(void) VIR_MOCK_REAL_INIT_ALT(stat64, __xstat64); VIR_MOCK_REAL_INIT_ALT(lstat, __lxstat); VIR_MOCK_REAL_INIT_ALT(lstat64, __lxstat64); + VIR_MOCK_REAL_INIT(connect); } =20 static void @@ -321,3 +327,19 @@ __lxstat64(int ver, const char *path, struct stat64 *s= b) return real___lxstat64(ver, path, sb); } #endif + + +int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) +{ + init_syms(); + +#ifdef HAVE_SYS_UN_H + if (addrlen =3D=3D sizeof(struct sockaddr_un)) { + struct sockaddr_un *tmp =3D (struct sockaddr_un *) addr; + if (tmp->sun_family =3D=3D AF_UNIX) + checkPath(tmp->sun_path); + } +#endif + + return real_connect(sockfd, addr, addrlen); +} --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 18:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531130187989686.8808398939871; Mon, 9 Jul 2018 02:56:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 134CF811A7; Mon, 9 Jul 2018 09:56:26 +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 A678F2010CBC; Mon, 9 Jul 2018 09:56:25 +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 C508C1800B69; Mon, 9 Jul 2018 09:56:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w699uMNt001054 for ; Mon, 9 Jul 2018 05:56:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id B81D1111E3EB; Mon, 9 Jul 2018 09:56:22 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CEFF111E3E8 for ; Mon, 9 Jul 2018 09:56:22 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 11:56:13 +0200 Message-Id: <02fbdc89a8ae9a64b7b90e1a2e5d00a298ebe6de.1531129992.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/6] check-file-access: Allow specifying action 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 09 Jul 2018 09:56:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The check-file-access.pl script is used to match access list generated by virtestmock against whitelisted rules stored in file_access_whitelist.txt. So far the rules are in form: $path: $progname: $testname This is not sufficient because the rule does not take into account 'action' that caused $path to appear in the list of accessed files. After this commit the rule can be in new form: $path: $action: $progname: $testname where $action is one from ("open", "fopen", "access", "stat", "lstat", "connect"). This way the white list can be fine tuned to allow say access() but not connect(). Signed-off-by: Michal Privoznik --- tests/check-file-access.pl | 32 +++++++++++++++++++++++++++----- tests/file_access_whitelist.txt | 15 ++++++++++----- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/tests/check-file-access.pl b/tests/check-file-access.pl index 977a2bc533..ea0b7a18a2 100755 --- a/tests/check-file-access.pl +++ b/tests/check-file-access.pl @@ -27,18 +27,21 @@ use warnings; my $access_file =3D "test_file_access.txt"; my $whitelist_file =3D "file_access_whitelist.txt"; =20 +my @known_actions =3D ("open", "fopen", "access", "stat", "lstat", "connec= t"); + my @files; my @whitelist; =20 open FILE, "<", $access_file or die "Unable to open $access_file: $!"; while () { chomp; - if (/^(\S*):\s*(\S*)(\s*:\s*(.*))?$/) { + if (/^(\S*):\s*(\S*):\s*(\S*)(\s*:\s*(.*))?$/) { my %rec; ${rec}{path} =3D $1; - ${rec}{progname} =3D $2; - if (defined $4) { - ${rec}{testname} =3D $4; + ${rec}{action} =3D $2; + ${rec}{progname} =3D $3; + if (defined $5) { + ${rec}{testname} =3D $5; } push (@files, \%rec); } else { @@ -52,7 +55,21 @@ while () { chomp; if (/^\s*#.*$/) { # comment + } elsif (/^(\S*):\s*(\S*)(:\s*(\S*)(\s*:\s*(.*))?)?$/ and + grep /^$2$/, @known_actions) { + # $path: $action: $progname: $testname + my %rec; + ${rec}{path} =3D $1; + ${rec}{action} =3D $3; + if (defined $4) { + ${rec}{progname} =3D $4; + } + if (defined $6) { + ${rec}{testname} =3D $6; + } + push (@whitelist, \%rec); } elsif (/^(\S*)(:\s*(\S*)(\s*:\s*(.*))?)?$/) { + # $path: $progname: $testname my %rec; ${rec}{path} =3D $1; if (defined $3) { @@ -79,6 +96,11 @@ for my $file (@files) { next; } =20 + if (defined %${rule}{action} and + not %${file}{action} =3D~ m/^$rule->{action}$/) { + next; + } + if (defined %${rule}{progname} and not %${file}{progname} =3D~ m/^$rule->{progname}$/) { next; @@ -95,7 +117,7 @@ for my $file (@files) { =20 if (not $match) { $error =3D 1; - print "$file->{path}: $file->{progname}"; + print "$file->{path}: $file->{action}: $file->{progname}"; print ": $file->{testname}" if defined %${file}{testname}; print "\n"; } diff --git a/tests/file_access_whitelist.txt b/tests/file_access_whitelist.= txt index 850b28506e..3fb318cbab 100644 --- a/tests/file_access_whitelist.txt +++ b/tests/file_access_whitelist.txt @@ -1,14 +1,17 @@ # This is a whitelist that allows accesses to files not in our # build directory nor source directory. The records are in the -# following format: +# following formats: # # $path: $progname: $testname +# $path: $action: $progname: $testname # -# All these three are evaluated as perl RE. So to allow /dev/sda -# and /dev/sdb, you can just '/dev/sd[a-b]', or to allow +# All these variables are evaluated as perl RE. So to allow +# /dev/sda and /dev/sdb, you can just '/dev/sd[a-b]', or to allow # /proc/$pid/status you can '/proc/\d+/status' and so on. -# Moreover, $progname and $testname can be empty, in which which -# case $path is allowed for all tests. +# Moreover, $action, $progname and $testname can be empty, in which +# which case $path is allowed for all tests. However, $action (if +# specified) must be one of "open", "fopen", "access", "stat", +# "lstat", "connect". =20 /bin/cat: sysinfotest /bin/dirname: sysinfotest: x86 sysinfo @@ -19,5 +22,7 @@ /etc/hosts /proc/\d+/status =20 +/etc/passwd: fopen + # This is just a dummy example, DO NOT USE IT LIKE THAT! .*: nonexistent-test-touching-everything --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 18:13:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531130217302207.5849275343212; Mon, 9 Jul 2018 02:56:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A730461CE; Mon, 9 Jul 2018 09:56:54 +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 8EA303781; Mon, 9 Jul 2018 09:56:54 +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 225AF1800B6B; Mon, 9 Jul 2018 09:56:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w699uNO3001060 for ; Mon, 9 Jul 2018 05:56:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 59084111E3EB; Mon, 9 Jul 2018 09:56:23 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id F263E111E3E8 for ; Mon, 9 Jul 2018 09:56:22 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 11:56:14 +0200 Message-Id: <607834247fce84ce9252d610105bbef4d8db4f66.1531129992.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/6] virtestmock: Track action 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Jul 2018 09:56:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" As advertised in the previous commit, we need the list of accessed files to also contain action that caused the $path to appear on the list. Not only this enables us to fine tune our white list rules it also helps us to see why $path is reported. For instance: /run/user/1000/libvirt/libvirt-sock: connect: qemuxml2argvtest: QEMU XML-= 2-ARGV net-vhostuser-multiq Signed-off-by: Michal Privoznik --- tests/virtestmock.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/tests/virtestmock.c b/tests/virtestmock.c index 654af24a10..25aadf8aea 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -88,7 +88,8 @@ static void init_syms(void) } =20 static void -printFile(const char *file) +printFile(const char *file, + const char *func) { FILE *fp; const char *testname =3D getenv("VIR_TEST_MOCK_TESTNAME"); @@ -116,9 +117,9 @@ printFile(const char *file) } =20 /* Now append the following line into the output file: - * $file: $progname $testname */ + * $file: $progname: $func: $testname */ =20 - fprintf(fp, "%s: %s", file, progname); + fprintf(fp, "%s: %s: %s", file, func, progname); if (testname) fprintf(fp, ": %s", testname); =20 @@ -128,8 +129,12 @@ printFile(const char *file) fclose(fp); } =20 +#define CHECK_PATH(path) \ + checkPath(path, __FUNCTION__) + static void -checkPath(const char *path) +checkPath(const char *path, + const char *func) { char *fullPath =3D NULL; char *relPath =3D NULL; @@ -160,7 +165,7 @@ checkPath(const char *path) =20 if (!STRPREFIX(path, abs_topsrcdir) && !STRPREFIX(path, abs_topbuilddir)) { - printFile(path); + printFile(path, func); } =20 VIR_FREE(crippledPath); @@ -180,7 +185,7 @@ int open(const char *path, int flags, ...) =20 init_syms(); =20 - checkPath(path); + CHECK_PATH(path); =20 if (flags & O_CREAT) { va_list ap; @@ -199,7 +204,7 @@ FILE *fopen(const char *path, const char *mode) { init_syms(); =20 - checkPath(path); + CHECK_PATH(path); =20 return real_fopen(path, mode); } @@ -209,7 +214,7 @@ int access(const char *path, int mode) { init_syms(); =20 - checkPath(path); + CHECK_PATH(path); =20 return real_access(path, mode); } @@ -239,7 +244,7 @@ int stat(const char *path, struct stat *sb) { init_syms(); =20 - checkPath(path); + checkPath(path, "stat"); =20 return real_stat(path, sb); } @@ -250,7 +255,7 @@ int stat64(const char *path, struct stat64 *sb) { init_syms(); =20 - checkPath(path); + checkPath(path, "stat"); =20 return real_stat64(path, sb); } @@ -262,7 +267,7 @@ __xstat(int ver, const char *path, struct stat *sb) { init_syms(); =20 - checkPath(path); + checkPath(path, "stat"); =20 return real___xstat(ver, path, sb); } @@ -274,7 +279,7 @@ __xstat64(int ver, const char *path, struct stat64 *sb) { init_syms(); =20 - checkPath(path); + checkPath(path, "stat"); =20 return real___xstat64(ver, path, sb); } @@ -286,7 +291,7 @@ lstat(const char *path, struct stat *sb) { init_syms(); =20 - checkPath(path); + checkPath(path, "lstat"); =20 return real_lstat(path, sb); } @@ -298,7 +303,7 @@ lstat64(const char *path, struct stat64 *sb) { init_syms(); =20 - checkPath(path); + checkPath(path, "lstat"); =20 return real_lstat64(path, sb); } @@ -310,7 +315,7 @@ __lxstat(int ver, const char *path, struct stat *sb) { init_syms(); =20 - checkPath(path); + checkPath(path, "lstat"); =20 return real___lxstat(ver, path, sb); } @@ -322,7 +327,7 @@ __lxstat64(int ver, const char *path, struct stat64 *sb) { init_syms(); =20 - checkPath(path); + checkPath(path, "lstat"); =20 return real___lxstat64(ver, path, sb); } @@ -337,7 +342,7 @@ int connect(int sockfd, const struct sockaddr *addr, so= cklen_t addrlen) if (addrlen =3D=3D sizeof(struct sockaddr_un)) { struct sockaddr_un *tmp =3D (struct sockaddr_un *) addr; if (tmp->sun_family =3D=3D AF_UNIX) - checkPath(tmp->sun_path); + CHECK_PATH(tmp->sun_path); } #endif =20 --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list