mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 09:55:18 +00:00
qemu: let virCommand set child process security labels/uid/gid
The qemu driver had been calling virSecurityManagerSetProcessLabel() from a "pre-exec hook" function that is run after the child is forked, but before exec'ing qemu. This is problematic because the uid and gid of the child are set by the security driver, but capabilities are dropped by virCommand - such separation doesn't work; the two operations must be done together or the capabilities do not transfer properly to the child process. This patch switches to using virSecurityManagerSetChildProcessLabel(), which is called prior to virCommandRun() (rather than being called *during* virCommandrun() by the hook function), and doesn't set the UID/GID/security label directly, but instead merely informs virCommand what it should set them all to when the time is appropriate. This lets virCommand choose to do the uid/gid and caps dropping all at the same time if it wants (it does *want* to, but isn't doing so yet; that's for an upcoming patch).
This commit is contained in:
parent
7bf1aa0b9b
commit
0345c7281b
@ -2763,10 +2763,6 @@ static int qemuProcessHook(void *data)
|
||||
if (qemuProcessInitNumaMemoryPolicy(h->vm, h->nodemask) < 0)
|
||||
goto cleanup;
|
||||
|
||||
VIR_DEBUG("Setting up security labelling");
|
||||
if (virSecurityManagerSetProcessLabel(h->driver->securityManager, h->vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
@ -3892,6 +3888,12 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
|
||||
virCommandSetPreExecHook(cmd, qemuProcessHook, &hookData);
|
||||
|
||||
VIR_DEBUG("Setting up security labelling");
|
||||
if (virSecurityManagerSetChildProcessLabel(driver->securityManager,
|
||||
vm->def, cmd) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virCommandSetOutputFD(cmd, &logfile);
|
||||
virCommandSetErrorFD(cmd, &logfile);
|
||||
virCommandNonblockingFDs(cmd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user