Skip to content

Commit 8ff2c64

Browse files
committed
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>
1 parent f38cb9d commit 8ff2c64

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

drivers/block/rbd.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,10 +3862,9 @@ static struct ceph_locker *get_lock_owner_info(struct rbd_device *rbd_dev)
38623862
u32 num_lockers;
38633863
u8 lock_type;
38643864
char *lock_tag;
3865+
u64 handle;
38653866
int ret;
38663867

3867-
dout("%s rbd_dev %p\n", __func__, rbd_dev);
3868-
38693868
ret = ceph_cls_lock_info(osdc, &rbd_dev->header_oid,
38703869
&rbd_dev->header_oloc, RBD_LOCK_NAME,
38713870
&lock_type, &lock_tag, &lockers, &num_lockers);
@@ -3886,18 +3885,28 @@ static struct ceph_locker *get_lock_owner_info(struct rbd_device *rbd_dev)
38863885
goto err_busy;
38873886
}
38883887

3889-
if (lock_type == CEPH_CLS_LOCK_SHARED) {
3890-
rbd_warn(rbd_dev, "shared lock type detected");
3888+
if (lock_type != CEPH_CLS_LOCK_EXCLUSIVE) {
3889+
rbd_warn(rbd_dev, "incompatible lock type detected");
38913890
goto err_busy;
38923891
}
38933892

38943893
WARN_ON(num_lockers != 1);
3895-
if (strncmp(lockers[0].id.cookie, RBD_LOCK_COOKIE_PREFIX,
3896-
strlen(RBD_LOCK_COOKIE_PREFIX))) {
3894+
ret = sscanf(lockers[0].id.cookie, RBD_LOCK_COOKIE_PREFIX " %llu",
3895+
&handle);
3896+
if (ret != 1) {
38973897
rbd_warn(rbd_dev, "locked by external mechanism, cookie %s",
38983898
lockers[0].id.cookie);
38993899
goto err_busy;
39003900
}
3901+
if (ceph_addr_is_blank(&lockers[0].info.addr)) {
3902+
rbd_warn(rbd_dev, "locker has a blank address");
3903+
goto err_busy;
3904+
}
3905+
3906+
dout("%s rbd_dev %p got locker %s%llu@%pISpc/%u handle %llu\n",
3907+
__func__, rbd_dev, ENTITY_NAME(lockers[0].id.name),
3908+
&lockers[0].info.addr.in_addr,
3909+
le32_to_cpu(lockers[0].info.addr.nonce), handle);
39013910

39023911
out:
39033912
kfree(lock_tag);

net/ceph/messenger.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,7 @@ bool ceph_addr_is_blank(const struct ceph_entity_addr *addr)
11231123
return true;
11241124
}
11251125
}
1126+
EXPORT_SYMBOL(ceph_addr_is_blank);
11261127

11271128
int ceph_addr_port(const struct ceph_entity_addr *addr)
11281129
{

0 commit comments

Comments
 (0)