crypto: move PMD driver input validation to common function
Previously was only checking the crypto driver name in the conf file parsing and not when it came in via RPC so a bogus name could result in nasty stuff. Moved the check to the common function used by both paths so a bad name will fail gracefully. Addresses github issue #444 Change-Id: Id881d9d448d0bb6935162484154964a1d5d59a0b Signed-off-by: paul luse <paul.e.luse@intel.com> Reviewed-on: https://review.gerrithub.io/427164 Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
4db5688e32
commit
369719c26b
@ -1036,7 +1036,8 @@ vbdev_crypto_insert_name(const char *bdev_name, const char *vbdev_name,
|
||||
const char *crypto_pmd, const char *key)
|
||||
{
|
||||
struct bdev_names *name;
|
||||
int rc;
|
||||
int rc, j;
|
||||
bool found = false;
|
||||
|
||||
name = calloc(1, sizeof(struct bdev_names));
|
||||
if (!name) {
|
||||
@ -1064,6 +1065,17 @@ vbdev_crypto_insert_name(const char *bdev_name, const char *vbdev_name,
|
||||
rc = -ENOMEM;
|
||||
goto error_alloc_dname;
|
||||
}
|
||||
for (j = 0; j < MAX_NUM_DRV_TYPES ; j++) {
|
||||
if (strcmp(crypto_pmd, g_driver_names[j]) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
SPDK_ERRLOG("invalid crypto PMD type %s\n", crypto_pmd);
|
||||
rc = -EINVAL;
|
||||
goto error_invalid_pmd;
|
||||
}
|
||||
|
||||
name->key = strdup(key);
|
||||
if (!name->key) {
|
||||
@ -1084,6 +1096,7 @@ vbdev_crypto_insert_name(const char *bdev_name, const char *vbdev_name,
|
||||
/* Error cleanup paths. */
|
||||
error_invalid_key:
|
||||
error_alloc_key:
|
||||
error_invalid_pmd:
|
||||
free(name->drv_name);
|
||||
error_alloc_dname:
|
||||
free(name->vbdev_name);
|
||||
@ -1151,8 +1164,7 @@ vbdev_crypto_init(void)
|
||||
const char *conf_bdev_name = NULL;
|
||||
const char *conf_vbdev_name = NULL;
|
||||
const char *crypto_pmd = NULL;
|
||||
bool found = false;
|
||||
int i, j;
|
||||
int i;
|
||||
int rc = 0;
|
||||
const char *key = NULL;
|
||||
|
||||
@ -1192,17 +1204,6 @@ vbdev_crypto_init(void)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (j = 0; j < MAX_NUM_DRV_TYPES ; j++) {
|
||||
if (strcmp(crypto_pmd, g_driver_names[j]) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
SPDK_ERRLOG("crypto configuration invalid PMD type\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = vbdev_crypto_insert_name(conf_bdev_name, conf_vbdev_name,
|
||||
crypto_pmd, key);
|
||||
if (rc != 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user