All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: serial: Repair FTDI FT232R bricked eeprom
@ 2020-09-08  6:36 James Hilliard
  2020-09-09 10:56 ` kernel test robot
  0 siblings, 1 reply; 3+ messages in thread
From: James Hilliard @ 2020-09-08  6:36 UTC (permalink / raw)
  To: linux-usb
  Cc: Johan Hovold, Greg Kroah-Hartman, linux-kernel, James Hilliard,
	Russ Dill, Hector Martin

This patch detects end reverses the effects of the malicious FTDI
Windows driver version 2.12.00(FTDIgate).

While we currently load the ftdi_sio driver for devices with
FTDI_BRICK_PID(0x0000) userspace applications that expect the
appropriate FTDI_8U232AM_PID(0x6001) PID may not work properly.

Since the malicious FTDI driver modifies the PID without modifying
the normal checksum field we can detect and limit the unbricking
to devices that were bricked specifically using the FTDI checksum
preimage attack technique used by the official Windows drivers.

This should have no effect on devices where the PID was deliberately
set to FTDI_BRICK_PID(0x0000) as the checksum would normally change
and the preimage target(address 62) should be 0. We validate that
the preimage target is not 0 before attempting to unbrick.

Since we only write to even addresses this should have no effect at
all on non-counterfeit FTDI hardware due to the hardware only
committing EEPROM writes when odd addresses are written.

References:
https://marcan.st/transf/detect_ftdi_clone.py
https://hackaday.com/2014/10/22/watch-that-windows-update-ftdi-drivers-are-killing-fake-chips/
https://www.eevblog.com/forum/reviews/ftdi-driver-kills-fake-ftdi-ft232/msg535270/#msg535270
https://lkml.org/lkml/2014/10/23/266
https://lore.kernel.org/patchwork/patch/509929/
https://lore.kernel.org/patchwork/patch/510097/

Signed-off-by: Russ Dill <Russ.Dill@gmail.com>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Cc: Hector Martin <hector@marcansoft.com>
---
 drivers/usb/serial/ftdi_sio.c | 112 ++++++++++++++++++++++++++++++++++
 drivers/usb/serial/ftdi_sio.h |   4 ++
 2 files changed, 116 insertions(+)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 871cdccf3a5f..39fc14af6185 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -2029,6 +2029,22 @@ static int ftdi_read_eeprom(struct usb_serial *serial, void *dst, u16 addr,
 	return 0;
 }
 
+static int ftdi_write_eeprom(struct usb_serial_port *port, u8 addr, u16 data)
+{
+	struct usb_device *udev = port->serial->dev;
+	int rv;
+
+	rv = usb_control_msg(udev,
+			     usb_sndctrlpipe(udev, 0),
+			     FTDI_SIO_WRITE_EEPROM_REQUEST,
+			     FTDI_SIO_WRITE_EEPROM_REQUEST_TYPE,
+			     data, addr,
+			     NULL, 0, WDR_TIMEOUT);
+	if (rv < 0)
+		dev_err(&port->dev, "Unable to write EEPROM: %i\n", rv);
+	return rv;
+}
+
 static int ftdi_gpio_init_ft232h(struct usb_serial_port *port)
 {
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -2234,10 +2250,100 @@ static int ftdi_sio_probe(struct usb_serial *serial,
 	return 0;
 }
 
+static u16 ftdi_checksum(u16 *data, int n)
+{
+	u16 checksum;
+	int i;
+
+	checksum = 0xaaaa;
+	for (i = 0; i < n - 1; i++) {
+		checksum ^= be16_to_cpu(data[i]);
+		checksum = (checksum << 1) | (checksum >> 15);
+	}
+
+	return cpu_to_be16(checksum);
+}
+
+static int ftdi_repair_brick(struct usb_serial_port *port)
+{
+	struct ftdi_private *priv = usb_get_serial_port_data(port);
+	int orig_latency;
+	int rv;
+	u16 *eeprom_data;
+	u16 checksum;
+	int eeprom_size;
+	int result;
+
+	switch (priv->chip_type) {
+	case FT232RL:
+		eeprom_size = 0x40;
+		break;
+	default:
+		/* Unsupported for brick repair */
+		return 0;
+	}
+
+	/* Latency timer needs to be 0x77 to unlock EEPROM programming */
+	if (priv->latency != 0x77) {
+		orig_latency = priv->latency;
+		priv->latency = 0x77;
+		rv = write_latency_timer(port);
+		priv->latency = orig_latency;
+		if (rv < 0)
+			return -EIO;
+	}
+
+	eeprom_data = kmalloc(eeprom_size * 2, GFP_KERNEL);
+	if (!eeprom_data)
+		return -ENOMEM;
+
+	/* Read in EEPROM */
+	result = ftdi_read_eeprom(port->serial, eeprom_data, 0x00, eeprom_size * 2);
+	if (result < 0)
+		goto end_repair_brick;
+
+	/* Verify EEPROM is valid */
+	checksum = ftdi_checksum(eeprom_data, eeprom_size);
+	if (checksum != eeprom_data[eeprom_size - 1])
+		goto end_repair_brick;
+
+	/* FTDI driver checksum preimage attack targets address 62 */
+	if (eeprom_data[62] == 0)
+		goto end_repair_brick;
+
+	/* Attempt to restore Product ID to 0x6001 */
+	eeprom_data[2] = FTDI_8U232AM_PID;
+
+	/* Clear preimage attack target address */
+	eeprom_data[62] = 0;
+
+	/* Calculate and verify new checksum */
+	checksum = ftdi_checksum(eeprom_data, eeprom_size);
+	if (checksum != eeprom_data[eeprom_size - 1])
+		goto end_repair_brick;
+
+	/* Restore EEPROM PID to original pre-brick state */
+	if (ftdi_write_eeprom(port, 2, eeprom_data[2]) < 0)
+		goto end_repair_brick;
+
+	/* Restore EEPROM preimage target address to original pre-brick state */
+	if (ftdi_write_eeprom(port, 62, eeprom_data[62]) < 0)
+		goto end_repair_brick;
+
+	dev_info(&port->dev, "Successfully repaired eeprom bricked by FTDI's malicious Windows driver.\n");
+
+end_repair_brick:
+	kfree(eeprom_data);
+
+	return result;
+}
+
 static int ftdi_sio_port_probe(struct usb_serial_port *port)
 {
 	struct ftdi_private *priv;
 	const struct ftdi_sio_quirk *quirk = usb_get_serial_data(port->serial);
+	u16 vendor_id;
+	u16 product_id;
 	int result;
 
 	priv = kzalloc(sizeof(struct ftdi_private), GFP_KERNEL);
@@ -2255,6 +2361,12 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
 	ftdi_set_max_packet_size(port);
 	if (read_latency_timer(port) < 0)
 		priv->latency = 16;
+	vendor_id = le16_to_cpu(port->serial->dev->descriptor.idVendor);
+	product_id = le16_to_cpu(port->serial->dev->descriptor.idProduct);
+	if (vendor_id == FTDI_VID &&
+		product_id == FTDI_BRICK_PID &&
+		priv->chip_type == FT232RL)
+		ftdi_repair_brick(port);
 	write_latency_timer(port);
 	create_sysfs_attrs(port);
 
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index be1641e0408b..40c6c4372a34 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -39,6 +39,7 @@
 #define FTDI_SIO_SET_BITMODE		0x0b /* Set bitbang mode */
 #define FTDI_SIO_READ_PINS		0x0c /* Read immediate value of pins */
 #define FTDI_SIO_READ_EEPROM		0x90 /* Read EEPROM */
+#define FTDI_SIO_WRITE_EEPROM		0x91 /* Write EEPROM */
 
 /* Interface indices for FT2232, FT2232H and FT4232H devices */
 #define INTERFACE_A		1
@@ -457,6 +458,9 @@ enum ftdi_sio_baudrate {
 #define FTDI_SIO_READ_EEPROM_REQUEST_TYPE 0xc0
 #define FTDI_SIO_READ_EEPROM_REQUEST FTDI_SIO_READ_EEPROM
 
+#define FTDI_SIO_WRITE_EEPROM_REQUEST_TYPE 0x40
+#define FTDI_SIO_WRITE_EEPROM_REQUEST FTDI_SIO_WRITE_EEPROM
+
 #define FTDI_FTX_CBUS_MUX_GPIO		0x8
 #define FTDI_FT232R_CBUS_MUX_GPIO	0xa
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: serial: Repair FTDI FT232R bricked eeprom
  2020-09-08  6:36 [PATCH] usb: serial: Repair FTDI FT232R bricked eeprom James Hilliard
@ 2020-09-09 10:56 ` kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2020-09-09 10:56 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 4807 bytes --]

Hi James,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on usb-serial/usb-next]
[also build test ERROR on usb/usb-testing peter.chen-usb/ci-for-usb-next balbi-usb/testing/next v5.9-rc4 next-20200908]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/James-Hilliard/usb-serial-Repair-FTDI-FT232R-bricked-eeprom/20200908-143733
base:   https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git usb-next
config: mips-rm200_defconfig (attached as .config)
compiler: mipsel-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/usb/serial/ftdi_sio.c: In function 'ftdi_repair_brick':
>> drivers/usb/serial/ftdi_sio.c:2301:11: error: implicit declaration of function 'ftdi_read_eeprom' [-Werror=implicit-function-declaration]
    2301 |  result = ftdi_read_eeprom(port->serial, eeprom_data, 0x00, eeprom_size * 2);
         |           ^~~~~~~~~~~~~~~~
>> drivers/usb/serial/ftdi_sio.c:2326:6: error: implicit declaration of function 'ftdi_write_eeprom' [-Werror=implicit-function-declaration]
    2326 |  if (ftdi_write_eeprom(port, 2, eeprom_data[2]) < 0)
         |      ^~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

# https://github.com/0day-ci/linux/commit/7eb2ed589ba1653721e98ee20e339030a8fe8032
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review James-Hilliard/usb-serial-Repair-FTDI-FT232R-bricked-eeprom/20200908-143733
git checkout 7eb2ed589ba1653721e98ee20e339030a8fe8032
vim +/ftdi_read_eeprom +2301 drivers/usb/serial/ftdi_sio.c

  2266	
  2267	static int ftdi_repair_brick(struct usb_serial_port *port)
  2268	{
  2269		struct ftdi_private *priv = usb_get_serial_port_data(port);
  2270		int orig_latency;
  2271		int rv;
  2272		u16 *eeprom_data;
  2273		u16 checksum;
  2274		int eeprom_size;
  2275		int result;
  2276	
  2277		switch (priv->chip_type) {
  2278		case FT232RL:
  2279			eeprom_size = 0x40;
  2280			break;
  2281		default:
  2282			/* Unsupported for brick repair */
  2283			return 0;
  2284		}
  2285	
  2286		/* Latency timer needs to be 0x77 to unlock EEPROM programming */
  2287		if (priv->latency != 0x77) {
  2288			orig_latency = priv->latency;
  2289			priv->latency = 0x77;
  2290			rv = write_latency_timer(port);
  2291			priv->latency = orig_latency;
  2292			if (rv < 0)
  2293				return -EIO;
  2294		}
  2295	
  2296		eeprom_data = kmalloc(eeprom_size * 2, GFP_KERNEL);
  2297		if (!eeprom_data)
  2298			return -ENOMEM;
  2299	
  2300		/* Read in EEPROM */
> 2301		result = ftdi_read_eeprom(port->serial, eeprom_data, 0x00, eeprom_size * 2);
  2302		if (result < 0)
  2303			goto end_repair_brick;
  2304	
  2305		/* Verify EEPROM is valid */
  2306		checksum = ftdi_checksum(eeprom_data, eeprom_size);
  2307		if (checksum != eeprom_data[eeprom_size - 1])
  2308			goto end_repair_brick;
  2309	
  2310		/* FTDI driver checksum preimage attack targets address 62 */
  2311		if (eeprom_data[62] == 0)
  2312			goto end_repair_brick;
  2313	
  2314		/* Attempt to restore Product ID to 0x6001 */
  2315		eeprom_data[2] = FTDI_8U232AM_PID;
  2316	
  2317		/* Clear preimage attack target address */
  2318		eeprom_data[62] = 0;
  2319	
  2320		/* Calculate and verify new checksum */
  2321		checksum = ftdi_checksum(eeprom_data, eeprom_size);
  2322		if (checksum != eeprom_data[eeprom_size - 1])
  2323			goto end_repair_brick;
  2324	
  2325		/* Restore EEPROM PID to original pre-brick state */
> 2326		if (ftdi_write_eeprom(port, 2, eeprom_data[2]) < 0)
  2327			goto end_repair_brick;
  2328	
  2329		/* Restore EEPROM preimage target address to original pre-brick state */
  2330		if (ftdi_write_eeprom(port, 62, eeprom_data[62]) < 0)
  2331			goto end_repair_brick;
  2332	
  2333		dev_info(&port->dev, "Successfully repaired eeprom bricked by FTDI's malicious Windows driver.\n");
  2334	
  2335	end_repair_brick:
  2336		kfree(eeprom_data);
  2337	
  2338		return result;
  2339	}
  2340	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 18825 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: serial: Repair FTDI FT232R bricked eeprom
@ 2020-09-08 18:48 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2020-09-08 18:48 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 8789 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20200908063609.2817032-1-james.hilliard1@gmail.com>
References: <20200908063609.2817032-1-james.hilliard1@gmail.com>
TO: James Hilliard <james.hilliard1@gmail.com>
TO: linux-usb(a)vger.kernel.org
CC: Johan Hovold <johan@kernel.org>
CC: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
CC: linux-kernel(a)vger.kernel.org
CC: James Hilliard <james.hilliard1@gmail.com>
CC: Russ Dill <Russ.Dill@gmail.com>
CC: Hector Martin <hector@marcansoft.com>

Hi James,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on usb-serial/usb-next]
[also build test WARNING on usb/usb-testing peter.chen-usb/ci-for-usb-next balbi-usb/testing/next v5.9-rc4 next-20200903]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/James-Hilliard/usb-serial-Repair-FTDI-FT232R-bricked-eeprom/20200908-143733
base:   https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git usb-next
:::::: branch date: 12 hours ago
:::::: commit date: 12 hours ago
compiler: sparc64-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


cppcheck warnings: (new ones prefixed by >>)

   drivers/usb/serial/ftdi_sio.c:1688:10: warning: %i in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [invalidPrintfArgType_sint]
     return sprintf(buf, "%in", priv->latency);
            ^
>> drivers/usb/serial/ftdi_sio.c:2291:17: warning: Variable 'priv->latency' is reassigned a value before the old one has been used. [redundantAssignment]
     priv->latency = orig_latency;
                   ^
   drivers/usb/serial/ftdi_sio.c:2289:17: note: Variable 'priv->latency' is reassigned a value before the old one has been used.
     priv->latency = 0x77;
                   ^
   drivers/usb/serial/ftdi_sio.c:2291:17: note: Variable 'priv->latency' is reassigned a value before the old one has been used.
     priv->latency = orig_latency;
                   ^
   drivers/usb/serial/ftdi_sio.c:2810:8: warning: Variable 'cflag' is reassigned a value before the old one has been used. [redundantAssignment]
    cflag = termios->c_cflag;
          ^
   drivers/usb/serial/ftdi_sio.c:2768:0: note: Variable 'cflag' is reassigned a value before the old one has been used.
    unsigned int cflag = termios->c_cflag;
   ^
   drivers/usb/serial/ftdi_sio.c:2810:8: note: Variable 'cflag' is reassigned a value before the old one has been used.
    cflag = termios->c_cflag;
          ^

# https://github.com/0day-ci/linux/commit/7eb2ed589ba1653721e98ee20e339030a8fe8032
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review James-Hilliard/usb-serial-Repair-FTDI-FT232R-bricked-eeprom/20200908-143733
git checkout 7eb2ed589ba1653721e98ee20e339030a8fe8032
vim +2291 drivers/usb/serial/ftdi_sio.c

7eb2ed589ba165 James Hilliard 2020-09-08  2266  
7eb2ed589ba165 James Hilliard 2020-09-08  2267  static int ftdi_repair_brick(struct usb_serial_port *port)
7eb2ed589ba165 James Hilliard 2020-09-08  2268  {
7eb2ed589ba165 James Hilliard 2020-09-08  2269  	struct ftdi_private *priv = usb_get_serial_port_data(port);
7eb2ed589ba165 James Hilliard 2020-09-08  2270  	int orig_latency;
7eb2ed589ba165 James Hilliard 2020-09-08  2271  	int rv;
7eb2ed589ba165 James Hilliard 2020-09-08  2272  	u16 *eeprom_data;
7eb2ed589ba165 James Hilliard 2020-09-08  2273  	u16 checksum;
7eb2ed589ba165 James Hilliard 2020-09-08  2274  	int eeprom_size;
7eb2ed589ba165 James Hilliard 2020-09-08  2275  	int result;
7eb2ed589ba165 James Hilliard 2020-09-08  2276  
7eb2ed589ba165 James Hilliard 2020-09-08  2277  	switch (priv->chip_type) {
7eb2ed589ba165 James Hilliard 2020-09-08  2278  	case FT232RL:
7eb2ed589ba165 James Hilliard 2020-09-08  2279  		eeprom_size = 0x40;
7eb2ed589ba165 James Hilliard 2020-09-08  2280  		break;
7eb2ed589ba165 James Hilliard 2020-09-08  2281  	default:
7eb2ed589ba165 James Hilliard 2020-09-08  2282  		/* Unsupported for brick repair */
7eb2ed589ba165 James Hilliard 2020-09-08  2283  		return 0;
7eb2ed589ba165 James Hilliard 2020-09-08  2284  	}
7eb2ed589ba165 James Hilliard 2020-09-08  2285  
7eb2ed589ba165 James Hilliard 2020-09-08  2286  	/* Latency timer needs to be 0x77 to unlock EEPROM programming */
7eb2ed589ba165 James Hilliard 2020-09-08  2287  	if (priv->latency != 0x77) {
7eb2ed589ba165 James Hilliard 2020-09-08  2288  		orig_latency = priv->latency;
7eb2ed589ba165 James Hilliard 2020-09-08  2289  		priv->latency = 0x77;
7eb2ed589ba165 James Hilliard 2020-09-08  2290  		rv = write_latency_timer(port);
7eb2ed589ba165 James Hilliard 2020-09-08 @2291  		priv->latency = orig_latency;
7eb2ed589ba165 James Hilliard 2020-09-08  2292  		if (rv < 0)
7eb2ed589ba165 James Hilliard 2020-09-08  2293  			return -EIO;
7eb2ed589ba165 James Hilliard 2020-09-08  2294  	}
7eb2ed589ba165 James Hilliard 2020-09-08  2295  
7eb2ed589ba165 James Hilliard 2020-09-08  2296  	eeprom_data = kmalloc(eeprom_size * 2, GFP_KERNEL);
7eb2ed589ba165 James Hilliard 2020-09-08  2297  	if (!eeprom_data)
7eb2ed589ba165 James Hilliard 2020-09-08  2298  		return -ENOMEM;
7eb2ed589ba165 James Hilliard 2020-09-08  2299  
7eb2ed589ba165 James Hilliard 2020-09-08  2300  	/* Read in EEPROM */
7eb2ed589ba165 James Hilliard 2020-09-08  2301  	result = ftdi_read_eeprom(port->serial, eeprom_data, 0x00, eeprom_size * 2);
7eb2ed589ba165 James Hilliard 2020-09-08  2302  	if (result < 0)
7eb2ed589ba165 James Hilliard 2020-09-08  2303  		goto end_repair_brick;
7eb2ed589ba165 James Hilliard 2020-09-08  2304  
7eb2ed589ba165 James Hilliard 2020-09-08  2305  	/* Verify EEPROM is valid */
7eb2ed589ba165 James Hilliard 2020-09-08  2306  	checksum = ftdi_checksum(eeprom_data, eeprom_size);
7eb2ed589ba165 James Hilliard 2020-09-08  2307  	if (checksum != eeprom_data[eeprom_size - 1])
7eb2ed589ba165 James Hilliard 2020-09-08  2308  		goto end_repair_brick;
7eb2ed589ba165 James Hilliard 2020-09-08  2309  
7eb2ed589ba165 James Hilliard 2020-09-08  2310  	/* FTDI driver checksum preimage attack targets address 62 */
7eb2ed589ba165 James Hilliard 2020-09-08  2311  	if (eeprom_data[62] == 0)
7eb2ed589ba165 James Hilliard 2020-09-08  2312  		goto end_repair_brick;
7eb2ed589ba165 James Hilliard 2020-09-08  2313  
7eb2ed589ba165 James Hilliard 2020-09-08  2314  	/* Attempt to restore Product ID to 0x6001 */
7eb2ed589ba165 James Hilliard 2020-09-08  2315  	eeprom_data[2] = FTDI_8U232AM_PID;
7eb2ed589ba165 James Hilliard 2020-09-08  2316  
7eb2ed589ba165 James Hilliard 2020-09-08  2317  	/* Clear preimage attack target address */
7eb2ed589ba165 James Hilliard 2020-09-08  2318  	eeprom_data[62] = 0;
7eb2ed589ba165 James Hilliard 2020-09-08  2319  
7eb2ed589ba165 James Hilliard 2020-09-08  2320  	/* Calculate and verify new checksum */
7eb2ed589ba165 James Hilliard 2020-09-08  2321  	checksum = ftdi_checksum(eeprom_data, eeprom_size);
7eb2ed589ba165 James Hilliard 2020-09-08  2322  	if (checksum != eeprom_data[eeprom_size - 1])
7eb2ed589ba165 James Hilliard 2020-09-08  2323  		goto end_repair_brick;
7eb2ed589ba165 James Hilliard 2020-09-08  2324  
7eb2ed589ba165 James Hilliard 2020-09-08  2325  	/* Restore EEPROM PID to original pre-brick state */
7eb2ed589ba165 James Hilliard 2020-09-08  2326  	if (ftdi_write_eeprom(port, 2, eeprom_data[2]) < 0)
7eb2ed589ba165 James Hilliard 2020-09-08  2327  		goto end_repair_brick;
7eb2ed589ba165 James Hilliard 2020-09-08  2328  
7eb2ed589ba165 James Hilliard 2020-09-08  2329  	/* Restore EEPROM preimage target address to original pre-brick state */
7eb2ed589ba165 James Hilliard 2020-09-08  2330  	if (ftdi_write_eeprom(port, 62, eeprom_data[62]) < 0)
7eb2ed589ba165 James Hilliard 2020-09-08  2331  		goto end_repair_brick;
7eb2ed589ba165 James Hilliard 2020-09-08  2332  
7eb2ed589ba165 James Hilliard 2020-09-08  2333  	dev_info(&port->dev, "Successfully repaired eeprom bricked by FTDI's malicious Windows driver.\n");
7eb2ed589ba165 James Hilliard 2020-09-08  2334  
7eb2ed589ba165 James Hilliard 2020-09-08  2335  end_repair_brick:
7eb2ed589ba165 James Hilliard 2020-09-08  2336  	kfree(eeprom_data);
7eb2ed589ba165 James Hilliard 2020-09-08  2337  
7eb2ed589ba165 James Hilliard 2020-09-08  2338  	return result;
7eb2ed589ba165 James Hilliard 2020-09-08  2339  }
7eb2ed589ba165 James Hilliard 2020-09-08  2340  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-09 10:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08  6:36 [PATCH] usb: serial: Repair FTDI FT232R bricked eeprom James Hilliard
2020-09-09 10:56 ` kernel test robot
2020-09-08 18:48 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.