Commit ca8f4bee authored by Dongli Zhang's avatar Dongli Zhang Committed by Christoph Hellwig

nvme-fcloop: verify wwnn and wwpn format

The nvme host and target verify the wwnn and wwpn format via
nvme_fc_parse_traddr(). For instance, it is required that the length of
wwnn to be either 21 ("nn-0x") or 19 (nn-).

Add this verification to nvme-fcloop so that the input should always be in
hex and the length of input should always be 18.

Otherwise, the user may use e.g. 0x2 to create fcloop local port, while
0x0000000000000002 is required for nvme host and target. This makes the
requirement of format confusing.
Signed-off-by: default avatarDongli Zhang <dongli.zhang@oracle.com>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Reviewed-by: default avatarJames Smart <james.smart@broadcom.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent a0f0dbaa
...@@ -43,6 +43,17 @@ static const match_table_t opt_tokens = { ...@@ -43,6 +43,17 @@ static const match_table_t opt_tokens = {
{ NVMF_OPT_ERR, NULL } { NVMF_OPT_ERR, NULL }
}; };
static int fcloop_verify_addr(substring_t *s)
{
size_t blen = s->to - s->from + 1;
if (strnlen(s->from, blen) != NVME_FC_TRADDR_HEXNAMELEN + 2 ||
strncmp(s->from, "0x", 2))
return -EINVAL;
return 0;
}
static int static int
fcloop_parse_options(struct fcloop_ctrl_options *opts, fcloop_parse_options(struct fcloop_ctrl_options *opts,
const char *buf) const char *buf)
...@@ -64,14 +75,16 @@ fcloop_parse_options(struct fcloop_ctrl_options *opts, ...@@ -64,14 +75,16 @@ fcloop_parse_options(struct fcloop_ctrl_options *opts,
opts->mask |= token; opts->mask |= token;
switch (token) { switch (token) {
case NVMF_OPT_WWNN: case NVMF_OPT_WWNN:
if (match_u64(args, &token64)) { if (fcloop_verify_addr(args) ||
match_u64(args, &token64)) {
ret = -EINVAL; ret = -EINVAL;
goto out_free_options; goto out_free_options;
} }
opts->wwnn = token64; opts->wwnn = token64;
break; break;
case NVMF_OPT_WWPN: case NVMF_OPT_WWPN:
if (match_u64(args, &token64)) { if (fcloop_verify_addr(args) ||
match_u64(args, &token64)) {
ret = -EINVAL; ret = -EINVAL;
goto out_free_options; goto out_free_options;
} }
...@@ -92,14 +105,16 @@ fcloop_parse_options(struct fcloop_ctrl_options *opts, ...@@ -92,14 +105,16 @@ fcloop_parse_options(struct fcloop_ctrl_options *opts,
opts->fcaddr = token; opts->fcaddr = token;
break; break;
case NVMF_OPT_LPWWNN: case NVMF_OPT_LPWWNN:
if (match_u64(args, &token64)) { if (fcloop_verify_addr(args) ||
match_u64(args, &token64)) {
ret = -EINVAL; ret = -EINVAL;
goto out_free_options; goto out_free_options;
} }
opts->lpwwnn = token64; opts->lpwwnn = token64;
break; break;
case NVMF_OPT_LPWWPN: case NVMF_OPT_LPWWPN:
if (match_u64(args, &token64)) { if (fcloop_verify_addr(args) ||
match_u64(args, &token64)) {
ret = -EINVAL; ret = -EINVAL;
goto out_free_options; goto out_free_options;
} }
...@@ -141,14 +156,16 @@ fcloop_parse_nm_options(struct device *dev, u64 *nname, u64 *pname, ...@@ -141,14 +156,16 @@ fcloop_parse_nm_options(struct device *dev, u64 *nname, u64 *pname,
token = match_token(p, opt_tokens, args); token = match_token(p, opt_tokens, args);
switch (token) { switch (token) {
case NVMF_OPT_WWNN: case NVMF_OPT_WWNN:
if (match_u64(args, &token64)) { if (fcloop_verify_addr(args) ||
match_u64(args, &token64)) {
ret = -EINVAL; ret = -EINVAL;
goto out_free_options; goto out_free_options;
} }
*nname = token64; *nname = token64;
break; break;
case NVMF_OPT_WWPN: case NVMF_OPT_WWPN:
if (match_u64(args, &token64)) { if (fcloop_verify_addr(args) ||
match_u64(args, &token64)) {
ret = -EINVAL; ret = -EINVAL;
goto out_free_options; goto out_free_options;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment