Skip to content

Commit 5dd3397

Browse files
Greg Joyceaxboe
authored andcommitted
block: sed-opal: keystore access for SED Opal keys
Allow for permanent SED authentication keys by reading/writing to the SED Opal non-volatile keystore. Signed-off-by: Greg Joyce <gjoyce@linux.vnet.ibm.com> Reviewed-by: Jonathan Derrick <jonathan.derrick@linux.dev> Link: https://lore.kernel.org/r/20231004201957.1451669-3-gjoyce@linux.vnet.ibm.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 96ff37c commit 5dd3397

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

block/sed-opal.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/uaccess.h>
1919
#include <uapi/linux/sed-opal.h>
2020
#include <linux/sed-opal.h>
21+
#include <linux/sed-opal-key.h>
2122
#include <linux/string.h>
2223
#include <linux/kdev_t.h>
2324
#include <linux/key.h>
@@ -3019,7 +3020,13 @@ static int opal_set_new_pw(struct opal_dev *dev, struct opal_new_pw *opal_pw)
30193020
if (ret)
30203021
return ret;
30213022

3022-
/* update keyring with new password */
3023+
/* update keyring and key store with new password */
3024+
ret = sed_write_key(OPAL_AUTH_KEY,
3025+
opal_pw->new_user_pw.opal_key.key,
3026+
opal_pw->new_user_pw.opal_key.key_len);
3027+
if (ret != -EOPNOTSUPP)
3028+
pr_warn("error updating SED key: %d\n", ret);
3029+
30233030
ret = update_sed_opal_key(OPAL_AUTH_KEY,
30243031
opal_pw->new_user_pw.opal_key.key,
30253032
opal_pw->new_user_pw.opal_key.key_len);
@@ -3292,6 +3299,8 @@ EXPORT_SYMBOL_GPL(sed_ioctl);
32923299
static int __init sed_opal_init(void)
32933300
{
32943301
struct key *kr;
3302+
char init_sed_key[OPAL_KEY_MAX];
3303+
int keylen = OPAL_KEY_MAX - 1;
32953304

32963305
kr = keyring_alloc(".sed_opal",
32973306
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(),
@@ -3304,6 +3313,11 @@ static int __init sed_opal_init(void)
33043313

33053314
sed_opal_keyring = kr;
33063315

3307-
return 0;
3316+
if (sed_read_key(OPAL_AUTH_KEY, init_sed_key, &keylen) < 0) {
3317+
memset(init_sed_key, '\0', sizeof(init_sed_key));
3318+
keylen = OPAL_KEY_MAX - 1;
3319+
}
3320+
3321+
return update_sed_opal_key(OPAL_AUTH_KEY, init_sed_key, keylen);
33083322
}
33093323
late_initcall(sed_opal_init);

0 commit comments

Comments
 (0)