mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
security: Don't remember seclabel for paths we haven't locked successfully
There are some cases where we want to remember the original owner of a file but we fail to lock it for XATTR change (e.g. root squashed NFS). If that is the case we error out and refuse to start a domain. Well, we can do better if we disable remembering for paths we haven't locked successfully. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
256e01e59e
commit
5fddf61351
@ -240,6 +240,20 @@ virSecurityDACTransactionRun(pid_t pid G_GNUC_UNUSED,
|
||||
|
||||
if (!(state = virSecurityManagerMetadataLock(list->manager, paths, npaths)))
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < list->nItems; i++) {
|
||||
virSecurityDACChownItemPtr item = list->items[i];
|
||||
size_t j;
|
||||
|
||||
for (j = 0; j < state->nfds; j++) {
|
||||
if (STREQ_NULLABLE(item->path, state->paths[j]))
|
||||
break;
|
||||
}
|
||||
|
||||
/* If path wasn't locked, don't try to remember its label. */
|
||||
if (j == state->nfds)
|
||||
item->remember = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < list->nItems; i++) {
|
||||
|
@ -1245,13 +1245,6 @@ virSecurityManagerRestoreTPMLabels(virSecurityManagerPtr mgr,
|
||||
}
|
||||
|
||||
|
||||
struct _virSecurityManagerMetadataLockState {
|
||||
size_t nfds; /* Captures size of both @fds and @paths */
|
||||
int *fds;
|
||||
const char **paths;
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
cmpstringp(const void *p1, const void *p2)
|
||||
{
|
||||
|
@ -203,6 +203,12 @@ int virSecurityManagerRestoreTPMLabels(virSecurityManagerPtr mgr,
|
||||
|
||||
typedef struct _virSecurityManagerMetadataLockState virSecurityManagerMetadataLockState;
|
||||
typedef virSecurityManagerMetadataLockState *virSecurityManagerMetadataLockStatePtr;
|
||||
struct _virSecurityManagerMetadataLockState {
|
||||
size_t nfds; /* Captures size of both @fds and @paths */
|
||||
int *fds;
|
||||
const char **paths;
|
||||
};
|
||||
|
||||
|
||||
virSecurityManagerMetadataLockStatePtr
|
||||
virSecurityManagerMetadataLock(virSecurityManagerPtr mgr,
|
||||
|
@ -271,6 +271,20 @@ virSecuritySELinuxTransactionRun(pid_t pid G_GNUC_UNUSED,
|
||||
|
||||
if (!(state = virSecurityManagerMetadataLock(list->manager, paths, npaths)))
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < list->nItems; i++) {
|
||||
virSecuritySELinuxContextItemPtr item = list->items[i];
|
||||
size_t j;
|
||||
|
||||
for (j = 0; j < state->nfds; j++) {
|
||||
if (STREQ_NULLABLE(item->path, state->paths[j]))
|
||||
break;
|
||||
}
|
||||
|
||||
/* If path wasn't locked, don't try to remember its label. */
|
||||
if (j == state->nfds)
|
||||
item->remember = false;
|
||||
}
|
||||
}
|
||||
|
||||
rv = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user