crush: ensure take bucket value is valid
authorIlya Dryomov <idryomov@gmail.com>
Sun, 31 Jan 2016 13:36:05 +0000 (14:36 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Thu, 4 Feb 2016 17:25:50 +0000 (18:25 +0100)
Ensure that the take argument is a valid bucket ID before indexing the
buckets array.

Reflects ceph.git commit 93ec538e8a667699876b72459b8ad78966d89c61.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Sage Weil <sage@redhat.com>
net/ceph/crush/mapper.c

index 97ecf6f262aac98b27fa44e7a23f166d13cf2d31..abb700621e4ab040b1a0450f24e9a9267d2a6625 100644 (file)
@@ -835,7 +835,8 @@ int crush_do_rule(const struct crush_map *map,
                case CRUSH_RULE_TAKE:
                        if ((curstep->arg1 >= 0 &&
                             curstep->arg1 < map->max_devices) ||
-                           (-1-curstep->arg1 < map->max_buckets &&
+                           (-1-curstep->arg1 >= 0 &&
+                            -1-curstep->arg1 < map->max_buckets &&
                             map->buckets[-1-curstep->arg1])) {
                                w[0] = curstep->arg1;
                                wsize = 1;