From nobody Fri Dec 19 07:15:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621509019; cv=none; d=zohomail.com; s=zohoarc; b=grEknvvx9JgBRQCeKgD/ke2zyFzb/jWtnJIiQv+dvUeSalvKHRl/Y4lUDmubSDUP174OFmCp6fLvCKm4l5ZDFArp+dPyGk9piPsEOFQdXVO8pZtFYQszGf/X4So3RlS7iUMEsV3l9Py3lirsBZkqyF8/L9rEDt3G+ltecUlIIJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621509019; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=SEIK0+f8xAhENSUO1Wsp9GXIhMyGmKAMVfEhOA0o4Xo=; b=DYMSyIYXHNXt9sZ53dLgOL3JrHTGdT9OafXBSzdPhl1PJU8Wm+D5nlHDev6Xd+HItXE7Cmsmb30MAoF6vIJjga+dioRi86qmmyew6VtfSp9XcduJ59gRFGGnNTXRGuaE6I/E55el8B66yO0RHcJYWlmqpMmcLxUDQ3LEnOpqZTs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1621509019261518.9309014680293; Thu, 20 May 2021 04:10:19 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-420-erX2qkoLNsW6y0owdAtYHg-1; Thu, 20 May 2021 07:10:16 -0400 Received: by mail-wr1-f69.google.com with SMTP id i15-20020a5d558f0000b029011215b1cf5cso2138822wrv.22 for ; Thu, 20 May 2021 04:10:16 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (31.red-83-51-215.dynamicip.rima-tde.net. [83.51.215.31]) by smtp.gmail.com with ESMTPSA id l3sm2331270wmh.2.2021.05.20.04.10.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 04:10:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621509018; 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=SEIK0+f8xAhENSUO1Wsp9GXIhMyGmKAMVfEhOA0o4Xo=; b=h7foC6jXPwSLlnK0IANgf5ObN46rCZvn++ydBmaJbeTZZUTuZA4OjLrZX9jbZpbj0Swfqq rBl0fP+hmMW6d4RZEHPInyuwdd+zbBQpmZ/b/TE9tNrwwd6sMk7VUcD0Eyk4Wuk00o7/+/ Np6zv/7dA0+78L2bsKTYF1/RRBq1TpQ= X-MC-Unique: erX2qkoLNsW6y0owdAtYHg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SEIK0+f8xAhENSUO1Wsp9GXIhMyGmKAMVfEhOA0o4Xo=; b=SLd5KleIO8rpr5uBdo2zLJTr7mBsXtvdi+XWmvSTNbxmH4J00WJlC9TdPXWcX76SKN NogUJV0kNHf3KV6b0K0sLOpieN2cdOmQCiE/pGKjOMwofE/4RDvXdJI/DoadBdSHnh9b Rl0S3ChY1qwIQl3fA2ouOieTwIl/fWU3v8WBIsDyHaM6OzCpOqIPnLCb0T7RtWgUNdo/ jOZ39+k1Tq3qenuASVuIWoMdEQzTSRO1PM5eeGGrm6bWZqIw7AGJPslVgu/IpDN0Ytj+ UD5mYkAEENX+1xBBdTDlWshJe7E1FcouZ/Y+qiZBXMHb5JwUno7brAUYxZA95f9IClEl HU+Q== X-Gm-Message-State: AOAM531ZuTupzem/E/dIO0BCi6oJdqeSFWt/sswQG+2NMvwYD4XnQZ7f 4nWKFUsxS9oDYTP1ZSi9MJ0jv/OP9ckfW72RIVwMbIePsb6fMukKpHZCj8grHIAKXvYVu7mZnJp JI47M9h5FIOGgnQ== X-Received: by 2002:adf:e608:: with SMTP id p8mr3801832wrm.162.1621509015591; Thu, 20 May 2021 04:10:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgOa3Tel7oAr+U0C0L/KLNS+VyKeVlMa8TYcIL1vcCGh34R3TMJnS/Xhv4kOqefrqVE7VApA== X-Received: by 2002:adf:e608:: with SMTP id p8mr3801817wrm.162.1621509015405; Thu, 20 May 2021 04:10:15 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , Peter Maydell , Peter Xu , Paolo Bonzini , Richard Henderson , Bibo Mao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH 12/12] hw/virtio: Display error if vring flag field is not aligned Date: Thu, 20 May 2021 13:09:19 +0200 Message-Id: <20210520110919.2483190-13-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210520110919.2483190-1-philmd@redhat.com> References: <20210520110919.2483190-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Per the virtio spec [*] the vring is aligned, so the 'flag' field is also 16-bit aligned. If it is not, this is a guest error, and we'd rather report any malicious activity. Enforce the transaction alignment by setting the 'aligned' attribute and log unaligned addresses. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/virtio/virtio.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 1b8bc194ce1..f19d12fc71e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -291,15 +291,24 @@ static inline bool vring_avail_flags(VirtQueue *vq, u= int16_t *val) { VRingMemoryRegionCaches *caches =3D vring_get_region_caches(vq); hwaddr pa =3D offsetof(VRingAvail, flags); + MemTxAttrs attrs =3D { .aligned =3D 1 }; + MemTxResult res; =20 if (!caches) { *val =3D 0; return true; } =20 - *val =3D virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, = pa); + *val =3D virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, + pa, attrs, &res); + if (res =3D=3D MEMTX_UNALIGNED_ERROR) { + qemu_log_mask(LOG_GUEST_ERROR, + "virtio: vring flag address 0x%" HWADDR_PRIX " " + "is not aligned\n", pa); + return false; + } =20 - return true; + return res =3D=3D MEMTX_OK; } =20 /* Called within rcu_read_lock(). */ --=20 2.26.3