-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nvme-keyring: register '.nvme' keyring
Register a '.nvme' keyring to hold keys for TLS and DH-HMAC-CHAP and add a new config option NVME_KEYRING. We need a separate keyring for NVMe as the configuration is done via individual commands (eg for configfs), and the usual per-session or per-process keyrings can't be used. Signed-off-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Keith Busch <kbusch@kernel.org>
- Loading branch information
Hannes Reinecke
authored and
Keith Busch
committed
Oct 11, 2023
1 parent
ccd3129
commit 9d77eb5
Showing
5 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,7 @@ | |
|
||
config NVME_COMMON | ||
tristate | ||
|
||
config NVME_KEYRING | ||
bool | ||
select KEYS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright (c) 2023 Hannes Reinecke, SUSE Labs | ||
*/ | ||
|
||
#include <linux/module.h> | ||
#include <linux/seq_file.h> | ||
#include <linux/key-type.h> | ||
#include <keys/user-type.h> | ||
#include <linux/nvme.h> | ||
|
||
static struct key *nvme_keyring; | ||
|
||
key_serial_t nvme_keyring_id(void) | ||
{ | ||
return nvme_keyring->serial; | ||
} | ||
EXPORT_SYMBOL_GPL(nvme_keyring_id); | ||
|
||
int nvme_keyring_init(void) | ||
{ | ||
nvme_keyring = keyring_alloc(".nvme", | ||
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, | ||
current_cred(), | ||
(KEY_POS_ALL & ~KEY_POS_SETATTR) | | ||
(KEY_USR_ALL & ~KEY_USR_SETATTR), | ||
KEY_ALLOC_NOT_IN_QUOTA, NULL, NULL); | ||
if (IS_ERR(nvme_keyring)) | ||
return PTR_ERR(nvme_keyring); | ||
|
||
return 0; | ||
} | ||
EXPORT_SYMBOL_GPL(nvme_keyring_init); | ||
|
||
void nvme_keyring_exit(void) | ||
{ | ||
key_revoke(nvme_keyring); | ||
key_put(nvme_keyring); | ||
} | ||
EXPORT_SYMBOL_GPL(nvme_keyring_exit); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Copyright (c) 2023 Hannes Reinecke, SUSE Labs | ||
*/ | ||
|
||
#ifndef _NVME_KEYRING_H | ||
#define _NVME_KEYRING_H | ||
|
||
#ifdef CONFIG_NVME_KEYRING | ||
|
||
key_serial_t nvme_keyring_id(void); | ||
int nvme_keyring_init(void); | ||
void nvme_keyring_exit(void); | ||
|
||
#else | ||
|
||
static inline key_serial_t nvme_keyring_id(void) | ||
{ | ||
return 0; | ||
} | ||
static inline int nvme_keyring_init(void) | ||
{ | ||
return 0; | ||
} | ||
static inline void nvme_keyring_exit(void) {} | ||
|
||
#endif /* !CONFIG_NVME_KEYRING */ | ||
#endif /* _NVME_KEYRING_H */ |