@@ -95,16 +95,25 @@ int32_t krun_set_root_disk(uint32_t ctx_id, const char *disk_path);
95
95
int32_t krun_set_data_disk (uint32_t ctx_id , const char * disk_path );
96
96
97
97
/**
98
- * Adds a disk image to be used as a general partition for the microVM.
98
+ * Adds a disk image to be used as a general partition for the microVM. The only supported image
99
+ * format is "raw".
99
100
*
100
101
* This API is mutually exclusive with the deprecated krun_set_root_disk and
101
102
* krun_set_data_disk methods and must not be used together.
102
103
*
104
+ * SECURITY NOTE:
105
+ * Libkrun is not responsible for probing the disk image provided, as probing a disk image should
106
+ * be avoided. However, if one must probe the disk image, it falls onto the user. The disk image
107
+ * must only be probed once, and the probe of the image must be done before the first boot of the
108
+ * microVM.
109
+ *
110
+ * The disk image is assumed to be a Raw disk image, and trust is put into the user to
111
+ * correctly and securely probe the disk image, if at all.
112
+ *
103
113
* Arguments:
104
114
* "ctx_id" - the configuration context ID.
105
115
* "block_id" - a null-terminated string representing the partition.
106
- * "disk_path" - a null-terminated string representing the path leading to the disk image that
107
- * contains the root file-system.
116
+ * "disk_path" - a null-terminated string representing the path leading to the disk image.
108
117
* "read_only" - whether the mount should be read-only. Required if the caller does not have
109
118
* write permissions (for disk images in /usr/share).
110
119
*
@@ -113,6 +122,49 @@ int32_t krun_set_data_disk(uint32_t ctx_id, const char *disk_path);
113
122
*/
114
123
int32_t krun_add_disk (uint32_t ctx_id , const char * block_id , const char * disk_path , bool read_only );
115
124
125
+ /* Supported disk image formats */
126
+ #define KRUN_DISK_FORMAT_RAW 0
127
+ #define KRUN_DISK_FORMAT_QCOW2 1
128
+ /**
129
+ * Adds a disk image to be used as a general partition for the microVM. The supported
130
+ * image formats are: "raw" and "qcow2".
131
+ *
132
+ * This API is mutually exclusive with the deprecated krun_set_root_disk and
133
+ * krun_set_data_disk methods and must not be used together.
134
+ *
135
+ * SECURITY NOTE:
136
+ * Libkrun is not responsible for probing the disk image provided, as probing a disk image should
137
+ * be avoided. However, if one must probe the disk image, it falls onto the user. The disk image
138
+ * must only be probed once, and the probe of the image must be done before the first boot of the
139
+ * microVM.
140
+ *
141
+ * The disk image may be in the Raw or Qcow2 format, but trust is put into the user to
142
+ * correctly and securely probe the disk image, if at all.
143
+ *
144
+ * It is possible for a Raw disk image to be probed, and have the guest write a Qcow2
145
+ * image header into the Raw file's first sector. If the disk image is then re-probed, and the
146
+ * user tells libkrun it is a Qcow2, then libkrun will boot the disk image as a Qcow2. Qcow2
147
+ * files can, and will, open other files. The guest will most likely have access to the data in those
148
+ * files, essentially giving the guest access to any file on the host system the disk emulation
149
+ * has access to.
150
+ *
151
+ * Arguments:
152
+ * "ctx_id" - the configuration context ID.
153
+ * "block_id" - a null-terminated string representing the partition.
154
+ * "disk_path" - a null-terminated string representing the path leading to the disk image.
155
+ * "disk_format" - the disk image format (i.e. KRUN_DISK_FORMAT_{RAW, QCOW2})
156
+ * "read_only" - whether the mount should be read-only. Required if the caller does not have
157
+ * write permissions (for disk images in /usr/share).
158
+ *
159
+ * Returns:
160
+ * Zero on success or a negative error number on failure.
161
+ */
162
+ int32_t krun_add_disk2 (uint32_t ctx_id ,
163
+ const char * block_id ,
164
+ const char * disk_path ,
165
+ uint32_t disk_format ,
166
+ bool read_only );
167
+
116
168
/**
117
169
* NO LONGER SUPPORTED. DO NOT USE.
118
170
*
0 commit comments