Skip to content

Commit 3d788b2

Browse files
rpedgecoliuw
authored andcommitted
uio_hv_generic: Don't free decrypted memory
In CoCo VMs it is possible for the untrusted host to cause set_memory_encrypted() or set_memory_decrypted() to fail such that an error is returned and the resulting memory is shared. Callers need to take care to handle these errors to avoid returning decrypted (shared) memory to the page allocator, which could lead to functional or security issues. The VMBus device UIO driver could free decrypted/shared pages if set_memory_decrypted() fails. Check the decrypted field in the gpadl to decide whether to free the memory. Signed-off-by: Rick Edgecombe <[email protected]> Signed-off-by: Michael Kelley <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]> Message-ID: <[email protected]>
1 parent bbf9ac3 commit 3d788b2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/uio/uio_hv_generic.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,14 @@ hv_uio_cleanup(struct hv_device *dev, struct hv_uio_private_data *pdata)
181181
{
182182
if (pdata->send_gpadl.gpadl_handle) {
183183
vmbus_teardown_gpadl(dev->channel, &pdata->send_gpadl);
184-
vfree(pdata->send_buf);
184+
if (!pdata->send_gpadl.decrypted)
185+
vfree(pdata->send_buf);
185186
}
186187

187188
if (pdata->recv_gpadl.gpadl_handle) {
188189
vmbus_teardown_gpadl(dev->channel, &pdata->recv_gpadl);
189-
vfree(pdata->recv_buf);
190+
if (!pdata->recv_gpadl.decrypted)
191+
vfree(pdata->recv_buf);
190192
}
191193
}
192194

@@ -295,7 +297,8 @@ hv_uio_probe(struct hv_device *dev,
295297
ret = vmbus_establish_gpadl(channel, pdata->recv_buf,
296298
RECV_BUFFER_SIZE, &pdata->recv_gpadl);
297299
if (ret) {
298-
vfree(pdata->recv_buf);
300+
if (!pdata->recv_gpadl.decrypted)
301+
vfree(pdata->recv_buf);
299302
goto fail_close;
300303
}
301304

@@ -317,7 +320,8 @@ hv_uio_probe(struct hv_device *dev,
317320
ret = vmbus_establish_gpadl(channel, pdata->send_buf,
318321
SEND_BUFFER_SIZE, &pdata->send_gpadl);
319322
if (ret) {
320-
vfree(pdata->send_buf);
323+
if (!pdata->send_gpadl.decrypted)
324+
vfree(pdata->send_buf);
321325
goto fail_close;
322326
}
323327

0 commit comments

Comments
 (0)