From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479481347113.0343548738955; Mon, 5 Jul 2021 03:04:41 -0700 (PDT) Received: from localhost ([::1]:33648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LSx-0002UO-Un for importer@patchew.org; Mon, 05 Jul 2021 06:04:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRR-0008MR-7D for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25069) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRO-0000mP-9M for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:04 -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-423-_df83Hz3NYSzkvNjo6wItg-1; Mon, 05 Jul 2021 06:03:00 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C9A611084F40; Mon, 5 Jul 2021 10:02:58 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78C8B61093; Mon, 5 Jul 2021 10:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479381; 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: in-reply-to:in-reply-to:references:references; bh=PZsbzidgZY0zaVw9AfdFtK4x8LuhEWW7hh18a5AXJBk=; b=Ghuobef4J6xeCTI//05nl6xM7fE6R4HJmafJ8y2swmEDMX363hvMDoeY5zOgZSynrzpjEw AmlAnr3358y8oquQGvHXC7MPPBEPvlrjSOrI9eH5LplBCAfmIVoLU8KesTqWI47IZPD3kv hAQsDJCi2uZT+UofB60scYoSrfCEwDk= X-MC-Unique: _df83Hz3NYSzkvNjo6wItg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 01/19] tests: migration-test: Add dirty ring test Date: Mon, 5 Jul 2021 11:02:17 +0100 Message-Id: <20210705100235.157093-2-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479491487100002 Content-Type: text/plain; charset="utf-8" From: Peter Xu Add dirty ring test if kernel supports it. Add the dirty ring parameter on source should be mostly enough, but let's change the dest too to make them match always. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Message-Id: <20210615175523.439830-3-peterx@redhat.com> Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- tests/qtest/migration-test.c | 58 ++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 2b028df687..328d6dbe97 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -27,6 +27,10 @@ #include "migration-helpers.h" #include "tests/migration/migration-test.h" =20 +#if defined(__linux__) +#include "linux/kvm.h" +#endif + /* TODO actually test the results and get rid of this */ #define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS_= _)) =20 @@ -467,6 +471,8 @@ typedef struct { bool use_shmem; /* only launch the target process */ bool only_target; + /* Use dirty ring if true; dirty logging otherwise */ + bool use_dirty_ring; char *opts_source; char *opts_target; } MigrateStart; @@ -573,11 +579,13 @@ static int test_migrate_start(QTestState **from, QTes= tState **to, shmem_opts =3D g_strdup(""); } =20 - cmd_source =3D g_strdup_printf("-accel kvm -accel tcg%s%s " + cmd_source =3D g_strdup_printf("-accel kvm%s -accel tcg%s%s " "-name source,debug-threads=3Don " "-m %s " "-serial file:%s/src_serial " "%s %s %s %s", + args->use_dirty_ring ? + ",dirty-ring-size=3D4096" : "", machine_opts ? " -machine " : "", machine_opts ? machine_opts : "", memory_size, tmpfs, @@ -587,12 +595,14 @@ static int test_migrate_start(QTestState **from, QTes= tState **to, *from =3D qtest_init(cmd_source); } =20 - cmd_target =3D g_strdup_printf("-accel kvm -accel tcg%s%s " + cmd_target =3D g_strdup_printf("-accel kvm%s -accel tcg%s%s " "-name target,debug-threads=3Don " "-m %s " "-serial file:%s/dest_serial " "-incoming %s " "%s %s %s %s", + args->use_dirty_ring ? + ",dirty-ring-size=3D4096" : "", machine_opts ? " -machine " : "", machine_opts ? machine_opts : "", memory_size, tmpfs, uri, @@ -785,12 +795,14 @@ static void test_baddest(void) test_migrate_end(from, to, false); } =20 -static void test_precopy_unix(void) +static void test_precopy_unix_common(bool dirty_ring) { g_autofree char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); MigrateStart *args =3D migrate_start_new(); QTestState *from, *to; =20 + args->use_dirty_ring =3D dirty_ring; + if (test_migrate_start(&from, &to, uri, args)) { return; } @@ -825,6 +837,18 @@ static void test_precopy_unix(void) test_migrate_end(from, to, true); } =20 +static void test_precopy_unix(void) +{ + /* Using default dirty logging */ + test_precopy_unix_common(false); +} + +static void test_precopy_unix_dirty_ring(void) +{ + /* Using dirty ring tracking */ + test_precopy_unix_common(true); +} + #if 0 /* Currently upset on aarch64 TCG */ static void test_ignore_shared(void) @@ -1369,6 +1393,29 @@ static void test_multifd_tcp_cancel(void) test_migrate_end(from, to2, true); } =20 +static bool kvm_dirty_ring_supported(void) +{ +#if defined(__linux__) + int ret, kvm_fd =3D open("/dev/kvm", O_RDONLY); + + if (kvm_fd < 0) { + return false; + } + + ret =3D ioctl(kvm_fd, KVM_CHECK_EXTENSION, KVM_CAP_DIRTY_LOG_RING); + close(kvm_fd); + + /* We test with 4096 slots */ + if (ret < 4096) { + return false; + } + + return true; +#else + return false; +#endif +} + int main(int argc, char **argv) { char template[] =3D "/tmp/migration-test-XXXXXX"; @@ -1439,6 +1486,11 @@ int main(int argc, char **argv) qtest_add_func("/migration/multifd/tcp/zstd", test_multifd_tcp_zstd); #endif =20 + if (kvm_dirty_ring_supported()) { + qtest_add_func("/migration/dirty_ring", + test_precopy_unix_dirty_ring); + } + ret =3D g_test_run(); =20 g_assert_cmpint(ret, =3D=3D, 0); --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479637697295.5323055454004; Mon, 5 Jul 2021 03:07:17 -0700 (PDT) Received: from localhost ([::1]:42106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LVU-0008Aw-Ey for importer@patchew.org; Mon, 05 Jul 2021 06:07:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRS-0008On-Sz for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41092) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRR-0000nW-76 for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:06 -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-28-GtPwuD9BOAax47BHEWKU1w-1; Mon, 05 Jul 2021 06:03:02 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F4CD100C610; Mon, 5 Jul 2021 10:03:01 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F56860C0F; Mon, 5 Jul 2021 10:02:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479384; 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: in-reply-to:in-reply-to:references:references; bh=wvQHA93JiGIpz1G0Cyy5ab5xSbhqVWLuEjlIwl7FZ/w=; b=XaF8pzqmBMez48JiciQ09CQYwl5lx8sJR2g0wW4Yv6ccM8g5RUVG31282DKOxrRnKYahWn 9zMTyRu/0T6NQsbyfyOP+abrmH3HrxHYL8HQpSwaViQdczGssz0qGefrO0PuDOFlpV1E+d M965okuhDWMUcIhDs2SxWJjuTiRtsxs= X-MC-Unique: GtPwuD9BOAax47BHEWKU1w-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 02/19] migration: fix the memory overwriting risk in add_to_iovec Date: Mon, 5 Jul 2021 11:02:18 +0100 Message-Id: <20210705100235.157093-3-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479639277100001 Content-Type: text/plain; charset="utf-8" From: Feng Lin When testing migration, a Segmentation fault qemu core is generated. 0 error_free (err=3D0x1) 1 0x00007f8b862df647 in qemu_fclose (f=3Df@entry=3D0x55e06c247640) 2 0x00007f8b8516d59a in migrate_fd_cleanup (s=3Ds@entry=3D0x55e06c0e1ef0) 3 0x00007f8b8516d66c in migrate_fd_cleanup_bh (opaque=3D0x55e06c0e1ef0) 4 0x00007f8b8626a47f in aio_bh_poll (ctx=3Dctx@entry=3D0x55e06b5a16d0) 5 0x00007f8b8626e71f in aio_dispatch (ctx=3D0x55e06b5a16d0) 6 0x00007f8b8626a33d in aio_ctx_dispatch (source=3D, callba= ck=3D, user_data=3D) 7 0x00007f8b866bdba4 in g_main_context_dispatch () 8 0x00007f8b8626cde9 in glib_pollfds_poll () 9 0x00007f8b8626ce62 in os_host_main_loop_wait (timeout=3D) 10 0x00007f8b8626cffd in main_loop_wait (nonblocking=3Dnonblocking@entry=3D= 0) 11 0x00007f8b862ef01f in main_loop () Using gdb print the struct QEMUFile f =3D { ..., iovcnt =3D 65, last_error =3D 21984, last_error_obj =3D 0x1, shutdown =3D true } Well iovcnt is overflow, because the max size of MAX_IOV_SIZE is 64. struct QEMUFile { ...; struct iovec iov[MAX_IOV_SIZE]; unsigned int iovcnt; int last_error; Error *last_error_obj; bool shutdown; }; iovcnt and last_error is overwrited by add_to_iovec(). Right now, add_to_iovec() increase iovcnt before check the limit. And it seems that add_to_iovec() assumes that iovcnt will set to zero in qemu_fflush(). But qemu_fflush() will directly return when f->shutdown is true. The situation may occur when libvirtd restart during migration, after f->shutdown is set, before calling qemu_file_set_error() in qemu_file_shutdown(). So the safiest way is checking the iovcnt before increasing it. Signed-off-by: Feng Lin Message-Id: <20210625062138.1899-1-linfeng23@huawei.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert Fix typo in 'writeable' which is actually misnamed 'writable' --- migration/qemu-file.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index d6e03dbc0e..1eacf9e831 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -416,6 +416,11 @@ static int add_to_iovec(QEMUFile *f, const uint8_t *bu= f, size_t size, { f->iov[f->iovcnt - 1].iov_len +=3D size; } else { + if (f->iovcnt >=3D MAX_IOV_SIZE) { + /* Should only happen if a previous fflush failed */ + assert(f->shutdown || !qemu_file_is_writable(f)); + return 1; + } if (may_free) { set_bit(f->iovcnt, f->may_free); } --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479846950328.0362187070623; Mon, 5 Jul 2021 03:10:46 -0700 (PDT) Received: from localhost ([::1]:50636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LYr-0005Qp-HY for importer@patchew.org; Mon, 05 Jul 2021 06:10:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRh-0000e7-VL for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32721) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRf-0000zc-4y for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:20 -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-551-H8GybJ_sNoWyx4HxujMH1w-1; Mon, 05 Jul 2021 06:03:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EAB92100C611; Mon, 5 Jul 2021 10:03:15 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAF3360C0F; Mon, 5 Jul 2021 10:03:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479398; 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: in-reply-to:in-reply-to:references:references; bh=bWSVkaQLg9fnLysApXUXsqjRYe9B5EjHAPM+SLaUhmg=; b=GuIFTLd/ZAf3qrnPnKqOF5f6TOawuWGQ9k5idzNdTC2tnBkG2YAw/CiHXmNlw4q5UdXhOW suNCPSPS9LKPzaKozbVreQ+WO321jwEuolalqYNOrUFYvf26FCOZPEY3JqEjLCTmY9BYoX jprsHxApzJNaSF30VAM9npYNPd3a6FU= X-MC-Unique: H8GybJ_sNoWyx4HxujMH1w-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 03/19] migration: Move yank outside qemu_start_incoming_migration() Date: Mon, 5 Jul 2021 11:02:19 +0100 Message-Id: <20210705100235.157093-4-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479848803100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Starting from commit b5eea99ec2f5c, qmp_migrate_recover() calls unregister before calling qemu_start_incoming_migration(). I believe it wanted to miti= gate the next call to yank_register_instance(), but I think that's wrong. Firstly, if during recover, we should keep the yank instance there, not "quickly removing and adding it back". Meanwhile, calling qmp_migrate_recover() twice with b5eea99ec2f5c will dire= ctly crash the dest qemu (right now it can't; but it'll start to work right after the next patch) because the 1st call of qmp_migrate_recover() will unregist= er permanently when the channel failed to establish, then the 2nd call of qmp_migrate_recover() crashes at yank_unregister_instance(). This patch fixes it by moving yank ops out of qemu_start_incoming_migration= () into qmp_migrate_incoming. For qmp_migrate_recover(), drop the unregister = of yank instance too since we keep it there during the recovery phase. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210629181356.217312-2-peterx@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 4228635d18..1bb03d1eca 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -456,10 +456,6 @@ static void qemu_start_incoming_migration(const char *= uri, Error **errp) { const char *p =3D NULL; =20 - if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { - return; - } - qapi_event_send_migration(MIGRATION_STATUS_SETUP); if (strstart(uri, "tcp:", &p) || strstart(uri, "unix:", NULL) || @@ -474,7 +470,6 @@ static void qemu_start_incoming_migration(const char *u= ri, Error **errp) } else if (strstart(uri, "fd:", &p)) { fd_start_incoming_migration(p, errp); } else { - yank_unregister_instance(MIGRATION_YANK_INSTANCE); error_setg(errp, "unknown migration protocol: %s", uri); } } @@ -2083,9 +2078,14 @@ void qmp_migrate_incoming(const char *uri, Error **e= rrp) return; } =20 + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { + return; + } + qemu_start_incoming_migration(uri, &local_err); =20 if (local_err) { + yank_unregister_instance(MIGRATION_YANK_INSTANCE); error_propagate(errp, local_err); return; } @@ -2114,7 +2114,6 @@ void qmp_migrate_recover(const char *uri, Error **err= p) * only re-setup the migration stream and poke existing migration * to continue using that newly established channel. */ - yank_unregister_instance(MIGRATION_YANK_INSTANCE); qemu_start_incoming_migration(uri, errp); } =20 --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162547966605220.388438114460882; Mon, 5 Jul 2021 03:07:46 -0700 (PDT) Received: from localhost ([::1]:43760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LVw-0000t4-TK for importer@patchew.org; Mon, 05 Jul 2021 06:07:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRn-0000fj-2h for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21609) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRh-00011Z-T2 for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:26 -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-596-TkG2FAjePiSltEIoLGtplA-1; Mon, 05 Jul 2021 06:03:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F73A802C80; Mon, 5 Jul 2021 10:03:18 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43E4D60C0F; Mon, 5 Jul 2021 10:03:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479401; 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: in-reply-to:in-reply-to:references:references; bh=pPYfbcJSRE2nAtqT3UIEYmJJfgrlp488u56cgx+7PJ4=; b=OuriajK9+ni0LICa737S/ka4oivlOMXGtkn2un7xC/TCTW+H2P/5s7Hc6lDlNZ26aF8NKV c3PirXcfsZKUVC2k1NY8FIGRgnZj1a/hgJgRo/dYhxKw0aTI/TXC+peLIzSCVZ+Puf0D+K fex0NBcGxqjiIfn/uk87IM23nefj+cM= X-MC-Unique: TkG2FAjePiSltEIoLGtplA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 04/19] migration: Allow reset of postcopy_recover_triggered when failed Date: Mon, 5 Jul 2021 11:02:20 +0100 Message-Id: <20210705100235.157093-5-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479667072100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu It's possible qemu_start_incoming_migration() failed at any point, when it happens we should reset postcopy_recover_triggered to false so that the user can still retry with a saner incoming port. Signed-off-by: Peter Xu Message-Id: <20210629181356.217312-3-peterx@redhat.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 1bb03d1eca..fcca289ef7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2097,6 +2097,13 @@ void qmp_migrate_recover(const char *uri, Error **er= rp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 + /* + * Don't even bother to use ERRP_GUARD() as it _must_ always be set by + * callers (no one should ignore a recover failure); if there is, it's= a + * programming error. + */ + assert(errp); + if (mis->state !=3D MIGRATION_STATUS_POSTCOPY_PAUSED) { error_setg(errp, "Migrate recover can only be run " "when postcopy is paused."); @@ -2115,6 +2122,12 @@ void qmp_migrate_recover(const char *uri, Error **er= rp) * to continue using that newly established channel. */ qemu_start_incoming_migration(uri, errp); + + /* Safe to dereference with the assert above */ + if (*errp) { + /* Reset the flag so user could still retry */ + qatomic_set(&mis->postcopy_recover_triggered, false); + } } =20 void qmp_migrate_pause(Error **errp) --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16254794987981013.3313733533046; Mon, 5 Jul 2021 03:04:58 -0700 (PDT) Received: from localhost ([::1]:35208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LTF-0003Wa-NH for importer@patchew.org; Mon, 05 Jul 2021 06:04:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRu-0000hR-Qb for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45406) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRl-00012w-2p for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:30 -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-44-kvul9w8AOISQ-ASJ1H_ZWw-1; Mon, 05 Jul 2021 06:03:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3AAE280430C; Mon, 5 Jul 2021 10:03:21 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBF7060C0F; Mon, 5 Jul 2021 10:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479403; 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: in-reply-to:in-reply-to:references:references; bh=C6Mj+rinVIX7Eq3M97XvTePIm+MUp2suc069axeUI8M=; b=Zm4BXtCeyyGo50yx3RwR0HYrcmgI2TD/I7uH+nQhIW9wM5NsccznpNWLNSD6CmBcgi7FAF pmvnlRxoQq0pSpCldKPF9U0/1pvdRCuJbZmFhZ05EXpnb6AXOp/tPZY4rRjFYkVK7CFfA1 rjge7YrkROOOKn1FC9kTFmPK/0fHMeI= X-MC-Unique: kvul9w8AOISQ-ASJ1H_ZWw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 05/19] migration: move wait-unplug loop to its own function Date: Mon, 5 Jul 2021 11:02:21 +0100 Message-Id: <20210705100235.157093-6-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479503394100001 Content-Type: text/plain; charset="utf-8" From: Laurent Vivier The loop is used in migration_thread() and bg_migration_thread(), so we can move it to its own function and call it from these both places. Moreover, in migration_thread() we have a wrong state transition from SETUP to ACTIVE while state could be WAIT_UNPLUG. This is correctly managed in bg_migration_thread() so use this code instead. Signed-off-by: Laurent Vivier Message-Id: <20210629155007.629086-2-lvivier@redhat.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 54 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index fcca289ef7..dbc484c802 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3676,6 +3676,28 @@ bool migration_rate_limit(void) return urgent; } =20 +/* + * if failover devices are present, wait they are completely + * unplugged + */ + +static void qemu_savevm_wait_unplug(MigrationState *s, int old_state, + int new_state) +{ + if (qemu_savevm_state_guest_unplug_pending()) { + migrate_set_state(&s->state, old_state, MIGRATION_STATUS_WAIT_UNPL= UG); + + while (s->state =3D=3D MIGRATION_STATUS_WAIT_UNPLUG && + qemu_savevm_state_guest_unplug_pending()) { + qemu_sem_timedwait(&s->wait_unplug_sem, 250); + } + + migrate_set_state(&s->state, MIGRATION_STATUS_WAIT_UNPLUG, new_sta= te); + } else { + migrate_set_state(&s->state, old_state, new_state); + } +} + /* * Master migration thread on the source VM. * It drives the migration and pumps the data down the outgoing channel. @@ -3722,22 +3744,10 @@ static void *migration_thread(void *opaque) =20 qemu_savevm_state_setup(s->to_dst_file); =20 - if (qemu_savevm_state_guest_unplug_pending()) { - migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, - MIGRATION_STATUS_WAIT_UNPLUG); - - while (s->state =3D=3D MIGRATION_STATUS_WAIT_UNPLUG && - qemu_savevm_state_guest_unplug_pending()) { - qemu_sem_timedwait(&s->wait_unplug_sem, 250); - } - - migrate_set_state(&s->state, MIGRATION_STATUS_WAIT_UNPLUG, - MIGRATION_STATUS_ACTIVE); - } + qemu_savevm_wait_unplug(s, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_ACTIVE); =20 s->setup_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; - migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, - MIGRATION_STATUS_ACTIVE); =20 trace_migration_thread_setup_complete(); =20 @@ -3845,21 +3855,9 @@ static void *bg_migration_thread(void *opaque) qemu_savevm_state_header(s->to_dst_file); qemu_savevm_state_setup(s->to_dst_file); =20 - if (qemu_savevm_state_guest_unplug_pending()) { - migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, - MIGRATION_STATUS_WAIT_UNPLUG); - - while (s->state =3D=3D MIGRATION_STATUS_WAIT_UNPLUG && - qemu_savevm_state_guest_unplug_pending()) { - qemu_sem_timedwait(&s->wait_unplug_sem, 250); - } + qemu_savevm_wait_unplug(s, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_ACTIVE); =20 - migrate_set_state(&s->state, MIGRATION_STATUS_WAIT_UNPLUG, - MIGRATION_STATUS_ACTIVE); - } else { - migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, - MIGRATION_STATUS_ACTIVE); - } s->setup_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; =20 trace_migration_thread_setup_complete(); --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479882724222.84015804670696; Mon, 5 Jul 2021 03:11:22 -0700 (PDT) Received: from localhost ([::1]:52316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LZR-0006dC-EX for importer@patchew.org; Mon, 05 Jul 2021 06:11:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRu-0000he-SR for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30444) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LRn-00014C-IZ for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:34 -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-65-0FvtCL4hPoWdk7G_vD2WcQ-1; Mon, 05 Jul 2021 06:03:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F22EA8018A7; Mon, 5 Jul 2021 10:03:23 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85EC360C0F; Mon, 5 Jul 2021 10:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479406; 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: in-reply-to:in-reply-to:references:references; bh=BEQbkL5PEeq7gAgk/MM/YqgfMkjP8R1PG79qBME4fkU=; b=BuZMBn7+eExlqSp+hLDtU+SAPceLcblIPTTzGiHIq5CyNyMBkMAbsx3l4UrQGdkKdbmrNu +Hrtxbc6cx14UPazEp7B06esNa/D49A9FATJa7fLOp8nExRr/20TVY+6gfxIgtD0PWyFiZ pblvmxt6Ou5Pg6BjKTlWxc/t/GL5bfU= X-MC-Unique: 0FvtCL4hPoWdk7G_vD2WcQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 06/19] migration: failover: continue to wait card unplug on error Date: Mon, 5 Jul 2021 11:02:22 +0100 Message-Id: <20210705100235.157093-7-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479883625100001 Content-Type: text/plain; charset="utf-8" From: Laurent Vivier If the user cancels the migration in the unplug-wait state, QEMU will try to plug back the card and this fails because the card is partially unplugged. To avoid the problem, continue to wait the card unplug, but to allow the migration to be canceled if the card never finishes to unplug use a timeout. Bug: https://bugzilla.redhat.com/show_bug.cgi?id=3D1976852 Signed-off-by: Laurent Vivier Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210629155007.629086-3-lvivier@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index dbc484c802..5ff7ba9d5c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3691,6 +3691,17 @@ static void qemu_savevm_wait_unplug(MigrationState *= s, int old_state, qemu_savevm_state_guest_unplug_pending()) { qemu_sem_timedwait(&s->wait_unplug_sem, 250); } + if (s->state !=3D MIGRATION_STATUS_WAIT_UNPLUG) { + int timeout =3D 120; /* 30 seconds */ + /* + * migration has been canceled + * but as we have started an unplug we must wait the end + * to be able to plug back the card + */ + while (timeout-- && qemu_savevm_state_guest_unplug_pending()) { + qemu_sem_timedwait(&s->wait_unplug_sem, 250); + } + } =20 migrate_set_state(&s->state, MIGRATION_STATUS_WAIT_UNPLUG, new_sta= te); } else { --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479981661444.27304973344076; Mon, 5 Jul 2021 03:13:01 -0700 (PDT) Received: from localhost ([::1]:59546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0Lb2-00030c-JR for importer@patchew.org; Mon, 05 Jul 2021 06:13:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LS6-00012w-TN for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43928) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LS1-000186-3C for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:46 -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-298-9RLR5am3NFSqDbVEtl3Rxg-1; Mon, 05 Jul 2021 06:03:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 292191835AC3; Mon, 5 Jul 2021 10:03:37 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C7A760C0F; Mon, 5 Jul 2021 10:03:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479419; 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: in-reply-to:in-reply-to:references:references; bh=zoKhpUuiY+tW/MIokd2pOT+nKwF7gHjwHqcpMCtK4Mg=; b=RyLW/apNb1SAmVz+p++mSMMKk3L4xh+ZGHQmkLfcFzdvVgES4YnwPS9G503vfXo8SjXWcg o4oGYPGHdHxObgnXPVzTRY6gkDIqc2BlwXnMq5TrXV5ReZhawQ8RAHUqno82tzSCl4ZgaA Ea8rEIDHr4rocpH4tX2SgbTxYHZKwos= X-MC-Unique: 9RLR5am3NFSqDbVEtl3Rxg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 07/19] virtiofsd: use GDateTime for formatting timestamp for debug messages Date: Mon, 5 Jul 2021 11:02:23 +0100 Message-Id: <20210705100235.157093-8-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479982771100001 From: Daniel P. Berrang=C3=A9 The GDateTime APIs provided by GLib avoid portability pitfalls, such as some platforms where 'struct timeval.tv_sec' field is still 'long' instead of 'time_t'. When combined with automatic cleanup, GDateTime often results in simpler code too. Localtime is changed to UTC to avoid the need to grant extra seccomp permissions for GLib's access of the timezone database. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210611164319.67762-1-berrange@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 49c21fd855..9858e961d9 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -3559,10 +3559,6 @@ static void setup_nofile_rlimit(unsigned long rlimit= _nofile) static void log_func(enum fuse_log_level level, const char *fmt, va_list a= p) { g_autofree char *localfmt =3D NULL; - struct timespec ts; - struct tm tm; - char sec_fmt[sizeof "2020-12-07 18:17:54"]; - char zone_fmt[sizeof "+0100"]; =20 if (current_log_level < level) { return; @@ -3574,23 +3570,10 @@ static void log_func(enum fuse_log_level level, con= st char *fmt, va_list ap) localfmt =3D g_strdup_printf("[ID: %08ld] %s", syscall(__NR_ge= ttid), fmt); } else { - /* try formatting a broken-down timestamp */ - if (clock_gettime(CLOCK_REALTIME, &ts) !=3D -1 && - localtime_r(&ts.tv_sec, &tm) !=3D NULL && - strftime(sec_fmt, sizeof sec_fmt, "%Y-%m-%d %H:%M:%S", - &tm) !=3D 0 && - strftime(zone_fmt, sizeof zone_fmt, "%z", &tm) !=3D 0) { - localfmt =3D g_strdup_printf("[%s.%02ld%s] [ID: %08ld] %s", - sec_fmt, - ts.tv_nsec / (10L * 1000 * 1000= ), - zone_fmt, syscall(__NR_gettid), - fmt); - } else { - /* fall back to a flat timestamp */ - localfmt =3D g_strdup_printf("[%" PRId64 "] [ID: %08ld] %s= ", - get_clock(), syscall(__NR_getti= d), - fmt); - } + g_autoptr(GDateTime) now =3D g_date_time_new_now_utc(); + g_autofree char *nowstr =3D g_date_time_format(now, "%Y-%m-%d = %H:%M:%S.%f%z"); + localfmt =3D g_strdup_printf("[%s] [ID: %08ld] %s", + nowstr, syscall(__NR_gettid), fmt); } fmt =3D localfmt; } --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479682897538.8478721003873; Mon, 5 Jul 2021 03:08:02 -0700 (PDT) Received: from localhost ([::1]:43938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LWD-00010N-Qt for importer@patchew.org; Mon, 05 Jul 2021 06:08:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LS8-000190-BO for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LS3-00018H-Lu for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:48 -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-190-CzuGJXd1M-KBf3GMZQGGgA-1; Mon, 05 Jul 2021 06:03:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BCE39802C88; Mon, 5 Jul 2021 10:03:39 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7516660C0F; Mon, 5 Jul 2021 10:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479422; 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: in-reply-to:in-reply-to:references:references; bh=/XhfYA2g9RCN4drP8vUJy7C+n2pp9jT/Q4HuQU/E7dQ=; b=ZJFZZFTskks4KnbHJgC8GOucEZHSPEmQ7it28CvsvYE/l7kIsMT/PI3CCEx0BSKqUuYMSP PmEIwRT60/0oEwwr3+HFvOu66rQLp0zGDBn8uwUjjo+vlap2O5fFV6R1qfxnK3KGUAdZd2 5k0xiK2LfnGXBLMLHoef6tPmsJaayIE= X-MC-Unique: CzuGJXd1M-KBf3GMZQGGgA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 08/19] docs: describe the security considerations with virtiofsd xattr mapping Date: Mon, 5 Jul 2021 11:02:24 +0100 Message-Id: <20210705100235.157093-9-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479684000100001 From: Daniel P. Berrang=C3=A9 Different guest xattr prefixes have distinct access control rules applied by the guest. When remapping a guest xattr care must be taken that the remapping does not allow the a guest user to bypass guest kernel access control rules. For example if 'trusted.*' which requires CAP_SYS_ADMIN is remapped to 'user.virtiofs.trusted.*', an unprivileged guest user which can write to 'user.*' can bypass the CAP_SYS_ADMIN control. Thus the target of any remapping must be explicitly blocked from read/writes by the guest, to prevent access control bypass. The examples shown in the virtiofsd man page already do the right thing and ensure safety, but the security implications of getting this wrong were not made explicit. This could lead to host admins and apps unwittingly creating insecure configurations. Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20210611120427.49736-1-berrange@redhat.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- docs/tools/virtiofsd.rst | 55 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index 4911e797cb..a6c3502710 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -127,8 +127,8 @@ Options timeout. ``always`` sets a long cache lifetime at the expense of cohere= ncy. The default is ``auto``. =20 -xattr-mapping -------------- +Extended attribute (xattr) mapping +---------------------------------- =20 By default the name of xattr's used by the client are passed through to th= e server file system. This can be a problem where either those xattr names are used @@ -136,6 +136,9 @@ by something on the server (e.g. selinux client/server = confusion) or if the virtiofsd is running in a container with restricted privileges where it ca= nnot access some attributes. =20 +Mapping syntax +~~~~~~~~~~~~~~ + A mapping of xattr names can be made using -o xattrmap=3Dmapping where the= ``mapping`` string consists of a series of rules. =20 @@ -232,8 +235,48 @@ Note: When the 'security.capability' xattr is remapped= , the daemon has to do extra work to remove it during many operations, which the host kernel norm= ally does itself. =20 -xattr-mapping Examples ----------------------- +Security considerations +~~~~~~~~~~~~~~~~~~~~~~~ + +Operating systems typically partition the xattr namespace using +well defined name prefixes. Each partition may have different +access controls applied. For example, on Linux there are multiple +partitions + + * ``system.*`` - access varies depending on attribute & filesystem + * ``security.*`` - only processes with CAP_SYS_ADMIN + * ``trusted.*`` - only processes with CAP_SYS_ADMIN + * ``user.*`` - any process granted by file permissions / ownership + +While other OS such as FreeBSD have different name prefixes +and access control rules. + +When remapping attributes on the host, it is important to +ensure that the remapping does not allow a guest user to +evade the guest access control rules. + +Consider if ``trusted.*`` from the guest was remapped to +``user.virtiofs.trusted*`` in the host. An unprivileged +user in a Linux guest has the ability to write to xattrs +under ``user.*``. Thus the user can evade the access +control restriction on ``trusted.*`` by instead writing +to ``user.virtiofs.trusted.*``. + +As noted above, the partitions used and access controls +applied, will vary across guest OS, so it is not wise to +try to predict what the guest OS will use. + +The simplest way to avoid an insecure configuration is +to remap all xattrs at once, to a given fixed prefix. +This is shown in example (1) below. + +If selectively mapping only a subset of xattr prefixes, +then rules must be added to explicitly block direct +access to the target of the remapping. This is shown +in example (2) below. + +Mapping examples +~~~~~~~~~~~~~~~~ =20 1) Prefix all attributes with 'user.virtiofs.' =20 @@ -271,7 +314,9 @@ stripping of 'user.virtiofs.'. The second rule hides unprefixed 'trusted.' attributes on the host. The third rule stops a guest from explicitly setting -the 'user.virtiofs.' path directly. +the 'user.virtiofs.' path directly to prevent access +control bypass on the target of the earlier prefix +remapping. Finally, the fourth rule lets all remaining attributes through. =20 --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479964797938.5659239589484; Mon, 5 Jul 2021 03:12:44 -0700 (PDT) Received: from localhost ([::1]:58642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0Lal-0002Qm-KU for importer@patchew.org; Mon, 05 Jul 2021 06:12:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSA-0001KS-Tm for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40133) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LS8-0001BF-26 for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:03:50 -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-562-L0w6WDp2M9yKKhced1Rk0w-1; Mon, 05 Jul 2021 06:03:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2091B1835AC3; Mon, 5 Jul 2021 10:03:45 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1334260C0F; Mon, 5 Jul 2021 10:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479427; 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: in-reply-to:in-reply-to:references:references; bh=bsA2HH6yfLKkqV4WkmgRRh9p9oulko4q1HRmnuira8c=; b=WISnk+8g7iyyXj56kP89sPp5YO/qhnimwaQNcgaEMEWH3xiBEb6qA5VAp3LKleYzqbH5qM 06yqvnF46TM3OtroZpYYQDw8OH6I4kMlrSpSvcEAz6xsfLq/3b8oVwacKinFNZC+5mdSpa MJWpsjeqC+benjf8RvZ7x5JzD3e5kyU= X-MC-Unique: L0w6WDp2M9yKKhced1Rk0w-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 09/19] virtiofsd: Don't allow file creation with FUSE_OPEN Date: Mon, 5 Jul 2021 11:02:25 +0100 Message-Id: <20210705100235.157093-10-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479966006100001 Content-Type: text/plain; charset="utf-8" From: Greg Kurz A well behaved FUSE client uses FUSE_CREATE to create files. It isn't supposed to pass O_CREAT along a FUSE_OPEN request, as documented in the "fuse_lowlevel.h" header : /** * Open a file * * Open flags are available in fi->flags. The following rules * apply. * * - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be * filtered out / handled by the kernel. But if the client happens to do it anyway, the server ends up passing this flag to open() without the mandatory mode_t 4th argument. Since open() is a variadic function, glibc will happily pass whatever it finds on the stack to the syscall. If this file is compiled with -D_FORTIFY_SOURCE=3D2, glibc will even detect that and abort: *** invalid openat64 call: O_CREAT or O_TMPFILE without mode ***: terminated Specifying O_CREAT with FUSE_OPEN is a protocol violation. Check this in do_open(), print out a message and return an error to the client, EINVAL like we already do when fuse_mbuf_iter_advance() fails. The FUSE filesystem doesn't currently support O_TMPFILE, but the very same would happen if O_TMPFILE was passed in a FUSE_OPEN request. Check that as well. Signed-off-by: Greg Kurz Message-Id: <20210624101809.48032-1-groug@kaod.org> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 7fe2cef1eb..3d725bcba2 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -1084,6 +1084,12 @@ static void do_open(fuse_req_t req, fuse_ino_t nodei= d, return; } =20 + /* File creation is handled by do_create() or do_mknod() */ + if (arg->flags & (O_CREAT | O_TMPFILE)) { + fuse_reply_err(req, EINVAL); + return; + } + memset(&fi, 0, sizeof(fi)); fi.flags =3D arg->flags; fi.kill_priv =3D arg->open_flags & FUSE_OPEN_KILL_SUIDGID; --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479885235540.5310809412255; Mon, 5 Jul 2021 03:11:25 -0700 (PDT) Received: from localhost ([::1]:52578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LZU-0006nh-0i for importer@patchew.org; Mon, 05 Jul 2021 06:11:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSN-0001z6-Gt for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSL-0001Lk-BP for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:03 -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-478-8jdMO3P-PUqnm0sBDQuZEg-1; Mon, 05 Jul 2021 06:03:59 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1670E1084F4C; Mon, 5 Jul 2021 10:03:58 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BC0560C0F; Mon, 5 Jul 2021 10:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479440; 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: in-reply-to:in-reply-to:references:references; bh=9e89yhns/ABCOvoED2UxFdHblDRTHVUgDyiwXwTVXhE=; b=IfCM8tR9rdA0lhte9hWwP6poXSiwpZtSSXPcFoMQlBD96/I/zi2YJX5NCDkOU4zaU9Owkz U5+9iBAH9XMFuPT2EURv+9NRpLn65bdtW2kto5K+CGrmYkXYe6arnNpvywXug+gmOZK/dB 48dkeucSwlVDQu8f/sOViZIMQw9McGc= X-MC-Unique: 8jdMO3P-PUqnm0sBDQuZEg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 10/19] virtiofsd: Fix fuse setxattr() API change issue Date: Mon, 5 Jul 2021 11:02:26 +0100 Message-Id: <20210705100235.157093-11-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479886342100001 Content-Type: text/plain; charset="utf-8" From: Vivek Goyal With kernel header updates fuse_setxattr_in struct has grown in size. But this new struct size only takes affect if user has opted in for fuse feature FUSE_SETXATTR_EXT otherwise fuse continues to send "fuse_setxattr_in" of older size. Older size is determined by FUSE_COMPAT_SETXATTR_IN_SIZE. Fix this. If we have not opted in for FUSE_SETXATTR_EXT, then expect that we will get fuse_setxattr_in of size FUSE_COMPAT_SETXATTR_IN_SI= ZE and not sizeof(struct fuse_sexattr_in). Fixes: 278f064e4524 ("Update Linux headers to 5.13-rc4") Signed-off-by: Vivek Goyal Message-Id: <20210622150852.1507204-2-vgoyal@redhat.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Greg Kurz Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/fuse_common.h | 5 +++++ tools/virtiofsd/fuse_lowlevel.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/virtiofsd/fuse_common.h b/tools/virtiofsd/fuse_common.h index fa9671872e..0c2665b977 100644 --- a/tools/virtiofsd/fuse_common.h +++ b/tools/virtiofsd/fuse_common.h @@ -372,6 +372,11 @@ struct fuse_file_info { */ #define FUSE_CAP_HANDLE_KILLPRIV_V2 (1 << 28) =20 +/** + * Indicates that file server supports extended struct fuse_setxattr_in + */ +#define FUSE_CAP_SETXATTR_EXT (1 << 29) + /** * Ioctl flags * diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 3d725bcba2..2028677907 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -1425,8 +1425,13 @@ static void do_setxattr(fuse_req_t req, fuse_ino_t n= odeid, struct fuse_setxattr_in *arg; const char *name; const char *value; + bool setxattr_ext =3D req->se->conn.want & FUSE_CAP_SETXATTR_EXT; =20 - arg =3D fuse_mbuf_iter_advance(iter, sizeof(*arg)); + if (setxattr_ext) { + arg =3D fuse_mbuf_iter_advance(iter, sizeof(*arg)); + } else { + arg =3D fuse_mbuf_iter_advance(iter, FUSE_COMPAT_SETXATTR_IN_SIZE); + } name =3D fuse_mbuf_iter_advance_str(iter); if (!arg || !name) { fuse_reply_err(req, EINVAL); --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625480073765343.8569632459779; Mon, 5 Jul 2021 03:14:33 -0700 (PDT) Received: from localhost ([::1]:35852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LcW-000637-Lt for importer@patchew.org; Mon, 05 Jul 2021 06:14:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSR-00022z-2D for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSO-0001Nc-5J for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:06 -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-273-SeJu1uJqNeKRrBrQrCFO7g-1; Mon, 05 Jul 2021 06:04:02 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C57CA1005521; Mon, 5 Jul 2021 10:04:00 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 605AC60CC9; Mon, 5 Jul 2021 10:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479443; 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: in-reply-to:in-reply-to:references:references; bh=EHIZaWrzTWVadqEEpcR1o8cVL1MoQyDMpjctO98rEi8=; b=f+EHOWdIz+y9Sb4QlMhRNxvUNA9nos7pyWc6/NDd09u0npuO6lnD6gL6lqh/Vc07FX4TMw wVXaombfM1aC0pbD2QUXpEwRTb0IFKUndYx9VI/E5+/jI4pvfZJCEjILlMok7eSlO/wZPQ xtlcQJNYrD4Rrknt/ndsz8jt0+ovKSA= X-MC-Unique: SeJu1uJqNeKRrBrQrCFO7g-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 11/19] virtiofsd: Fix xattr operations overwriting errno Date: Mon, 5 Jul 2021 11:02:27 +0100 Message-Id: <20210705100235.157093-12-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625480075057100001 Content-Type: text/plain; charset="utf-8" From: Vivek Goyal getxattr/setxattr/removexattr/listxattr operations handle regualar and non-regular files differently. For the case of non-regular files we do fchdir(/proc/self/fd) and the xattr operation and then revert back to original working directory. After this we are saving errno and that's buggy because fchdir() will overwrite the errno. FCHDIR_NOFAIL(lo->proc_self_fd); ret =3D getxattr(procname, name, value, size); FCHDIR_NOFAIL(lo->root.fd); if (ret =3D=3D -1) saverr =3D errno In above example, if getxattr() failed, we will still return 0 to caller as errno must have been written by FCHDIR_NOFAIL(lo->root.fd) call. Fix all such instances and capture "errno" early and save in "saverr" variable. Signed-off-by: Vivek Goyal Message-Id: <20210622150852.1507204-3-vgoyal@redhat.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Greg Kurz Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 9858e961d9..ccbda98c5a 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2791,15 +2791,17 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t = ino, const char *in_name, goto out_err; } ret =3D fgetxattr(fd, name, value, size); + saverr =3D ret =3D=3D -1 ? errno : 0; } else { /* fchdir should not fail here */ FCHDIR_NOFAIL(lo->proc_self_fd); ret =3D getxattr(procname, name, value, size); + saverr =3D ret =3D=3D -1 ? errno : 0; FCHDIR_NOFAIL(lo->root.fd); } =20 if (ret =3D=3D -1) { - goto out_err; + goto out; } if (size) { saverr =3D 0; @@ -2864,15 +2866,17 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t= ino, size_t size) goto out_err; } ret =3D flistxattr(fd, value, size); + saverr =3D ret =3D=3D -1 ? errno : 0; } else { /* fchdir should not fail here */ FCHDIR_NOFAIL(lo->proc_self_fd); ret =3D listxattr(procname, value, size); + saverr =3D ret =3D=3D -1 ? errno : 0; FCHDIR_NOFAIL(lo->root.fd); } =20 if (ret =3D=3D -1) { - goto out_err; + goto out; } if (size) { saverr =3D 0; @@ -2998,15 +3002,15 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t = ino, const char *in_name, goto out; } ret =3D fsetxattr(fd, name, value, size, flags); + saverr =3D ret =3D=3D -1 ? errno : 0; } else { /* fchdir should not fail here */ FCHDIR_NOFAIL(lo->proc_self_fd); ret =3D setxattr(procname, name, value, size, flags); + saverr =3D ret =3D=3D -1 ? errno : 0; FCHDIR_NOFAIL(lo->root.fd); } =20 - saverr =3D ret =3D=3D -1 ? errno : 0; - out: if (fd >=3D 0) { close(fd); @@ -3064,15 +3068,15 @@ static void lo_removexattr(fuse_req_t req, fuse_ino= _t ino, const char *in_name) goto out; } ret =3D fremovexattr(fd, name); + saverr =3D ret =3D=3D -1 ? errno : 0; } else { /* fchdir should not fail here */ FCHDIR_NOFAIL(lo->proc_self_fd); ret =3D removexattr(procname, name); + saverr =3D ret =3D=3D -1 ? errno : 0; FCHDIR_NOFAIL(lo->root.fd); } =20 - saverr =3D ret =3D=3D -1 ? errno : 0; - out: if (fd >=3D 0) { close(fd); --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479721943643.8232019210617; Mon, 5 Jul 2021 03:08:41 -0700 (PDT) Received: from localhost ([::1]:45324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LWq-0001uL-Sx for importer@patchew.org; Mon, 05 Jul 2021 06:08:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSW-0002BE-Fl for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27969) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSU-0001SC-Dr for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:12 -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-413-HMPdh941ObGWok_rwTn_ow-1; Mon, 05 Jul 2021 06:04:07 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 96B7E1084F4C; Mon, 5 Jul 2021 10:04:06 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CCC360C0F; Mon, 5 Jul 2021 10:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479449; 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: in-reply-to:in-reply-to:references:references; bh=6KFaiNUZVZ3goQxsx2F/n6GtS62cejQLT/xIiI+3nGU=; b=c0yr3ySO31ZRtvt8nb3fndRltrPuPORhhDWFK1/vVHz8x6TSkIcMyaY8TXl91EaE1Fu3Q6 o7uRq9m5IX6UqOHSvF8Nhv8aaTFWhQRZYv28RB79EoRAsE6lpZ4cIQG7HxAO1gKDmK2p44 ROCc+T16ImBp+4yOaxvvHk8zm27i8tw= X-MC-Unique: HMPdh941ObGWok_rwTn_ow-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 12/19] virtiofsd: Add support for extended setxattr Date: Mon, 5 Jul 2021 11:02:28 +0100 Message-Id: <20210705100235.157093-13-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479723640100001 Content-Type: text/plain; charset="utf-8" From: Vivek Goyal Add the bits to enable support for setxattr_ext if fuse offers it. Do not enable it by default yet. Let passthrough_ll opt-in. Enabling it by deafult kind of automatically means that you are taking responsibility of clearing SGID if ACL is set. Signed-off-by: Vivek Goyal Message-Id: <20210622150852.1507204-4-vgoyal@redhat.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert Fixed up double def in fuse_common.h --- tools/virtiofsd/fuse_lowlevel.c | 11 ++++++++++- tools/virtiofsd/fuse_lowlevel.h | 3 ++- tools/virtiofsd/passthrough_ll.c | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 2028677907..e4679c73ab 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -1445,7 +1445,9 @@ static void do_setxattr(fuse_req_t req, fuse_ino_t no= deid, } =20 if (req->se->op.setxattr) { - req->se->op.setxattr(req, nodeid, name, value, arg->size, arg->fla= gs); + uint32_t setxattr_flags =3D setxattr_ext ? arg->setxattr_flags : 0; + req->se->op.setxattr(req, nodeid, name, value, arg->size, arg->fla= gs, + setxattr_flags); } else { fuse_reply_err(req, ENOSYS); } @@ -1992,6 +1994,9 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, if (arg->flags & FUSE_HANDLE_KILLPRIV_V2) { se->conn.capable |=3D FUSE_CAP_HANDLE_KILLPRIV_V2; } + if (arg->flags & FUSE_SETXATTR_EXT) { + se->conn.capable |=3D FUSE_CAP_SETXATTR_EXT; + } #ifdef HAVE_SPLICE #ifdef HAVE_VMSPLICE se->conn.capable |=3D FUSE_CAP_SPLICE_WRITE | FUSE_CAP_SPLICE_MOVE; @@ -2127,6 +2132,10 @@ static void do_init(fuse_req_t req, fuse_ino_t nodei= d, outarg.flags |=3D FUSE_HANDLE_KILLPRIV_V2; } =20 + if (se->conn.want & FUSE_CAP_SETXATTR_EXT) { + outarg.flags |=3D FUSE_SETXATTR_EXT; + } + fuse_log(FUSE_LOG_DEBUG, " INIT: %u.%u\n", outarg.major, outarg.mino= r); fuse_log(FUSE_LOG_DEBUG, " flags=3D0x%08x\n", outarg.flags); fuse_log(FUSE_LOG_DEBUG, " max_readahead=3D0x%08x\n", outarg.max_rea= dahead); diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowleve= l.h index 3bf786b034..4b4e8c9724 100644 --- a/tools/virtiofsd/fuse_lowlevel.h +++ b/tools/virtiofsd/fuse_lowlevel.h @@ -798,7 +798,8 @@ struct fuse_lowlevel_ops { * fuse_reply_err */ void (*setxattr)(fuse_req_t req, fuse_ino_t ino, const char *name, - const char *value, size_t size, int flags); + const char *value, size_t size, int flags, + uint32_t setxattr_flags); =20 /** * Get an extended attribute diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index ccbda98c5a..4dec087bd4 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -2955,7 +2955,8 @@ out: } =20 static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_nam= e, - const char *value, size_t size, int flags) + const char *value, size_t size, int flags, + uint32_t extra_flags) { char procname[64]; const char *name; --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625479911595102.95121755474702; Mon, 5 Jul 2021 03:11:51 -0700 (PDT) Received: from localhost ([::1]:53950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LZu-0007jg-D3 for importer@patchew.org; Mon, 05 Jul 2021 06:11:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSi-0002lm-ET for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSg-0001ba-Qu for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:24 -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-602-fRVTc6rYOfevE5f4Yz2_wA-1; Mon, 05 Jul 2021 06:04:20 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B344F1084F40; Mon, 5 Jul 2021 10:04:19 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1BFA60C0F; Mon, 5 Jul 2021 10:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479462; 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: in-reply-to:in-reply-to:references:references; bh=cZMaP/Fr2UvYH3YfzZWfICfblNzKICo5fmD+7se/M64=; b=SUvS5ic5jvsyqNoxghFT6P2/ldGh+yiGoQ2JRCeUAxjjS7Li4S4jlVAVBw3QXtcwEI+Sa/ PpcOFAvzr2Y2eQiOQm5+SIFtnL3fhY7FdA+q9pbzgHohpE3AMPuPdUeOWygMWZbv1rqIzG yU9qzs0WwXCDZQ4LdQhBLLSLV0No8pQ= X-MC-Unique: fRVTc6rYOfevE5f4Yz2_wA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 13/19] virtiofsd: Add umask to seccom allow list Date: Mon, 5 Jul 2021 11:02:29 +0100 Message-Id: <20210705100235.157093-14-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625479912975100001 Content-Type: text/plain; charset="utf-8" From: Vivek Goyal Patches in this series are going to make use of "umask" syscall. So allow it. Signed-off-by: Vivek Goyal Reviewed-by: Stefan Hajnoczi Message-Id: <20210622150852.1507204-5-vgoyal@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_seccomp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virtiofsd/passthrough_seccomp.c b/tools/virtiofsd/passth= rough_seccomp.c index 62441cfcdb..f49ed94b5e 100644 --- a/tools/virtiofsd/passthrough_seccomp.c +++ b/tools/virtiofsd/passthrough_seccomp.c @@ -114,6 +114,7 @@ static const int syscall_allowlist[] =3D { SCMP_SYS(utimensat), SCMP_SYS(write), SCMP_SYS(writev), + SCMP_SYS(umask), }; =20 /* Syscalls used when --syslog is enabled */ --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625480050754596.691087771783; Mon, 5 Jul 2021 03:14:10 -0700 (PDT) Received: from localhost ([::1]:34728 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0Lc9-0005Hx-MV for importer@patchew.org; Mon, 05 Jul 2021 06:14:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSm-0002zj-2m for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSj-0001dS-V9 for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:27 -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-331-71IyafdhM_2MWg8WX-VmeA-1; Mon, 05 Jul 2021 06:04:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90D488015F5; Mon, 5 Jul 2021 10:04:22 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EB5C60C0F; Mon, 5 Jul 2021 10:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479465; 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: in-reply-to:in-reply-to:references:references; bh=wEs+EGaCVwVgsdq9B8HBs51p7HnNdyJCliUHEwdX5Gg=; b=CD3QNgDwMBDGl327+jlNq/3cqjqJS/Tz77Wjb0qk9c1ovbcdtI8FtqTIfGQPPtZ6dNiYUQ aZVm2q2ZHWzQnjTRw7ZUd95YHG/5WfKGOOIs6mWKTGMNvHyDkksI9T1F2RvqhpDvB6yKD6 6K0sRnmvY9nFUKG6r6shho7tNrAsoNk= X-MC-Unique: 71IyafdhM_2MWg8WX-VmeA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 14/19] virtiofsd: Add capability to change/restore umask Date: Mon, 5 Jul 2021 11:02:30 +0100 Message-Id: <20210705100235.157093-15-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625480052002100001 Content-Type: text/plain; charset="utf-8" From: Vivek Goyal When parent directory has default acl and a file is created in that directory, then umask is ignored and final file permissions are determined using default acl instead. (man 2 umask). Currently, fuse applies the umask and sends modified mode in create request accordingly. fuse server can set FUSE_DONT_MASK and tell fuse client to not apply umask and fuse server will take care of it as needed. With posix acls enabled, requirement will be that we want umask to determine final file mode if parent directory does not have default acl. So if posix acls are enabled, opt in for FUSE_DONT_MASK. virtiofsd will set umask of the thread doing file creation. And host kernel should use that umask if parent directory does not have default acls, otherwise umask does not take affect. Miklos mentioned that we already call unshare(CLONE_FS) for every thread. That means umask has now become property of per thread and it should be ok to manipulate it in file creation path. This patch only adds capability to change umask and restore it. It does not enable it yet. Next few patches will add capability to enable it based on if user enabled posix_acl or not. This should fix fstest generic/099. Reported-by: Luis Henriques Signed-off-by: Vivek Goyal Reviewed-by: Stefan Hajnoczi Reviewed-by: Dr. David Alan Gilbert Message-Id: <20210622150852.1507204-6-vgoyal@redhat.com> Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 4dec087bd4..65b2c6fd74 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -122,6 +122,7 @@ struct lo_inode { struct lo_cred { uid_t euid; gid_t egid; + mode_t umask; }; =20 enum { @@ -172,6 +173,8 @@ struct lo_data { /* An O_PATH file descriptor to /proc/self/fd/ */ int proc_self_fd; int user_killpriv_v2, killpriv_v2; + /* If set, virtiofsd is responsible for setting umask during creation = */ + bool change_umask; }; =20 static const struct fuse_opt lo_opts[] =3D { @@ -1134,7 +1137,8 @@ static void lo_lookup(fuse_req_t req, fuse_ino_t pare= nt, const char *name) * ownership of caller. * TODO: What about selinux context? */ -static int lo_change_cred(fuse_req_t req, struct lo_cred *old) +static int lo_change_cred(fuse_req_t req, struct lo_cred *old, + bool change_umask) { int res; =20 @@ -1154,11 +1158,14 @@ static int lo_change_cred(fuse_req_t req, struct lo= _cred *old) return errno_save; } =20 + if (change_umask) { + old->umask =3D umask(req->ctx.umask); + } return 0; } =20 /* Regain Privileges */ -static void lo_restore_cred(struct lo_cred *old) +static void lo_restore_cred(struct lo_cred *old, bool restore_umask) { int res; =20 @@ -1173,6 +1180,9 @@ static void lo_restore_cred(struct lo_cred *old) fuse_log(FUSE_LOG_ERR, "setegid(%u): %m\n", old->egid); exit(1); } + + if (restore_umask) + umask(old->umask); } =20 static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent, @@ -1202,7 +1212,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino= _t parent, return; } =20 - saverr =3D lo_change_cred(req, &old); + saverr =3D lo_change_cred(req, &old, lo->change_umask && !S_ISLNK(mode= )); if (saverr) { goto out; } @@ -1211,7 +1221,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino= _t parent, =20 saverr =3D errno; =20 - lo_restore_cred(&old); + lo_restore_cred(&old, lo->change_umask && !S_ISLNK(mode)); =20 if (res =3D=3D -1) { goto out; @@ -1917,7 +1927,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t pare= nt, const char *name, return; } =20 - err =3D lo_change_cred(req, &old); + err =3D lo_change_cred(req, &old, lo->change_umask); if (err) { goto out; } @@ -1928,7 +1938,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t pare= nt, const char *name, fd =3D openat(parent_inode->fd, name, fi->flags | O_CREAT | O_EXCL, mo= de); err =3D fd =3D=3D -1 ? errno : 0; =20 - lo_restore_cred(&old); + lo_restore_cred(&old, lo->change_umask); =20 /* Ignore the error if file exists and O_EXCL was not given */ if (err && (err !=3D EEXIST || (fi->flags & O_EXCL))) { --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625480231641630.1542830838515; Mon, 5 Jul 2021 03:17:11 -0700 (PDT) Received: from localhost ([::1]:41122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0Lf4-0001It-GX for importer@patchew.org; Mon, 05 Jul 2021 06:17:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSo-00038S-8l for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42831) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSm-0001ej-51 for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:30 -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-36-AuXHieubO2uVXq5kVziHMg-1; Mon, 05 Jul 2021 06:04:26 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B36F801B0F; Mon, 5 Jul 2021 10:04:25 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id E424E60C0F; Mon, 5 Jul 2021 10:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479467; 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: in-reply-to:in-reply-to:references:references; bh=6+T6x3SfzYsOAuAetn4fRdhMXzkQThUs182/Ka6sGcY=; b=WcBPTZDxH3r0pPO8Acd6XkDJrAGrPPVHGcsBsSQI9iVCef+HrWMXf8YEERmDO+FXMhatPa iRaVeNAQMsXEzmzi6mpRltQxVMyU1r3xoEKMBuP6HqNt/Xl/PIviXGnZ0kPx4WpvCp1Vwj PAUlwMjbvAEw+0pKoIh6WA8GSjWpspo= X-MC-Unique: AuXHieubO2uVXq5kVziHMg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 15/19] virtiofsd: Switch creds, drop FSETID for system.posix_acl_access xattr Date: Mon, 5 Jul 2021 11:02:31 +0100 Message-Id: <20210705100235.157093-16-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625480232846100001 Content-Type: text/plain; charset="utf-8" From: Vivek Goyal When posix access acls are set on a file, it can lead to adjusting file permissions (mode) as well. If caller does not have CAP_FSETID and it also does not have membership of owner group, this will lead to clearing SGID bit in mode. Current fuse code is written in such a way that it expects file server to take care of chaning file mode (permission), if there is a need. Right now, host kernel does not clear SGID bit because virtiofsd is running as root and has CAP_FSETID. For host kernel to clear SGID, virtiofsd need to switch to gid of caller in guest and also drop CAP_FSETID (if caller did not have it to begin with). If SGID needs to be cleared, client will set the flag FUSE_SETXATTR_ACL_KILL_SGID in setxattr request. In that case server should kill sgid. Currently just switch to uid/gid of the caller and drop CAP_FSETID and that should do it. This should fix the xfstest generic/375 test case. We don't have to switch uid for this to work. That could be one optimization that pass a parameter to lo_change_cred() to only switch gid and not uid. Also this will not work whenever (if ever) we support idmapped mounts. In that case it is possible that uid/gid in request are 0/0 but still we need to clear SGID. So we will have to pick a non-root sgid and switch to that instead. That's an TODO item for future when idmapped mount support is introduced. This patch only adds the capability to switch creds and drop FSETID when acl xattr is set. This does not take affect yet. It can take affect when next patch adds the capability to enable posix_acl. Reported-by: Luis Henriques Signed-off-by: Vivek Goyal Message-Id: <20210622150852.1507204-7-vgoyal@redhat.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 65b2c6fd74..6e30fd9113 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -175,6 +175,7 @@ struct lo_data { int user_killpriv_v2, killpriv_v2; /* If set, virtiofsd is responsible for setting umask during creation = */ bool change_umask; + int posix_acl; }; =20 static const struct fuse_opt lo_opts[] =3D { @@ -1185,6 +1186,51 @@ static void lo_restore_cred(struct lo_cred *old, boo= l restore_umask) umask(old->umask); } =20 +/* + * A helper to change cred and drop capability. Returns 0 on success and + * errno on error + */ +static int lo_drop_cap_change_cred(fuse_req_t req, struct lo_cred *old, + bool change_umask, const char *cap_name, + bool *cap_dropped) +{ + int ret; + bool __cap_dropped; + + assert(cap_name); + + ret =3D drop_effective_cap(cap_name, &__cap_dropped); + if (ret) { + return ret; + } + + ret =3D lo_change_cred(req, old, change_umask); + if (ret) { + if (__cap_dropped) { + if (gain_effective_cap(cap_name)) { + fuse_log(FUSE_LOG_ERR, "Failed to gain CAP_%s\n", cap_name= ); + } + } + } + + if (cap_dropped) { + *cap_dropped =3D __cap_dropped; + } + return ret; +} + +static void lo_restore_cred_gain_cap(struct lo_cred *old, bool restore_uma= sk, + const char *cap_name) +{ + assert(cap_name); + + lo_restore_cred(old, restore_umask); + + if (gain_effective_cap(cap_name)) { + fuse_log(FUSE_LOG_ERR, "Failed to gain CAP_%s\n", cap_name); + } +} + static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, dev_t rdev, const char *link) @@ -2976,6 +3022,9 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t in= o, const char *in_name, ssize_t ret; int saverr; int fd =3D -1; + bool switched_creds =3D false; + bool cap_fsetid_dropped =3D false; + struct lo_cred old =3D {}; =20 mapped_name =3D NULL; name =3D in_name; @@ -3006,6 +3055,26 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t i= no, const char *in_name, ", name=3D%s value=3D%s size=3D%zd)\n", ino, name, value, siz= e); =20 sprintf(procname, "%i", inode->fd); + /* + * If we are setting posix access acl and if SGID needs to be + * cleared, then switch to caller's gid and drop CAP_FSETID + * and that should make sure host kernel clears SGID. + * + * This probably will not work when we support idmapped mounts. + * In that case we will need to find a non-root gid and switch + * to it. (Instead of gid in request). Fix it when we support + * idmapped mounts. + */ + if (lo->posix_acl && !strcmp(name, "system.posix_acl_access") + && (extra_flags & FUSE_SETXATTR_ACL_KILL_SGID)) { + ret =3D lo_drop_cap_change_cred(req, &old, false, "FSETID", + &cap_fsetid_dropped); + if (ret) { + saverr =3D ret; + goto out; + } + switched_creds =3D true; + } if (S_ISREG(inode->filetype) || S_ISDIR(inode->filetype)) { fd =3D openat(lo->proc_self_fd, procname, O_RDONLY); if (fd < 0) { @@ -3021,6 +3090,12 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t i= no, const char *in_name, saverr =3D ret =3D=3D -1 ? errno : 0; FCHDIR_NOFAIL(lo->root.fd); } + if (switched_creds) { + if (cap_fsetid_dropped) + lo_restore_cred_gain_cap(&old, false, "FSETID"); + else + lo_restore_cred(&old, false); + } =20 out: if (fd >=3D 0) { --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625480216772761.8863737303649; Mon, 5 Jul 2021 03:16:56 -0700 (PDT) Received: from localhost ([::1]:39868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0Lep-0000PM-GR for importer@patchew.org; Mon, 05 Jul 2021 06:16:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSr-0003H9-Ep for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LSp-0001hB-68 for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:33 -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-496-z5RhZ6ryNOKSMT9-hwPJpw-1; Mon, 05 Jul 2021 06:04:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E76B3801B0C; Mon, 5 Jul 2021 10:04:27 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8509960C0F; Mon, 5 Jul 2021 10:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479470; 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: in-reply-to:in-reply-to:references:references; bh=fWNHqkdulg9jEXmNe2BHnjj4qJOUIv2pf/HPxRxQ2Ww=; b=AvzaUUWZUP4nm7GVUyVptM+7sw8U9/D3jVd8UmWf0DUnfHmB9mmRaIiV+AL2zk2CL537gJ qMMB2iMZqtpr3+Q85yfam5VglArMsgITgyY6rN7rnt6eaAE8s1UHDIKFyo1t3g8O3chAXQ TRTN79acRMnY8nG5ighsNZH0I2B5hxw= X-MC-Unique: z5RhZ6ryNOKSMT9-hwPJpw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 16/19] virtiofsd: Add an option to enable/disable posix acls Date: Mon, 5 Jul 2021 11:02:32 +0100 Message-Id: <20210705100235.157093-17-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625480217974100001 Content-Type: text/plain; charset="utf-8" From: Vivek Goyal fuse has an option FUSE_POSIX_ACL which needs to be opted in by fuse server to enable posix acls. As of now we are not opting in for this, so posix acls are disabled on virtiofs by default. Add virtiofsd option "-o posix_acl/no_posix_acl" to let users enable/disable posix acl support. By default it is disabled as of now due to performance concerns with cache=3Dnone. Currently even if file server has not opted in for FUSE_POSIX_ACL, user can still query acl and set acl, and system.posix_acl_access and system.posix_acl_default xattrs show up listxattr response. Miklos said this is confusing. So he said lets block and filter system.posix_acl_access and system.posix_acl_default xattrs in getxattr/setxattr/listxattr if user has explicitly disabled posix acls using -o no_posix_acl. As of now continuing to keeping the existing behavior if user did not specify any option to disable acl support due to concerns about backward compatibility. Signed-off-by: Vivek Goyal Message-Id: <20210622150852.1507204-8-vgoyal@redhat.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- docs/tools/virtiofsd.rst | 3 + tools/virtiofsd/helper.c | 1 + tools/virtiofsd/passthrough_ll.c | 115 ++++++++++++++++++++++++++++++- 3 files changed, 118 insertions(+), 1 deletion(-) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index a6c3502710..c4ac7fdf38 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -101,6 +101,9 @@ Options Enable/disable extended attributes (xattr) on files and directories. = The default is ``no_xattr``. =20 + * posix_acl|no_posix_acl - + Enable/disable posix acl support. Posix ACLs are disabled by default`. + .. option:: --socket-path=3DPATH =20 Listen on vhost-user UNIX domain socket at PATH. diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c index 5e98ed702b..a8295d975a 100644 --- a/tools/virtiofsd/helper.c +++ b/tools/virtiofsd/helper.c @@ -186,6 +186,7 @@ void fuse_cmdline_help(void) " to virtiofsd from guest applica= tions.\n" " default: no_allow_direct_io\n" " -o announce_submounts Announce sub-mount points to th= e guest\n" + " -o posix_acl/no_posix_acl Enable/Disable posix_acl. (defa= ult: disabled)\n" ); } =20 diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 6e30fd9113..38b2af8599 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -175,7 +175,7 @@ struct lo_data { int user_killpriv_v2, killpriv_v2; /* If set, virtiofsd is responsible for setting umask during creation = */ bool change_umask; - int posix_acl; + int user_posix_acl, posix_acl; }; =20 static const struct fuse_opt lo_opts[] =3D { @@ -208,6 +208,8 @@ static const struct fuse_opt lo_opts[] =3D { { "announce_submounts", offsetof(struct lo_data, announce_submounts), = 1 }, { "killpriv_v2", offsetof(struct lo_data, user_killpriv_v2), 1 }, { "no_killpriv_v2", offsetof(struct lo_data, user_killpriv_v2), 0 }, + { "posix_acl", offsetof(struct lo_data, user_posix_acl), 1 }, + { "no_posix_acl", offsetof(struct lo_data, user_posix_acl), 0 }, FUSE_OPT_END }; static bool use_syslog =3D false; @@ -706,6 +708,32 @@ static void lo_init(void *userdata, struct fuse_conn_i= nfo *conn) conn->want &=3D ~FUSE_CAP_HANDLE_KILLPRIV_V2; lo->killpriv_v2 =3D 0; } + + if (lo->user_posix_acl =3D=3D 1) { + /* + * User explicitly asked for this option. Enable it unconditionall= y. + * If connection does not have this capability, print error message + * now. It will fail later in fuse_lowlevel.c + */ + if (!(conn->capable & FUSE_CAP_POSIX_ACL) || + !(conn->capable & FUSE_CAP_DONT_MASK) || + !(conn->capable & FUSE_CAP_SETXATTR_EXT)) { + fuse_log(FUSE_LOG_ERR, "lo_init: Can not enable posix acl." + " kernel does not support FUSE_POSIX_ACL, FUSE_DONT_M= ASK" + " or FUSE_SETXATTR_EXT capability.\n"); + } else { + fuse_log(FUSE_LOG_DEBUG, "lo_init: enabling posix acl\n"); + } + + conn->want |=3D FUSE_CAP_POSIX_ACL | FUSE_CAP_DONT_MASK | + FUSE_CAP_SETXATTR_EXT; + lo->change_umask =3D true; + lo->posix_acl =3D true; + } else { + /* User either did not specify anything or wants it disabled */ + fuse_log(FUSE_LOG_DEBUG, "lo_init: disabling posix_acl\n"); + conn->want &=3D ~FUSE_CAP_POSIX_ACL; + } } =20 static void lo_getattr(fuse_req_t req, fuse_ino_t ino, @@ -2783,6 +2811,63 @@ static int xattr_map_server(const struct lo_data *lo= , const char *server_name, assert(fchdir_res =3D=3D 0); \ } while (0) =20 +static bool block_xattr(struct lo_data *lo, const char *name) +{ + /* + * If user explicitly enabled posix_acl or did not provide any option, + * do not block acl. Otherwise block system.posix_acl_access and + * system.posix_acl_default xattrs. + */ + if (lo->user_posix_acl) { + return false; + } + if (!strcmp(name, "system.posix_acl_access") || + !strcmp(name, "system.posix_acl_default")) + return true; + + return false; +} + +/* + * Returns number of bytes in xattr_list after filtering on success. This + * could be zero as well if nothing is left after filtering. + * + * Returns negative error code on failure. + * xattr_list is modified in place. + */ +static int remove_blocked_xattrs(struct lo_data *lo, char *xattr_list, + unsigned in_size) +{ + size_t out_index, in_index; + + /* + * As of now we only filter out acl xattrs. If acls are enabled or + * they have not been explicitly disabled, there is nothing to + * filter. + */ + if (lo->user_posix_acl) { + return in_size; + } + + out_index =3D 0; + in_index =3D 0; + while (in_index < in_size) { + char *in_ptr =3D xattr_list + in_index; + + /* Length of current attribute name */ + size_t in_len =3D strlen(xattr_list + in_index) + 1; + + if (!block_xattr(lo, in_ptr)) { + if (in_index !=3D out_index) { + memmove(xattr_list + out_index, xattr_list + in_index, in_= len); + } + out_index +=3D in_len; + } + in_index +=3D in_len; + } + return out_index; +} + static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_nam= e, size_t size) { @@ -2796,6 +2881,11 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t i= no, const char *in_name, int saverr; int fd =3D -1; =20 + if (block_xattr(lo, in_name)) { + fuse_reply_err(req, EOPNOTSUPP); + return; + } + mapped_name =3D NULL; name =3D in_name; if (lo->xattrmap) { @@ -2986,6 +3076,12 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t = ino, size_t size) goto out; } } + + ret =3D remove_blocked_xattrs(lo, value, ret); + if (ret <=3D 0) { + saverr =3D -ret; + goto out; + } fuse_reply_buf(req, value, ret); } else { /* @@ -3026,6 +3122,11 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t i= no, const char *in_name, bool cap_fsetid_dropped =3D false; struct lo_cred old =3D {}; =20 + if (block_xattr(lo, in_name)) { + fuse_reply_err(req, EOPNOTSUPP); + return; + } + mapped_name =3D NULL; name =3D in_name; if (lo->xattrmap) { @@ -3118,6 +3219,11 @@ static void lo_removexattr(fuse_req_t req, fuse_ino_= t ino, const char *in_name) int saverr; int fd =3D -1; =20 + if (block_xattr(lo, in_name)) { + fuse_reply_err(req, EOPNOTSUPP); + return; + } + mapped_name =3D NULL; name =3D in_name; if (lo->xattrmap) { @@ -3795,6 +3901,7 @@ int main(int argc, char *argv[]) .allow_direct_io =3D 0, .proc_self_fd =3D -1, .user_killpriv_v2 =3D -1, + .user_posix_acl =3D -1, }; struct lo_map_elem *root_elem; struct lo_map_elem *reserve_elem; @@ -3923,6 +4030,12 @@ int main(int argc, char *argv[]) exit(1); } =20 + if (lo.user_posix_acl =3D=3D 1 && !lo.xattr) { + fuse_log(FUSE_LOG_ERR, "Can't enable posix ACLs. xattrs are disabl= ed." + "\n"); + exit(1); + } + lo.use_statx =3D true; =20 se =3D fuse_session_new(&args, &lo_oper, sizeof(lo_oper), &lo); --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625480336858749.7768940115338; Mon, 5 Jul 2021 03:18:56 -0700 (PDT) Received: from localhost ([::1]:46898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0Lgk-00057r-Ny for importer@patchew.org; Mon, 05 Jul 2021 06:18:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LT6-0004C2-Fc for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46923) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LT4-0001sh-Sc for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:48 -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-528-opY-eyl9NqS6UDO8tfDcxA-1; Mon, 05 Jul 2021 06:04:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8FA41835AC3; Mon, 5 Jul 2021 10:04:43 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4076960C0F; Mon, 5 Jul 2021 10:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479486; 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: in-reply-to:in-reply-to:references:references; bh=oGFjksViURRBaaK6dL2ww4vZhfw/m6B0YkM0dByDldE=; b=DUaGX5jl8y5g/ivzloSpNqSGdCySBKg75ztnCASupEuTwTXFGVxd4/KuSyehJF+BEVM9Ec mkTNd/88K+TVq/zedOGcWioT8fd5B+eECMFzm+fgdODsbsYdsoE7bKHni7lovSC9lEK0nG 7w7AG934lBM4p5zFQEQBAC6of3KBuH8= X-MC-Unique: opY-eyl9NqS6UDO8tfDcxA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 17/19] tests/migration: parse the thread-id key of CpuInfoFast Date: Mon, 5 Jul 2021 11:02:33 +0100 Message-Id: <20210705100235.157093-18-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625480338044100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) thread_id in CpuInfoFast is deprecated, parse thread-id instead after execute qmp query-cpus-fast. fix this so that test can go smoothly. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Message-Id: <584578c0a0dd781cee45f72ddf517f6e6a41c504.1622729934.git.huangy= 81@chinatelecom.cn> Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Dr. David Alan Gilbert --- tests/migration/guestperf/engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/migration/guestperf/engine.py b/tests/migration/guestper= f/engine.py index 208e095794..9e16fa92d2 100644 --- a/tests/migration/guestperf/engine.py +++ b/tests/migration/guestperf/engine.py @@ -113,7 +113,7 @@ def _migrate(self, hardware, scenario, src, dst, connec= t_uri): vcpus =3D src.command("query-cpus-fast") src_threads =3D [] for vcpu in vcpus: - src_threads.append(vcpu["thread_id"]) + src_threads.append(vcpu["thread-id"]) =20 # XXX how to get dst timings on remote host ? =20 --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625480424939212.90077188707062; Mon, 5 Jul 2021 03:20:24 -0700 (PDT) Received: from localhost ([::1]:51682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0LiB-0008L3-TX for importer@patchew.org; Mon, 05 Jul 2021 06:20:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LT9-0004QL-Hj for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43026) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LT7-0001uk-QW for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:51 -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-456-0CNcGVw3OtC8OrBwQV0NIg-1; Mon, 05 Jul 2021 06:04:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 850861800D41; Mon, 5 Jul 2021 10:04:46 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4170C60C0F; Mon, 5 Jul 2021 10:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479489; 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: in-reply-to:in-reply-to:references:references; bh=rlwcdX8X5dsd/z20z7tWtn3wTUKnsr62oy9WKZNwWOM=; b=FUj9GpyIT2ZutmP4xFeDAXxcxkkuAVhsly030Fj+QoABAPGhL4ufS+BuEp8YNMKcNJ+vdP t7cw2px+DIfqTEAsoqjW3gyPYtJax1Qm/P7HynBbFhSOSi4FWv2+FwbhBWx2BHF8TvZrXs ikqRfneK6zDG4igsgt0IkfKZKv26i5I= X-MC-Unique: 0CNcGVw3OtC8OrBwQV0NIg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 18/19] tests/migration: fix "downtime_limit" type when "migrate-set-parameters" Date: Mon, 5 Jul 2021 11:02:34 +0100 Message-Id: <20210705100235.157093-19-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625480426453100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) migrate-set-parameters parse "downtime_limit" as integer type when execute "migrate-set-parameters" before migration, and, the unit dowtime_limit is milliseconds, fix this two so that test can go smoothly. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Message-Id: <31d82df24cc0c468dbe4d2d86730158ebf248071.1622729934.git.huangy= 81@chinatelecom.cn> Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Dr. David Alan Gilbert --- tests/migration/guestperf/engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/migration/guestperf/engine.py b/tests/migration/guestper= f/engine.py index 9e16fa92d2..7c991c4407 100644 --- a/tests/migration/guestperf/engine.py +++ b/tests/migration/guestperf/engine.py @@ -153,7 +153,7 @@ def _migrate(self, hardware, scenario, src, dst, connec= t_uri): max_bandwidth=3Dscenario._bandwidth * 1024 * 10= 24) =20 resp =3D src.command("migrate-set-parameters", - downtime_limit=3Dscenario._downtime / 1024.0) + downtime_limit=3Dscenario._downtime) =20 if scenario._compression_mt: resp =3D src.command("migrate-set-capabilities", --=20 2.31.1 From nobody Sat May 4 16:38:32 2024 Delivered-To: importer@patchew.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625480529952466.33989678351384; Mon, 5 Jul 2021 03:22:09 -0700 (PDT) Received: from localhost ([::1]:56286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0Ljs-00038c-Mu for importer@patchew.org; Mon, 05 Jul 2021 06:22:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LTF-0004nq-T6 for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56239) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0LTE-00022O-5G for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:04:57 -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-343-P5tIli_aP4-o2PAen0IZNQ-1; Mon, 05 Jul 2021 06:04:53 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C2401835AC5; Mon, 5 Jul 2021 10:04:52 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-114-11.ams2.redhat.com [10.36.114.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id D078E60C0F; Mon, 5 Jul 2021 10:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625479495; 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: in-reply-to:in-reply-to:references:references; bh=+Z2948xhR33lh2dPamiqHvKd80y+jfnjQLdjcksrLuU=; b=Kg7D9F5n6Oczg526IaO/Y48iTzg19jhdxhLoVGSnQDO35lqhQTyooSz/E8Uyx7DaEpwfLP FezefqdvDcBY0TruI3teBKowStO5EGQ6twTtMjZloh0EhVejONdDuNyCCPQ/23oQx/yUvE n2VmZH+Y6ZAOboiIygd44wn8d3yn1ro= X-MC-Unique: P5tIli_aP4-o2PAen0IZNQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, linfeng23@huawei.com, groug@kaod.org, huangy81@chinatelecom.cn, lvivier@redhat.com, lizhijian@cn.fujitsu.com, peterx@redhat.com, vgoyal@redhat.com Subject: [PULL 19/19] migration/rdma: Use error_report to suppress errno message Date: Mon, 5 Jul 2021 11:02:35 +0100 Message-Id: <20210705100235.157093-20-dgilbert@redhat.com> In-Reply-To: <20210705100235.157093-1-dgilbert@redhat.com> References: <20210705100235.157093-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.441, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: leobras@redhat.com, stefanha@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625480531288100001 Content-Type: text/plain; charset="utf-8" From: Li Zhijian Since the prior calls are successful, in this case a errno doesn't indicate a real error which would just make us confused. before: (qemu) migrate -d rdma:192.168.22.23:8888 source_resolve_host RDMA Device opened: kernel name rxe_eth0 uverbs device = name uverbs2, infiniband_verbs class device path /sys/class/infiniband_verb= s/uverbs2, infiniband class device path /sys/class/infiniband/rxe_eth0, tra= nsport: (2) Ethernet rdma_get_cm_event !=3D EVENT_ESTABLISHED after rdma_connect: No space left = on device Signed-off-by: Li Zhijian Message-Id: <20210628071959.23455-1-lizhijian@cn.fujitsu.com> Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/rdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index d90b29a4b5..b6cc4bef4a 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -1006,7 +1006,7 @@ route: if (cm_event->event !=3D RDMA_CM_EVENT_ADDR_RESOLVED) { ERROR(errp, "result not equal to event_addr_resolved %s", rdma_event_str(cm_event->event)); - perror("rdma_resolve_addr"); + error_report("rdma_resolve_addr"); rdma_ack_cm_event(cm_event); ret =3D -EINVAL; goto err_resolve_get_addr; @@ -2544,7 +2544,7 @@ static int qemu_rdma_connect(RDMAContext *rdma, Error= **errp, bool return_path) } =20 if (cm_event->event !=3D RDMA_CM_EVENT_ESTABLISHED) { - perror("rdma_get_cm_event !=3D EVENT_ESTABLISHED after rdma_connec= t"); + error_report("rdma_get_cm_event !=3D EVENT_ESTABLISHED after rdma_= connect"); ERROR(errp, "connecting to destination!"); rdma_ack_cm_event(cm_event); goto err_rdma_source_connect; --=20 2.31.1