Skip to content

Commit 4110ad0

Browse files
elkabloarndb
authored andcommitted
firmware: turris-mox-rwtm: Drop ECDSA signatures via debugfs
Drop the debugfs implementation of the ECDSA message signing, in preparation for a new implementation via the keyctl() syscall. Signed-off-by: Marek Behún <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent df94a2f commit 4110ad0

File tree

3 files changed

+7
-200
lines changed

3 files changed

+7
-200
lines changed

Documentation/ABI/testing/debugfs-turris-mox-rwtm

Lines changed: 0 additions & 14 deletions
This file was deleted.

Documentation/ABI/testing/sysfs-firmware-turris-mox-rwtm

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ Contact: Marek Behún <[email protected]>
1212
Description: (Read) MAC addresses burned into eFuses of this Turris Mox board.
1313
Format: %pM
1414

15-
What: /sys/firmware/turris-mox-rwtm/pubkey
16-
Date: August 2019
17-
KernelVersion: 5.4
18-
Contact: Marek Behún <[email protected]>
19-
Description: (Read) ECDSA public key (in pubkey hex compressed form) computed
20-
as pair to the ECDSA private key burned into eFuses of this
21-
Turris Mox Board.
22-
Format: string
23-
2415
What: /sys/firmware/turris-mox-rwtm/ram_size
2516
Date: August 2019
2617
KernelVersion: 5.4

drivers/firmware/turris-mox-rwtm.c

Lines changed: 7 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
* Copyright (C) 2019, 2024 Marek Behún <[email protected]>
66
*/
77

8-
#include <crypto/sha2.h>
98
#include <linux/align.h>
109
#include <linux/armada-37xx-rwtm-mailbox.h>
1110
#include <linux/completion.h>
1211
#include <linux/container_of.h>
13-
#include <linux/debugfs.h>
1412
#include <linux/device.h>
1513
#include <linux/dma-mapping.h>
1614
#include <linux/err.h>
17-
#include <linux/fs.h>
1815
#include <linux/hw_random.h>
1916
#include <linux/if_ether.h>
2017
#include <linux/kobject.h>
@@ -37,11 +34,6 @@
3734
* https://gitlab.labs.nic.cz/turris/mox-boot-builder/tree/master/wtmi.
3835
*/
3936

40-
#define MOX_ECC_NUMBER_WORDS 17
41-
#define MOX_ECC_NUMBER_LEN (MOX_ECC_NUMBER_WORDS * sizeof(u32))
42-
43-
#define MOX_ECC_SIGNATURE_WORDS (2 * MOX_ECC_NUMBER_WORDS)
44-
4537
#define MBOX_STS_SUCCESS (0 << 30)
4638
#define MBOX_STS_FAIL (1 << 30)
4739
#define MBOX_STS_BADCMD (2 << 30)
@@ -77,10 +69,6 @@ enum mbox_cmd {
7769
* @ram_size: RAM size of the device
7870
* @mac_address1: first MAC address of the device
7971
* @mac_address2: second MAC address of the device
80-
* @has_pubkey: whether board ECDSA public key is present
81-
* @pubkey: board ECDSA public key
82-
* @last_sig: last ECDSA signature generated with board ECDSA private key
83-
* @last_sig_done: whether the last ECDSA signing is complete
8472
*/
8573
struct mox_rwtm {
8674
struct mbox_client mbox_client;
@@ -99,53 +87,37 @@ struct mox_rwtm {
9987
u64 serial_number;
10088
int board_version, ram_size;
10189
u8 mac_address1[ETH_ALEN], mac_address2[ETH_ALEN];
102-
103-
bool has_pubkey;
104-
u8 pubkey[135];
105-
106-
#ifdef CONFIG_DEBUG_FS
107-
/*
108-
* Signature process. This is currently done via debugfs, because it
109-
* does not conform to the sysfs standard "one file per attribute".
110-
* It should be rewritten via crypto API once akcipher API is available
111-
* from userspace.
112-
*/
113-
u32 last_sig[MOX_ECC_SIGNATURE_WORDS];
114-
bool last_sig_done;
115-
#endif
11690
};
11791

11892
static inline struct device *rwtm_dev(struct mox_rwtm *rwtm)
11993
{
12094
return rwtm->mbox_client.dev;
12195
}
12296

123-
#define MOX_ATTR_RO(name, format, cat) \
97+
#define MOX_ATTR_RO(name, format) \
12498
static ssize_t \
12599
name##_show(struct device *dev, struct device_attribute *a, \
126100
char *buf) \
127101
{ \
128102
struct mox_rwtm *rwtm = dev_get_drvdata(dev); \
129-
if (!rwtm->has_##cat) \
103+
if (!rwtm->has_board_info) \
130104
return -ENODATA; \
131105
return sysfs_emit(buf, format, rwtm->name); \
132106
} \
133107
static DEVICE_ATTR_RO(name)
134108

135-
MOX_ATTR_RO(serial_number, "%016llX\n", board_info);
136-
MOX_ATTR_RO(board_version, "%i\n", board_info);
137-
MOX_ATTR_RO(ram_size, "%i\n", board_info);
138-
MOX_ATTR_RO(mac_address1, "%pM\n", board_info);
139-
MOX_ATTR_RO(mac_address2, "%pM\n", board_info);
140-
MOX_ATTR_RO(pubkey, "%s\n", pubkey);
109+
MOX_ATTR_RO(serial_number, "%016llX\n");
110+
MOX_ATTR_RO(board_version, "%i\n");
111+
MOX_ATTR_RO(ram_size, "%i\n");
112+
MOX_ATTR_RO(mac_address1, "%pM\n");
113+
MOX_ATTR_RO(mac_address2, "%pM\n");
141114

142115
static struct attribute *turris_mox_rwtm_attrs[] = {
143116
&dev_attr_serial_number.attr,
144117
&dev_attr_board_version.attr,
145118
&dev_attr_ram_size.attr,
146119
&dev_attr_mac_address1.attr,
147120
&dev_attr_mac_address2.attr,
148-
&dev_attr_pubkey.attr,
149121
NULL
150122
};
151123
ATTRIBUTE_GROUPS(turris_mox_rwtm);
@@ -247,24 +219,6 @@ static int mox_get_board_info(struct mox_rwtm *rwtm)
247219
pr_info(" burned RAM size %i MiB\n", rwtm->ram_size);
248220
}
249221

250-
ret = mox_rwtm_exec(rwtm, MBOX_CMD_ECDSA_PUB_KEY, NULL, false);
251-
if (ret == -ENODATA) {
252-
dev_warn(dev, "Board has no public key burned!\n");
253-
} else if (ret == -EOPNOTSUPP) {
254-
dev_notice(dev,
255-
"Firmware does not support the ECDSA_PUB_KEY command\n");
256-
} else if (ret < 0) {
257-
return ret;
258-
} else {
259-
u32 *s = reply->status;
260-
261-
rwtm->has_pubkey = true;
262-
sprintf(rwtm->pubkey,
263-
"%06x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x",
264-
ret, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7],
265-
s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15]);
266-
}
267-
268222
return 0;
269223
}
270224

@@ -306,128 +260,6 @@ static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
306260
return ret;
307261
}
308262

309-
#ifdef CONFIG_DEBUG_FS
310-
static int rwtm_debug_open(struct inode *inode, struct file *file)
311-
{
312-
file->private_data = inode->i_private;
313-
314-
return nonseekable_open(inode, file);
315-
}
316-
317-
static ssize_t do_sign_read(struct file *file, char __user *buf, size_t len,
318-
loff_t *ppos)
319-
{
320-
struct mox_rwtm *rwtm = file->private_data;
321-
ssize_t ret;
322-
323-
/* only allow one read, of whole signature, from position 0 */
324-
if (*ppos != 0)
325-
return 0;
326-
327-
if (len < sizeof(rwtm->last_sig))
328-
return -EINVAL;
329-
330-
if (!rwtm->last_sig_done)
331-
return -ENODATA;
332-
333-
ret = simple_read_from_buffer(buf, len, ppos, rwtm->last_sig,
334-
sizeof(rwtm->last_sig));
335-
rwtm->last_sig_done = false;
336-
337-
return ret;
338-
}
339-
340-
static ssize_t do_sign_write(struct file *file, const char __user *buf,
341-
size_t len, loff_t *ppos)
342-
{
343-
struct mox_rwtm *rwtm = file->private_data;
344-
struct armada_37xx_rwtm_tx_msg msg;
345-
loff_t dummy = 0;
346-
ssize_t ret;
347-
348-
if (len != SHA512_DIGEST_SIZE)
349-
return -EINVAL;
350-
351-
/* if last result is not zero user has not read that information yet */
352-
if (rwtm->last_sig_done)
353-
return -EBUSY;
354-
355-
if (!mutex_trylock(&rwtm->busy))
356-
return -EBUSY;
357-
358-
/*
359-
* Here we have to send:
360-
* 1. Address of the input to sign.
361-
* The input is an array of 17 32-bit words, the first (most
362-
* significat) is 0, the rest 16 words are copied from the SHA-512
363-
* hash given by the user and converted from BE to LE.
364-
* 2. Address of the buffer where ECDSA signature value R shall be
365-
* stored by the rWTM firmware.
366-
* 3. Address of the buffer where ECDSA signature value S shall be
367-
* stored by the rWTM firmware.
368-
*/
369-
memset(rwtm->buf, 0, sizeof(u32));
370-
ret = simple_write_to_buffer(rwtm->buf + sizeof(u32),
371-
SHA512_DIGEST_SIZE, &dummy, buf, len);
372-
if (ret < 0)
373-
goto unlock_mutex;
374-
be32_to_cpu_array(rwtm->buf, rwtm->buf, MOX_ECC_NUMBER_WORDS);
375-
376-
msg.args[0] = 1;
377-
msg.args[1] = rwtm->buf_phys;
378-
msg.args[2] = rwtm->buf_phys + MOX_ECC_NUMBER_LEN;
379-
msg.args[3] = rwtm->buf_phys + 2 * MOX_ECC_NUMBER_LEN;
380-
381-
ret = mox_rwtm_exec(rwtm, MBOX_CMD_SIGN, &msg, true);
382-
if (ret < 0)
383-
goto unlock_mutex;
384-
385-
/*
386-
* Here we read the R and S values of the ECDSA signature
387-
* computed by the rWTM firmware and convert their words from
388-
* LE to BE.
389-
*/
390-
memcpy(rwtm->last_sig, rwtm->buf + MOX_ECC_NUMBER_LEN,
391-
sizeof(rwtm->last_sig));
392-
cpu_to_be32_array(rwtm->last_sig, rwtm->last_sig,
393-
MOX_ECC_SIGNATURE_WORDS);
394-
rwtm->last_sig_done = true;
395-
396-
mutex_unlock(&rwtm->busy);
397-
return len;
398-
unlock_mutex:
399-
mutex_unlock(&rwtm->busy);
400-
return ret;
401-
}
402-
403-
static const struct file_operations do_sign_fops = {
404-
.owner = THIS_MODULE,
405-
.open = rwtm_debug_open,
406-
.read = do_sign_read,
407-
.write = do_sign_write,
408-
};
409-
410-
static void rwtm_debugfs_release(void *root)
411-
{
412-
debugfs_remove_recursive(root);
413-
}
414-
415-
static void rwtm_register_debugfs(struct mox_rwtm *rwtm)
416-
{
417-
struct dentry *root;
418-
419-
root = debugfs_create_dir("turris-mox-rwtm", NULL);
420-
421-
debugfs_create_file_unsafe("do_sign", 0600, root, rwtm, &do_sign_fops);
422-
423-
devm_add_action_or_reset(rwtm_dev(rwtm), rwtm_debugfs_release, root);
424-
}
425-
#else
426-
static inline void rwtm_register_debugfs(struct mox_rwtm *rwtm)
427-
{
428-
}
429-
#endif
430-
431263
static void rwtm_devm_mbox_release(void *mbox)
432264
{
433265
mbox_free_channel(mbox);
@@ -491,8 +323,6 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev)
491323
if (ret)
492324
return dev_err_probe(dev, ret, "Cannot register HWRNG!\n");
493325

494-
rwtm_register_debugfs(rwtm);
495-
496326
dev_info(dev, "HWRNG successfully registered\n");
497327

498328
/*

0 commit comments

Comments
 (0)