[PATCH v2 4/5] bhyve: validate serial devices validation

Roman Bogorodskiy posted 5 patches 1 month, 3 weeks ago
[PATCH v2 4/5] bhyve: validate serial devices validation
Posted by Roman Bogorodskiy 1 month, 3 weeks ago
Extend bhyveDomainDeviceDefValidate() to check that:

 - only 'nmdm' or 'tcp' serial devices are used,
 - serial device count is not more than supported,
 - only listening raw TCP sockets are used.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
 src/bhyve/bhyve_domain.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index c9bbf27d83..9dec300a99 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -263,6 +263,33 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev,
                            _("Only 'virio' RNG device model is supported"));
             return -1;
         }
+    } else if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
+               dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) {
+        virDomainChrDef *chr = dev->data.chr;
+        if (chr->source->type != VIR_DOMAIN_CHR_TYPE_NMDM &&
+            chr->source->type != VIR_DOMAIN_CHR_TYPE_TCP) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Only 'nmdm' and 'tcp' console types are supported"));
+            return -1;
+        }
+        if (chr->target.port > 3) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Only four serial ports are supported"));
+            return -1;
+        }
+        if (chr->source->type == VIR_DOMAIN_CHR_TYPE_TCP) {
+            if (chr->source->data.tcp.listen == false) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Only listening TCP sockets are supported"));
+                return -1;
+            }
+
+            if (chr->source->data.tcp.protocol != VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Only 'raw' protocol is supported for TCP sockets"));
+                return -1;
+            }
+        }
     }
 
     return 0;
-- 
2.49.0
Re: [PATCH v2 4/5] bhyve: validate serial devices validation
Posted by Daniel P. Berrangé via Devel 1 month, 3 weeks ago
On Wed, Jul 16, 2025 at 06:28:46PM +0200, Roman Bogorodskiy wrote:
> Extend bhyveDomainDeviceDefValidate() to check that:
> 
>  - only 'nmdm' or 'tcp' serial devices are used,
>  - serial device count is not more than supported,
>  - only listening raw TCP sockets are used.
> 
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> ---
>  src/bhyve/bhyve_domain.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|