Tighten reencryption direction field validation.

This commit is contained in:
Ondrej Kozina
2019-07-25 14:10:01 +02:00
parent 1b82e70fc1
commit a1111c7aa0

View File

@@ -256,8 +256,8 @@ static int reenc_keyslot_dump(struct crypt_device *cd, int keyslot)
static int reenc_keyslot_validate(struct crypt_device *cd, json_object *jobj_keyslot) static int reenc_keyslot_validate(struct crypt_device *cd, json_object *jobj_keyslot)
{ {
json_object *jobj_mode, *jobj_area, *jobj_type, *jobj_shift_size, *jobj_hash, *jobj_sector_size; json_object *jobj_mode, *jobj_area, *jobj_type, *jobj_shift_size, *jobj_hash, *jobj_sector_size, *jobj_direction;
const char *mode, *type; const char *mode, *type, *direction;
uint32_t sector_size; uint32_t sector_size;
uint64_t shift_size; uint64_t shift_size;
@@ -277,12 +277,14 @@ static int reenc_keyslot_validate(struct crypt_device *cd, json_object *jobj_key
return -EINVAL; return -EINVAL;
jobj_mode = json_contains(cd, jobj_keyslot, "", "reencrypt keyslot", "mode", json_type_string); jobj_mode = json_contains(cd, jobj_keyslot, "", "reencrypt keyslot", "mode", json_type_string);
jobj_direction = json_contains(cd, jobj_keyslot, "", "reencrypt keyslot", "direction", json_type_string);
if (!jobj_mode || !json_contains(cd, jobj_keyslot, "", "reencrypt keyslot", "direction", json_type_string)) if (!jobj_mode || !jobj_direction)
return -EINVAL; return -EINVAL;
mode = json_object_get_string(jobj_mode); mode = json_object_get_string(jobj_mode);
type = json_object_get_string(jobj_type); type = json_object_get_string(jobj_type);
direction = json_object_get_string(jobj_direction);
if (strcmp(mode, "reencrypt") && strcmp(mode, "encrypt") && if (strcmp(mode, "reencrypt") && strcmp(mode, "encrypt") &&
strcmp(mode, "decrypt")) { strcmp(mode, "decrypt")) {
@@ -290,6 +292,11 @@ static int reenc_keyslot_validate(struct crypt_device *cd, json_object *jobj_key
return -EINVAL; return -EINVAL;
} }
if (strcmp(direction, "forward") && strcmp(direction, "backward")) {
log_dbg(cd, "Illegal reencrypt direction %s.", direction);
return -EINVAL;
}
if (!strcmp(type, "checksum")) { if (!strcmp(type, "checksum")) {
jobj_hash = json_contains(cd, jobj_area, "type:checksum", "Keyslot area", "hash", json_type_string); jobj_hash = json_contains(cd, jobj_area, "type:checksum", "Keyslot area", "hash", json_type_string);
jobj_sector_size = json_contains(cd, jobj_area, "type:checksum", "Keyslot area", "sector_size", json_type_int); jobj_sector_size = json_contains(cd, jobj_area, "type:checksum", "Keyslot area", "sector_size", json_type_int);