You need to sign in or sign up before continuing.
提交 3f99d64d 编写于 作者: J John Ferlan

storage_conf: Resolve libvirtd crash matching scsi_host

https://bugzilla.redhat.com/show_bug.cgi?id=1146837

Resolve a crash in libvirtd resulting from commit id 'a4bd62ad' (1.0.6)
which added parentaddr and unique_id to allow unique identification of
a scsi_host, but assumed that all the pool entries and the incoming
definition would be similarly defined. If the existing pool uses the
'name' attribute and an incoming pool is using the parentaddr/unique_id,
then the code will attempt to compare the existing name string against
the incoming name string which doesn't exist (is NULL) and results in
a core (STREQ).

Conversely, if the existing pool used the parentaddr/unique_id and the
to be defined pool used the name, then the comparison would be against
the parentaddr, but since the incoming pool doesn't have one - that would
leave the comparison against a parentaddr of all 0's and a unique_id of 0,
which will always comparison to fail. This means someone could define the
same source adapter for two pools

In order to resolve this, adjust the code to get the 'host#' to be used
by the storage scsi backend in order to check/start the pool and make sure
the incoming definition doesn't match any of the existing pool defs.
上级 beff5d4e
...@@ -2062,26 +2062,37 @@ virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools, ...@@ -2062,26 +2062,37 @@ virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
return ret; return ret;
} }
static bool static int
matchSCSIAdapterParent(virStoragePoolObjPtr pool, getSCSIHostNumber(virStoragePoolSourceAdapter adapter,
virStoragePoolDefPtr def) unsigned int *hostnum)
{ {
virDevicePCIAddressPtr pooladdr = int ret = -1;
&pool->def->source.adapter.data.scsi_host.parentaddr; unsigned int num;
virDevicePCIAddressPtr defaddr = char *name = NULL;
&def->source.adapter.data.scsi_host.parentaddr;
int pool_unique_id = if (adapter.data.scsi_host.has_parent) {
pool->def->source.adapter.data.scsi_host.unique_id; virDevicePCIAddress addr = adapter.data.scsi_host.parentaddr;
int def_unique_id = unsigned int unique_id = adapter.data.scsi_host.unique_id;
def->source.adapter.data.scsi_host.unique_id;
if (pooladdr->domain == defaddr->domain && if (!(name = virGetSCSIHostNameByParentaddr(addr.domain,
pooladdr->bus == defaddr->bus && addr.bus,
pooladdr->slot == defaddr->slot && addr.slot,
pooladdr->function == defaddr->function && addr.function,
pool_unique_id == def_unique_id) { unique_id)))
return true; goto cleanup;
} if (virGetSCSIHostNumber(name, &num) < 0)
return false; goto cleanup;
} else {
if (virGetSCSIHostNumber(adapter.data.scsi_host.name, &num) < 0)
goto cleanup;
}
*hostnum = num;
ret = 0;
cleanup:
VIR_FREE(name);
return ret;
} }
int int
...@@ -2130,14 +2141,14 @@ virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools, ...@@ -2130,14 +2141,14 @@ virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools,
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST && VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST &&
def->source.adapter.type == def->source.adapter.type ==
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) { VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
if (pool->def->source.adapter.data.scsi_host.name) { unsigned int pool_hostnum, def_hostnum;
if (STREQ(pool->def->source.adapter.data.scsi_host.name,
def->source.adapter.data.scsi_host.name)) if (getSCSIHostNumber(pool->def->source.adapter,
matchpool = pool; &pool_hostnum) < 0 ||
} else { getSCSIHostNumber(def->source.adapter, &def_hostnum) < 0)
if (matchSCSIAdapterParent(pool, def)) goto error;
matchpool = pool; if (pool_hostnum == def_hostnum)
} matchpool = pool;
} }
break; break;
case VIR_STORAGE_POOL_ISCSI: case VIR_STORAGE_POOL_ISCSI:
...@@ -2177,6 +2188,10 @@ virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools, ...@@ -2177,6 +2188,10 @@ virStoragePoolSourceFindDuplicate(virStoragePoolObjListPtr pools,
ret = -1; ret = -1;
} }
return ret; return ret;
error:
virStoragePoolObjUnlock(pool);
return -1;
} }
void void
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册