Skip to content

Commit e545f0d

Browse files
ybernatgregkh
authored andcommitted
thunderbolt: Allow clearing the key
If secure authentication of a devices fails, either because the device already has another key uploaded, or there is some other error sending challenge to the device, and the user only wants to approve the device just once (without a new key being uploaded to the device) the current implementation does not allow this because the key cannot be cleared once set even if we allow it to be changed. Make this scenario possible and allow clearing the key by writing empty string to the key sysfs file. Signed-off-by: Yehezkel Bernat <[email protected]> Acked-by: Mika Westerberg <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0956e41 commit e545f0d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Documentation/ABI/testing/sysfs-bus-thunderbolt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Contact: [email protected]
4545
Description: When a devices supports Thunderbolt secure connect it will
4646
have this attribute. Writing 32 byte hex string changes
4747
authorization to use the secure connection method instead.
48+
Writing an empty string clears the key and regular connection
49+
method can be used again.
4850

4951
What: /sys/bus/thunderbolt/devices/.../device
5052
Date: Sep 2017

drivers/thunderbolt/switch.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,11 @@ static ssize_t key_store(struct device *dev, struct device_attribute *attr,
807807
struct tb_switch *sw = tb_to_switch(dev);
808808
u8 key[TB_SWITCH_KEY_SIZE];
809809
ssize_t ret = count;
810+
bool clear = false;
810811

811-
if (hex2bin(key, buf, sizeof(key)))
812+
if (!strcmp(buf, "\n"))
813+
clear = true;
814+
else if (hex2bin(key, buf, sizeof(key)))
812815
return -EINVAL;
813816

814817
if (mutex_lock_interruptible(&switch_lock))
@@ -818,9 +821,13 @@ static ssize_t key_store(struct device *dev, struct device_attribute *attr,
818821
ret = -EBUSY;
819822
} else {
820823
kfree(sw->key);
821-
sw->key = kmemdup(key, sizeof(key), GFP_KERNEL);
822-
if (!sw->key)
823-
ret = -ENOMEM;
824+
if (clear) {
825+
sw->key = NULL;
826+
} else {
827+
sw->key = kmemdup(key, sizeof(key), GFP_KERNEL);
828+
if (!sw->key)
829+
ret = -ENOMEM;
830+
}
824831
}
825832

826833
mutex_unlock(&switch_lock);

0 commit comments

Comments
 (0)