nvme: split host and target nvme_auth_extract_key
Subsystems (3)
PATCH 1/1 nvme: split host and target nvme_auth_extract_key
From: Keith Busch <[email protected]>
The host and target share common code, but the config allows you to disable support for one and not the other. When support is disabled, a stub implementation needs to be used, but that would clash with the real implementation that the other relies on.
Split the host and target implementations into uniquely named stub functions that either call the real implementation or return an error if their config option is disabled.
--- drivers/nvme/host/fabrics.c | 4 ++-- drivers/nvme/host/nvme.h | 12 +++++++++--- drivers/nvme/host/sysfs.c | 4 ++-- drivers/nvme/target/auth.c | 2 +- drivers/nvme/target/nvmet.h | 12 +++++++++--- 5 files changed, 23 insertions(+), 11 deletions(-)
drivers/nvme/host/fabrics.c +2 -2
@@ -1107,7 +1107,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,if (host_secret) {pr_debug ("lookup host identity '%s'\n" , host_secret); - key =nvme_auth_extract_key (opts->keyring, host_secret, + key =nvme_auth_extract_key_host (opts->keyring, host_secret,strlen (host_secret), &opts->dhchap_key_generated);if (IS_ERR (key)) {
@@ -1123,7 +1123,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, goto out; }pr_debug ("lookup ctrl identity '%s'\n" , ctrl_secret); - key =nvme_auth_extract_key (opts->keyring, ctrl_secret, + key =nvme_auth_extract_key_host (opts->keyring, ctrl_secret,strlen (ctrl_secret), &opts->dhchap_ctrl_key_generated);if (IS_ERR (key)) {
drivers/nvme/host/nvme.h +9 -3
@@ -7,6 +7,7 @@#define _NVME_H#include <linux/nvme.h> +#include <linux/nvme-auth.h> #include <linux/cdev.h> #include <linux/pci.h> #include <linux/kref.h>
@@ -1179,8 +1180,13 @@ int nvme_auth_negotiate(struct nvme_ctrl *ctrl, int qid);int nvme_auth_wait (struct nvme_ctrl *ctrl,int qid);void nvme_auth_free (struct nvme_ctrl *ctrl);void nvme_auth_revoke_tls_key (struct nvme_ctrl *ctrl); -struct key *nvme_auth_extract_key (struct key *keyring,const u8 *secret, -size_t secret_len,bool *generated); +static inline struct key *nvme_auth_extract_key_host (struct key *keyring, +const u8 *secret, +size_t secret_len, +bool *generated) +{ +return nvme_auth_extract_key (keyring, secret, secret_len, generated); +}#else static inline int nvme_auth_init_ctrl (struct nvme_ctrl *ctrl) {
@@ -1204,7 +1210,7 @@ static inline int nvme_auth_wait(struct nvme_ctrl *ctrl, int qid) }static inline void nvme_auth_free (struct nvme_ctrl *ctrl) {};static inline void nvme_auth_revoke_tls_key (struct nvme_ctrl *ctrl) {}; -static inline struct key *nvme_auth_extract_key (struct key *keyring, +static inline struct key *nvme_auth_extract_key_host (struct key *keyring,const u8 *secret,size_t secret_len,bool *generated)
drivers/nvme/host/sysfs.c +2 -2
@@ -648,7 +648,7 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,return -ENOMEM ;memcpy (dhchap_secret, buf, len);nvme_auth_stop (ctrl); - key =nvme_auth_extract_key (opts->keyring, dhchap_secret, len, + key =nvme_auth_extract_key_host (opts->keyring, dhchap_secret, len, &generated);if (IS_ERR (key)) {kfree (dhchap_secret);
@@ -735,7 +735,7 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,return -ENOMEM ;memcpy (dhchap_secret, buf, len);nvme_auth_stop (ctrl); - key =nvme_auth_extract_key (opts->keyring, dhchap_secret, len, + key =nvme_auth_extract_key_host (opts->keyring, dhchap_secret, len, &generated);if (IS_ERR (key)) {kfree (dhchap_secret);
drivers/nvme/target/auth.c +1 -1
@@ -69,7 +69,7 @@ int nvmet_auth_set_key(struct nvmet_host *host, const char *secret, } len =strcspn (secret,"\n" ); - key =nvme_auth_extract_key (host->dhchap_keyring, secret, len, &generated); + key =nvme_auth_extract_key_target (host->dhchap_keyring, secret, len, &generated);if (IS_ERR (key)) {pr_debug ("%s: invalid key specification\n" , __func__);return PTR_ERR (key);
drivers/nvme/target/nvmet.h +9 -3
@@ -15,6 +15,7 @@#include <linux/mutex.h> #include <linux/uuid.h> #include <linux/nvme.h> +#include <linux/nvme-auth.h> #include <linux/configfs.h> #include <linux/rcupdate.h> #include <linux/blkdev.h>
@@ -895,8 +896,13 @@ void nvmet_execute_auth_receive(struct nvmet_req *req);void nvmet_auth_revoke_key (struct nvmet_host *host,bool set_ctrl);int nvmet_auth_set_key (struct nvmet_host *host,const char *secret,bool set_ctrl); -struct key *nvme_auth_extract_key (struct key *keyring,const u8 *secret, -size_t secret_len,bool *generated); +static inline struct key *nvme_auth_extract_key_target (struct key *keyring, +const u8 *secret, +size_t secret_len, +bool *generated) +{ +return nvme_auth_extract_key (keyring, secret, secret_len, generated); +}int nvmet_auth_set_host_hash (struct nvmet_host *host,const char *hash);u8 nvmet_setup_auth (struct nvmet_ctrl *ctrl,struct nvmet_sq *sq);void nvmet_auth_sq_init (struct nvmet_sq *sq);
@@ -939,7 +945,7 @@ static inline bool nvmet_has_auth(struct nvmet_ctrl *ctrl, }static inline const char *nvmet_dhchap_dhgroup_name (u8 dhgid) {return NULL ; }static inline void nvmet_auth_insert_psk (struct nvmet_sq *sq) {}; -static inline struct key *nvme_auth_extract_key (struct key *keyring, +static inline struct key *nvme_auth_extract_key_target (struct key *keyring,const u8 *secret,size_t secret_len,bool *generated)
Signature · 1 line
2.47.3
Christoph Hellwig
maintainerQuoted 7 lines · Keith Busch
From: Keith Busch <[email protected]>
The host and target share common code, but the config allows you to disable support for one and not the other. When support is disabled, a stub implementation needs to be used, but that would clash with the real implementation that the other relies on.
Quoted 8 lines
Split the host and target implementations into uniquely named stub functions that either call the real implementation or return an error if their config option is disabled.
Fixes f59ae5c9e356b5e ("nvme: parse dhchap keys during option parsing")Reported-by kernel test robot <[email protected]>Signed-off-by Keith Busch <[email protected]>
This seems a bit backwards. How about dropping the stub entirely and guard the calls with IS_ENABLED or if needed ifdefs instead?
drivers/nvme/target/auth.c int nvmet_auth_set_key(struct nvmet_host *host, const char *secret, · line 72
Quoted 2 lines
drivers/nvme/target/auth.c +1
-1- key =nvme_auth_extract_key (host->dhchap_keyring, secret, len, &generated); + key =nvme_auth_extract_key_target (host->dhchap_keyring, secret, len, &generated);
And maybe fix the (pre-existing) overly long line here if you end up touching this.
Hannes Reinecke
maintainerQuoted 12 lines · Christoph Hellwig
Quoted 11 lines · Keith Busch
From: Keith Busch <[email protected]>
The host and target share common code, but the config allows you to disable support for one and not the other. When support is disabled, a stub implementation needs to be used, but that would clash with the real implementation that the other relies on.
Split the host and target implementations into uniquely named stub functions that either call the real implementation or return an error if their config option is disabled.
Quoted 8 lines
Quoted 4 lines
Fixes f59ae5c9e356b5e ("nvme: parse dhchap keys during option parsing")Reported-by kernel test robot <[email protected]>Signed-off-by Keith Busch <[email protected]>This seems a bit backwards. How about dropping the stub entirely and guard the calls with
IS_ENABLEDor if needed ifdefs instead?
Tried this once, but then ran into the same issue with one side being
modular and the other side being compiled in.
Can't we just fiddle with config magic to require CONFIG_NVME_TARGET_AUTH and CONFIG_NVME_HOST_AUTH to either be disabled or having the same type
(eg _either_ Y or M). Hmm?
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich