提交 ce01a2b1 编写于 作者: M Michal Privoznik

qemuDomainAttachDeviceMknodHelper: Don't unlink() so often

Not that I'd encounter any bug here, but the code doesn't look
100% correct. Imagine, somebody is trying to attach a device to a
domain, and the device's /dev entry already exists in the qemu
namespace. This is handled gracefully and the control continues
with setting up ACLs and calling security manager to set up
labels. Now, if any of these steps fail, control jump on the
'cleanup' label and unlink() the file straight away. Even when it
was not us who created the file in the first place. This can be
possibly dangerous.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 3aae99fe
...@@ -7523,6 +7523,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED, ...@@ -7523,6 +7523,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED,
{ {
struct qemuDomainAttachDeviceMknodData *data = opaque; struct qemuDomainAttachDeviceMknodData *data = opaque;
int ret = -1; int ret = -1;
bool delDevice = false;
virSecurityManagerPostFork(data->driver->securityManager); virSecurityManagerPostFork(data->driver->securityManager);
...@@ -7545,6 +7546,8 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED, ...@@ -7545,6 +7546,8 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED,
data->file); data->file);
goto cleanup; goto cleanup;
} }
} else {
delDevice = true;
} }
if (virFileSetACLs(data->file, data->acl) < 0 && if (virFileSetACLs(data->file, data->acl) < 0 &&
...@@ -7608,7 +7611,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED, ...@@ -7608,7 +7611,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED,
ret = 0; ret = 0;
cleanup: cleanup:
if (ret < 0) if (ret < 0 && delDevice)
unlink(data->file); unlink(data->file);
virFileFreeACLs(&data->acl); virFileFreeACLs(&data->acl);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册