Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1027012pxj; Wed, 2 Jun 2021 18:38:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmeAM0diXU0vHzJiFhf0yRPhftxUiG6yfUbvWQakMHK4fzy4uSLYBtnosYrjjt42Kyn+pf X-Received: by 2002:a50:cd58:: with SMTP id d24mr26073150edj.119.1622684318925; Wed, 02 Jun 2021 18:38:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622684318; cv=none; d=google.com; s=arc-20160816; b=l2eKqmaB5zIceJB/nUlqmjsc0S/lwaVjkJateFIrYNcu2i8c8WzdCHcturUukGvIr+ wxwEqlhiS1MO6GvCrTBpNB2XGoWIEpDA8iXrUrMvHd9PoPtUuqDXcJ8CrrT/e3rDjnqP HBBCI/JIOxLEu0MI0f2bTmGwwO54DLJcPeG10qyi+6ELmeKqPS/s4hOP7wIe9Bw05bTU Os0yOrXdgcC1aGYpYoFryUIs97ULfX5w0FgnMExAO4N5LxPt7CSW73vBrbnyk821igL2 ymqQEph5FxS/XMTrH6U06yoTKaNZ0e6lB2Rk4bqrESDBrQLFd9nZYPAm+Or81axrz03O ZRwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Y5CzXftv1cNQGBT4N8klgWnhnGPgyo6sbkOZKNeq8SY=; b=dPoTqGrwtWALu4wSrPzcRnnxqZoW70KK2QSMp6WWel3c9sNib5QrQJsSENI3xyTXCR bACGzFLt5X/sBSlv+lQU5r8y94QbgCfp59ijppRvlbQ70QRWDjrPYCaSAcyYcn2WxRM5 /zxFxOpCW1BF5WwDgcPYQdGk9XZAT8VWQgULXogUgplI+gz165AbXJjQCpceGvGX7hfv 98MLPBIgmqF72H4DlMh0PPeo1LSiRKFs62wi9XeNOKxr/0JKR4/Jmx7PPwkNcY28MS98 jU7vHc/udo7POrrpdPomuDHV4/9oEkZHgJCDYRmCv5kWzXSQ3VjPHZiz3nPhbPCzXDuJ uHFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NM2vVyMY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c13si1086630ejm.484.2021.06.02.18.38.15; Wed, 02 Jun 2021 18:38:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NM2vVyMY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbhFCBh6 (ORCPT + 99 others); Wed, 2 Jun 2021 21:37:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59757 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbhFCBh5 (ORCPT ); Wed, 2 Jun 2021 21:37:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622684173; 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=Y5CzXftv1cNQGBT4N8klgWnhnGPgyo6sbkOZKNeq8SY=; b=NM2vVyMYIQHsMFNOvl++CGuWLyLSKQxOw8GWUszzsKAM95EHvluyZqrTZtcR0yCR10OqvK Z4fj91ujcJm8ggAcgTh03uKwlQgb1OMXmmQlBAVX6nkxOXzS8o8L1Q3CyJ78nDZGw6EZNZ 8zB9T2T/X7PdL34HiDb9qxbLn51X790= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-588-6SWuBJQ8NNC0QRNQSGqvWg-1; Wed, 02 Jun 2021 21:36:12 -0400 X-MC-Unique: 6SWuBJQ8NNC0QRNQSGqvWg-1 Received: by mail-pj1-f72.google.com with SMTP id kk5-20020a17090b4a05b029016102a8423cso4419925pjb.1 for ; Wed, 02 Jun 2021 18:36:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=Y5CzXftv1cNQGBT4N8klgWnhnGPgyo6sbkOZKNeq8SY=; b=QHdnXZxdMWax1SI4U31ZHP9cx0qj6zcWzaurQOS0/U8yIMECZBIjjAp/lKVuIgedg2 BekxSuX9XLsNDgMkWYyU7ow0iECA5JK6tfqoqOecFO3ciCSmdIWHbSMYp3mSbxKehKn8 q1SYkGN45FguUO2+tu4Jd9zDLnaD7s6vN94msrQaH2QFAvrgvD/LEzDr92jEuKdwd7Qx 9N0hRfHubTzx7LPvE0adFNW8UPU4v4YEA7KoPHpBZBEn+IZiXoW6NcW0VmezhMxFb3AQ id1c+Q7vh8RIHO80nd3SRcWMqx5tEsbb+O79z6EIwbegt633WwvzAz0qn/oOcfPeRwQO E5gw== X-Gm-Message-State: AOAM530CxW9+UjcqgGzC/DEdNCDL+BB3lsU5Sxs2XKImN7mcUbdUQbtv p8ywRzwBpk+9pTFuBa4tqLbcqIvpf6+bJL4u4pHrgepfEOSBnEgT8ABNEEoKO21avPXkNdxJG/Z b7ZBtKLAfetZFrTuHhuAGL4X043SFPWiqkxwLco6eQNU0bmAmXhbc3jWYHrgXNvx74G8QVMvovu IQ X-Received: by 2002:a17:90b:3b92:: with SMTP id pc18mr33749663pjb.218.1622684171247; Wed, 02 Jun 2021 18:36:11 -0700 (PDT) X-Received: by 2002:a17:90b:3b92:: with SMTP id pc18mr33749621pjb.218.1622684170787; Wed, 02 Jun 2021 18:36:10 -0700 (PDT) Received: from wangxiaodeMacBook-Air.local ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id u24sm125140pfn.31.2021.06.02.18.36.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Jun 2021 18:36:10 -0700 (PDT) Subject: Re: [PATCH v1 1/8] virtio: Force only split mode with protected guest To: Andi Kleen , mst@redhat.com Cc: virtualization@lists.linux-foundation.org, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, iommu@lists.linux-foundation.org, x86@kernel.org, sathyanarayanan.kuppuswamy@linux.intel.com, jpoimboe@redhat.com, linux-kernel@vger.kernel.org References: <20210603004133.4079390-1-ak@linux.intel.com> <20210603004133.4079390-2-ak@linux.intel.com> From: Jason Wang Message-ID: <28c8302b-6833-10b4-c0eb-67456e7c4069@redhat.com> Date: Thu, 3 Jun 2021 09:36:05 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <20210603004133.4079390-2-ak@linux.intel.com> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ?? 2021/6/3 ????8:41, Andi Kleen ะด??: > When running under TDX the virtio host is untrusted. The bulk > of the kernel memory is encrypted and protected, but the virtio > ring is in special shared memory that is shared with the > untrusted host. > > This means virtio needs to be hardened against any attacks from > the host through the ring. Of course it's impossible to prevent DOS > (the host can chose at any time to stop doing IO), but there > should be no buffer overruns or similar that might give access to > any private memory in the guest. > > virtio has a lot of modes, most are difficult to harden. > > The best for hardening seems to be split mode without indirect > descriptors. This also simplifies the hardening job because > it's only a single code path. > > Only allow split mode when in a protected guest. Followon > patches harden the split mode code paths, and we don't want > an malicious host to force anything else. Also disallow > indirect mode for similar reasons. > > Signed-off-by: Andi Kleen > --- > drivers/virtio/virtio_ring.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 71e16b53e9c1..f35629fa47b1 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > #include > > #ifdef DEBUG > @@ -2221,8 +2222,16 @@ void vring_transport_features(struct virtio_device *vdev) > unsigned int i; > > for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) { > + > + /* > + * In protected guest mode disallow packed or indirect > + * because they ain't hardened. > + */ > + > switch (i) { > case VIRTIO_RING_F_INDIRECT_DESC: > + if (protected_guest_has(VM_MEM_ENCRYPT)) > + goto clear; So we will see huge performance regression without indirect descriptor. We need to consider to address this. Thanks > break; > case VIRTIO_RING_F_EVENT_IDX: > break; > @@ -2231,9 +2240,12 @@ void vring_transport_features(struct virtio_device *vdev) > case VIRTIO_F_ACCESS_PLATFORM: > break; > case VIRTIO_F_RING_PACKED: > + if (protected_guest_has(VM_MEM_ENCRYPT)) > + goto clear; > break; > case VIRTIO_F_ORDER_PLATFORM: > break; > + clear: > default: > /* We don't understand this bit. */ > __virtio_clear_bit(vdev, i);