Skip to contentSkip to conversation

applesmc: Expose Operating System Key in

PATCH In review Alexander Graf 2 participants 4 messages Oct 6, 2008 – Feb 23, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 applesmc: Expose Operating System Key in

The AppleSMC is used for various tasks. It allows control over fans, the backlight, invokes the acceleration interrupt and stores a key, that is used to decrypt binaries on Mac OS X.

This key is necessary to receive when virtualizing Mac OS X, but may not be distributed due to copyright restrictions.

This patch makes reading this key easy by exporting it via sysfs.

Cc Nicolas Boichat <[email protected]>
Cc Jean Delvare <[email protected]>
Cc René Rebe <[email protected]>
---
 drivers/hwmon/applesmc.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
drivers/hwmon/applesmc.c +34 -0
index b06b8e0..655e217 100644
@@ -61,6 +61,9 @@
 #define LIGHT_SENSOR_RIGHT_KEY	"ALV1" /* r-o {alv (6 bytes) */
 #define BACKLIGHT_KEY		"LKSB" /* w-o {lkb (2 bytes) */
 
+#define OSK0_KEY		"OSK0" /* r-o ascii (32 bytes) */
+#define OSK1_KEY		"OSK1" /* r-o ascii (32 bytes) */
+
 #define CLAMSHELL_KEY		"MSLD" /* r-o ui8 (unused) */
 
 #define MOTION_SENSOR_X_KEY	"MO_X" /* r-o sp78 (2 bytes) */
@@ -548,6 +551,31 @@ out:
 		return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right);
 }
 
+static ssize_t applesmc_osk_show(struct device *dev,
+				struct device_attribute *attr, char *sysfsbuf)
+{
+	int ret;
+	u8 osk0[33];
+	u8 osk1[33];
+
+	osk0[32] = '\0';
+	osk1[32] = '\0';
+
+	mutex_lock(&applesmc_lock);
+
+	ret = applesmc_read_key(OSK0_KEY, osk0, 32);
+	if (ret)
+		goto out;
+	ret = applesmc_read_key(OSK1_KEY, osk1, 32);
+
+out:
+	mutex_unlock(&applesmc_lock);
+	if (ret)
+		return ret;
+	else
+		return snprintf(sysfsbuf, PAGE_SIZE, "%s%s\n", osk0, osk1);
+}
+
 /* Displays degree Celsius * 1000 */
 static ssize_t applesmc_show_temperature(struct device *dev,
 			struct device_attribute *devattr, char *sysfsbuf)
@@ -935,6 +963,7 @@ static const struct attribute_group accelerometer_attributes_group  	{ .attrs = accelerometer_attributes };
 
 static DEVICE_ATTR(light, 0444, applesmc_light_show, NULL);
+static DEVICE_ATTR(osk, 0444, applesmc_osk_show, NULL);
 
 static DEVICE_ATTR(key_count, 0444, applesmc_key_count_show, NULL);
 static DEVICE_ATTR(key_at_index, 0644,
@@ -1386,6 +1415,10 @@ static int __init applesmc_init(void)
 			goto out_light_wq;
 	}
 
+	ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_osk.attr);
+	if (ret)
+		goto out_osk;
+
 	hwmon_dev = hwmon_device_register(&pdev->dev);
 	if (IS_ERR(hwmon_dev)) {
 		ret = PTR_ERR(hwmon_dev);
@@ -1397,6 +1430,7 @@ static int __init applesmc_init(void)
 	return 0;
 
 out_light_ledclass:
+out_osk:
 	if (applesmc_light)
 		led_classdev_unregister(&applesmc_backlight);
 out_light_wq:
Signature · 7 lines
1.5.6


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw

Hallo Alexander,

I don't know a thing about the applesmc driver, so just a few random comments. Nicolas being the maintainer of this driver, his approval is needed before your patch can go upstream anyway.

Quoted 64 lines · Alexander Graf

The AppleSMC is used for various tasks. It allows control over fans, the backlight, invokes the acceleration interrupt and stores a key, that is used to decrypt binaries on Mac OS X.

This key is necessary to receive when virtualizing Mac OS X, but may not be distributed due to copyright restrictions.

This patch makes reading this key easy by exporting it via sysfs.

Cc Nicolas Boichat <[email protected]>
Cc Jean Delvare <[email protected]>
Cc René Rebe <[email protected]>
---
 drivers/hwmon/applesmc.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
drivers/hwmon/applesmc.c +28 -0
index b06b8e0..655e217 100644
@@ -61,6 +61,9 @@
 #define LIGHT_SENSOR_RIGHT_KEY	"ALV1" /* r-o {alv (6 bytes) */
 #define BACKLIGHT_KEY		"LKSB" /* w-o {lkb (2 bytes) */
 
+#define OSK0_KEY		"OSK0" /* r-o ascii (32 bytes) */
+#define OSK1_KEY		"OSK1" /* r-o ascii (32 bytes) */
+
 #define CLAMSHELL_KEY		"MSLD" /* r-o ui8 (unused) */
 
 #define MOTION_SENSOR_X_KEY	"MO_X" /* r-o sp78 (2 bytes) */
@@ -548,6 +551,31 @@ out:
 		return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right);
 }
 
+static ssize_t applesmc_osk_show(struct device *dev,
+				struct device_attribute *attr, char *sysfsbuf)
+{
+	int ret;
+	u8 osk0[33];
+	u8 osk1[33];
+
+	osk0[32] = '\0';
+	osk1[32] = '\0';
+
+	mutex_lock(&applesmc_lock);
+
+	ret = applesmc_read_key(OSK0_KEY, osk0, 32);
+	if (ret)
+		goto out;
+	ret = applesmc_read_key(OSK1_KEY, osk1, 32);
+
+out:
+	mutex_unlock(&applesmc_lock);
+	if (ret)
+		return ret;
+	else
+		return snprintf(sysfsbuf, PAGE_SIZE, "%s%s\n", osk0, osk1);
+}
+
 /* Displays degree Celsius * 1000 */
 static ssize_t applesmc_show_temperature(struct device *dev,
 			struct device_attribute *devattr, char *sysfsbuf)

drivers/hwmon/applesmc.c static const struct attribute_group accelerometer_attributes_group > { .attrs = accelerometer_attributes }; · line 965

Quoted 3 lines
drivers/hwmon/applesmc.c +1 -0
@@ -935,6 +963,7 @@ static const struct attribute_group accelerometer_attributes_group >  	{ .attrs = accelerometer_attributes };
 
 static DEVICE_ATTR(light, 0444, applesmc_light_show, NULL);
+static DEVICE_ATTR(osk, 0444, applesmc_osk_show, NULL);

If this key "may not be distributed due to copyright restrictions" then is is OK to expose it to all users? Shouldn't the mode be 0440 or even 0400?

drivers/hwmon/applesmc.c static int __init applesmc_init(void) · line 1421

Quoted 11 lines
drivers/hwmon/applesmc.c +4 -0
 static DEVICE_ATTR(key_count, 0444, applesmc_key_count_show, NULL);
 static DEVICE_ATTR(key_at_index, 0644,
@@ -1386,6 +1415,10 @@ static int __init applesmc_init(void)
 			goto out_light_wq;
 	}
 
+	ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_osk.attr);
+	if (ret)
+		goto out_osk;
+

The applesmc driver cleanly removes all the sysfs files it created in case of error and at removal time. So you must do the same for this new file you're introducing.

Quoted 11 lines
drivers/hwmon/applesmc.c +1 -0
 	hwmon_dev = hwmon_device_register(&pdev->dev);
 	if (IS_ERR(hwmon_dev)) {
 		ret = PTR_ERR(hwmon_dev);
@@ -1397,6 +1430,7 @@ static int __init applesmc_init(void)
 	return 0;
 
 out_light_ledclass:
+out_osk:
 	if (applesmc_light)
 		led_classdev_unregister(&applesmc_backlight);
 out_light_wq:
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Alexander Graf
Quoted 21 lines · Jean Delvare

Hallo Alexander,

I don't know a thing about the applesmc driver, so just a few random comments. Nicolas being the maintainer of this driver, his approval is needed before your patch can go upstream anyway.

Quoted 14 lines · Alexander Graf

The AppleSMC is used for various tasks. It allows control over fans, the backlight, invokes the acceleration interrupt and stores a key, that is used to decrypt binaries on Mac OS X.

This key is necessary to receive when virtualizing Mac OS X, but may not be distributed due to copyright restrictions.

This patch makes reading this key easy by exporting it via sysfs.

Cc Nicolas Boichat <[email protected]>
Cc Jean Delvare <[email protected]>
Cc René Rebe <[email protected]>

(...)

Alexander, any news from this patch? I never heard you back from you since my review. If you are no longer interested in this patch, I'll just discard it. If you are still interested, please send an updated patch addressing my comments.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#3 lore raw
In reply to Alexander Graf
Quoted 24 lines · Jean Delvare
Quoted 22 lines · Jean Delvare

Hallo Alexander,

I don't know a thing about the applesmc driver, so just a few random comments. Nicolas being the maintainer of this driver, his approval is
needed before your patch can go upstream anyway.

Quoted 14 lines · Alexander Graf

The AppleSMC is used for various tasks. It allows control over fans, the backlight, invokes the acceleration interrupt and stores a key, that is used to decrypt binaries on Mac OS X.

This key is necessary to receive when virtualizing Mac OS X, but may not be distributed due to copyright restrictions.

This patch makes reading this key easy by exporting it via sysfs.

Cc Nicolas Boichat <[email protected]>
Cc Jean Delvare <[email protected]>
Cc René Rebe <[email protected]>

(...)

Quoted 4 lines

Alexander, any news from this patch? I never heard you back from you since my review. If you are no longer interested in this patch, I'll just discard it. If you are still interested, please send an updated patch addressing my comments.

Oh phew I almost forgot about it. I'll take your comments into account and send a new one this week :-).

Alex

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors