diff options
author | Duson Lin <dusonlin@emc.com.tw> | 2015-01-23 12:35:07 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-01-23 12:44:21 -0500 |
commit | bb03bf3f8427a38112819061fc8688999ba02f67 (patch) | |
tree | 13762fe3d8dd1cd8db48c26c3126ef32c50cceb6 /drivers/input | |
parent | e719963c4a71a5aa687998e83ccdb905bfc7f13f (diff) |
Input: elan_i2c - verify firmware signature applying it
To allow for different firmware sizes let's replace the original size check
with with checking the signature in the firmware data.
Signed-off-by: Duson Lin <dusonlin@emc.com.tw>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/mouse/elan_i2c.h | 6 | ||||
-rw-r--r-- | drivers/input/mouse/elan_i2c_core.c | 21 | ||||
-rw-r--r-- | drivers/input/mouse/elan_i2c_i2c.c | 1 | ||||
-rw-r--r-- | drivers/input/mouse/elan_i2c_smbus.c | 1 |
4 files changed, 15 insertions, 14 deletions
diff --git a/drivers/input/mouse/elan_i2c.h b/drivers/input/mouse/elan_i2c.h index 2e838626205f..e100c1b31597 100644 --- a/drivers/input/mouse/elan_i2c.h +++ b/drivers/input/mouse/elan_i2c.h | |||
@@ -4,7 +4,6 @@ | |||
4 | * Copyright (c) 2013 ELAN Microelectronics Corp. | 4 | * Copyright (c) 2013 ELAN Microelectronics Corp. |
5 | * | 5 | * |
6 | * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw> | 6 | * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw> |
7 | * Version: 1.5.5 | ||
8 | * | 7 | * |
9 | * Based on cyapa driver: | 8 | * Based on cyapa driver: |
10 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. | 9 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. |
@@ -33,8 +32,9 @@ | |||
33 | #define ETP_FW_IAP_PAGE_ERR (1 << 5) | 32 | #define ETP_FW_IAP_PAGE_ERR (1 << 5) |
34 | #define ETP_FW_IAP_INTF_ERR (1 << 4) | 33 | #define ETP_FW_IAP_INTF_ERR (1 << 4) |
35 | #define ETP_FW_PAGE_SIZE 64 | 34 | #define ETP_FW_PAGE_SIZE 64 |
36 | #define ETP_FW_PAGE_COUNT 768 | 35 | #define ETP_FW_VAILDPAGE_COUNT 768 |
37 | #define ETP_FW_SIZE (ETP_FW_PAGE_SIZE * ETP_FW_PAGE_COUNT) | 36 | #define ETP_FW_SIGNATURE_SIZE 6 |
37 | #define ETP_FW_SIGNATURE_ADDRESS 0xBFFA | ||
38 | 38 | ||
39 | struct i2c_client; | 39 | struct i2c_client; |
40 | struct completion; | 40 | struct completion; |
diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c index 0cb2be48d537..7ce8bfe22d7e 100644 --- a/drivers/input/mouse/elan_i2c_core.c +++ b/drivers/input/mouse/elan_i2c_core.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * Copyright (c) 2013 ELAN Microelectronics Corp. | 4 | * Copyright (c) 2013 ELAN Microelectronics Corp. |
5 | * | 5 | * |
6 | * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw> | 6 | * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw> |
7 | * Version: 1.5.5 | 7 | * Version: 1.5.6 |
8 | * | 8 | * |
9 | * Based on cyapa driver: | 9 | * Based on cyapa driver: |
10 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. | 10 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. |
@@ -40,7 +40,7 @@ | |||
40 | #include "elan_i2c.h" | 40 | #include "elan_i2c.h" |
41 | 41 | ||
42 | #define DRIVER_NAME "elan_i2c" | 42 | #define DRIVER_NAME "elan_i2c" |
43 | #define ELAN_DRIVER_VERSION "1.5.5" | 43 | #define ELAN_DRIVER_VERSION "1.5.6" |
44 | #define ETP_PRESSURE_OFFSET 25 | 44 | #define ETP_PRESSURE_OFFSET 25 |
45 | #define ETP_MAX_PRESSURE 255 | 45 | #define ETP_MAX_PRESSURE 255 |
46 | #define ETP_FWIDTH_REDUCE 90 | 46 | #define ETP_FWIDTH_REDUCE 90 |
@@ -312,7 +312,7 @@ static int __elan_update_firmware(struct elan_tp_data *data, | |||
312 | iap_start_addr = get_unaligned_le16(&fw->data[ETP_IAP_START_ADDR * 2]); | 312 | iap_start_addr = get_unaligned_le16(&fw->data[ETP_IAP_START_ADDR * 2]); |
313 | 313 | ||
314 | boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE; | 314 | boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE; |
315 | for (i = boot_page_count; i < ETP_FW_PAGE_COUNT; i++) { | 315 | for (i = boot_page_count; i < ETP_FW_VAILDPAGE_COUNT; i++) { |
316 | u16 checksum = 0; | 316 | u16 checksum = 0; |
317 | const u8 *page = &fw->data[i * ETP_FW_PAGE_SIZE]; | 317 | const u8 *page = &fw->data[i * ETP_FW_PAGE_SIZE]; |
318 | 318 | ||
@@ -434,10 +434,11 @@ static ssize_t elan_sysfs_update_fw(struct device *dev, | |||
434 | struct device_attribute *attr, | 434 | struct device_attribute *attr, |
435 | const char *buf, size_t count) | 435 | const char *buf, size_t count) |
436 | { | 436 | { |
437 | struct i2c_client *client = to_i2c_client(dev); | 437 | struct elan_tp_data *data = dev_get_drvdata(dev); |
438 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
439 | const struct firmware *fw; | 438 | const struct firmware *fw; |
440 | int error; | 439 | int error; |
440 | const u8 *fw_signature; | ||
441 | static const u8 signature[] = {0xAA, 0x55, 0xCC, 0x33, 0xFF, 0xFF}; | ||
441 | 442 | ||
442 | error = request_firmware(&fw, ETP_FW_NAME, dev); | 443 | error = request_firmware(&fw, ETP_FW_NAME, dev); |
443 | if (error) { | 444 | if (error) { |
@@ -446,10 +447,12 @@ static ssize_t elan_sysfs_update_fw(struct device *dev, | |||
446 | return error; | 447 | return error; |
447 | } | 448 | } |
448 | 449 | ||
449 | /* Firmware must be exactly PAGE_NUM * PAGE_SIZE bytes */ | 450 | /* Firmware file must match signature data */ |
450 | if (fw->size != ETP_FW_SIZE) { | 451 | fw_signature = &fw->data[ETP_FW_SIGNATURE_ADDRESS]; |
451 | dev_err(dev, "invalid firmware size = %zu, expected %d.\n", | 452 | if (memcmp(fw_signature, signature, sizeof(signature)) != 0) { |
452 | fw->size, ETP_FW_SIZE); | 453 | dev_err(dev, "signature mismatch (expected %*ph, got %*ph)\n", |
454 | (int)sizeof(signature), signature, | ||
455 | (int)sizeof(signature), fw_signature); | ||
453 | error = -EBADF; | 456 | error = -EBADF; |
454 | goto out_release_fw; | 457 | goto out_release_fw; |
455 | } | 458 | } |
diff --git a/drivers/input/mouse/elan_i2c_i2c.c b/drivers/input/mouse/elan_i2c_i2c.c index 97d4937fc244..029941f861af 100644 --- a/drivers/input/mouse/elan_i2c_i2c.c +++ b/drivers/input/mouse/elan_i2c_i2c.c | |||
@@ -4,7 +4,6 @@ | |||
4 | * Copyright (c) 2013 ELAN Microelectronics Corp. | 4 | * Copyright (c) 2013 ELAN Microelectronics Corp. |
5 | * | 5 | * |
6 | * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw> | 6 | * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw> |
7 | * Version: 1.5.5 | ||
8 | * | 7 | * |
9 | * Based on cyapa driver: | 8 | * Based on cyapa driver: |
10 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. | 9 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. |
diff --git a/drivers/input/mouse/elan_i2c_smbus.c b/drivers/input/mouse/elan_i2c_smbus.c index 359bf8583d54..5cd4a05370c2 100644 --- a/drivers/input/mouse/elan_i2c_smbus.c +++ b/drivers/input/mouse/elan_i2c_smbus.c | |||
@@ -4,7 +4,6 @@ | |||
4 | * Copyright (c) 2013 ELAN Microelectronics Corp. | 4 | * Copyright (c) 2013 ELAN Microelectronics Corp. |
5 | * | 5 | * |
6 | * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw> | 6 | * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw> |
7 | * Version: 1.5.5 | ||
8 | * | 7 | * |
9 | * Based on cyapa driver: | 8 | * Based on cyapa driver: |
10 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. | 9 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. |