mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-29 05:44:11 +00:00
rbd: harden get_lock_owner_info() a bit
- we want the exclusive lock type, so test for it directly - use sscanf() to actually parse the lock cookie and avoid admitting invalid handles - bail if locker has a blank address Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
This commit is contained in:
parent
f38cb9d9c2
commit
8ff2c64c97
2 changed files with 16 additions and 6 deletions
|
@ -3862,10 +3862,9 @@ static struct ceph_locker *get_lock_owner_info(struct rbd_device *rbd_dev)
|
||||||
u32 num_lockers;
|
u32 num_lockers;
|
||||||
u8 lock_type;
|
u8 lock_type;
|
||||||
char *lock_tag;
|
char *lock_tag;
|
||||||
|
u64 handle;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dout("%s rbd_dev %p\n", __func__, rbd_dev);
|
|
||||||
|
|
||||||
ret = ceph_cls_lock_info(osdc, &rbd_dev->header_oid,
|
ret = ceph_cls_lock_info(osdc, &rbd_dev->header_oid,
|
||||||
&rbd_dev->header_oloc, RBD_LOCK_NAME,
|
&rbd_dev->header_oloc, RBD_LOCK_NAME,
|
||||||
&lock_type, &lock_tag, &lockers, &num_lockers);
|
&lock_type, &lock_tag, &lockers, &num_lockers);
|
||||||
|
@ -3886,18 +3885,28 @@ static struct ceph_locker *get_lock_owner_info(struct rbd_device *rbd_dev)
|
||||||
goto err_busy;
|
goto err_busy;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lock_type == CEPH_CLS_LOCK_SHARED) {
|
if (lock_type != CEPH_CLS_LOCK_EXCLUSIVE) {
|
||||||
rbd_warn(rbd_dev, "shared lock type detected");
|
rbd_warn(rbd_dev, "incompatible lock type detected");
|
||||||
goto err_busy;
|
goto err_busy;
|
||||||
}
|
}
|
||||||
|
|
||||||
WARN_ON(num_lockers != 1);
|
WARN_ON(num_lockers != 1);
|
||||||
if (strncmp(lockers[0].id.cookie, RBD_LOCK_COOKIE_PREFIX,
|
ret = sscanf(lockers[0].id.cookie, RBD_LOCK_COOKIE_PREFIX " %llu",
|
||||||
strlen(RBD_LOCK_COOKIE_PREFIX))) {
|
&handle);
|
||||||
|
if (ret != 1) {
|
||||||
rbd_warn(rbd_dev, "locked by external mechanism, cookie %s",
|
rbd_warn(rbd_dev, "locked by external mechanism, cookie %s",
|
||||||
lockers[0].id.cookie);
|
lockers[0].id.cookie);
|
||||||
goto err_busy;
|
goto err_busy;
|
||||||
}
|
}
|
||||||
|
if (ceph_addr_is_blank(&lockers[0].info.addr)) {
|
||||||
|
rbd_warn(rbd_dev, "locker has a blank address");
|
||||||
|
goto err_busy;
|
||||||
|
}
|
||||||
|
|
||||||
|
dout("%s rbd_dev %p got locker %s%llu@%pISpc/%u handle %llu\n",
|
||||||
|
__func__, rbd_dev, ENTITY_NAME(lockers[0].id.name),
|
||||||
|
&lockers[0].info.addr.in_addr,
|
||||||
|
le32_to_cpu(lockers[0].info.addr.nonce), handle);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
kfree(lock_tag);
|
kfree(lock_tag);
|
||||||
|
|
|
@ -1123,6 +1123,7 @@ bool ceph_addr_is_blank(const struct ceph_entity_addr *addr)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(ceph_addr_is_blank);
|
||||||
|
|
||||||
int ceph_addr_port(const struct ceph_entity_addr *addr)
|
int ceph_addr_port(const struct ceph_entity_addr *addr)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue