All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads
@ 2017-08-07 21:10 Stephen Douthit
  2017-08-07 21:10 ` [PATCH 1/2] i2c: ismt: Don't duplicate the receive length for " Stephen Douthit
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Stephen Douthit @ 2017-08-07 21:10 UTC (permalink / raw)
  To: seth.heasley, nhorman; +Cc: wsa, danp, stephend, linux-i2c, linux-kernel

Hello all,

We ran into an issue where the ipmi_ssif and i2c-ismt drivers don't
agree on the format for data returned by i2c_smbus_read_block_data()

Looking at the traffic on the wire with a beagle analyzer:
-----
Packet Details   (Values in hex; [S] = Start condition;
                  [P] = Stop condition; * = No Ack)
[S] <10:R> 12 1C 01 00 00 80 02 1C 02 8F BE 12 00 25 12 41 01 00 00* [P]
-----

Looking at the matching kernel trace:
-----
kssif0010-759   [001] ....  1435.891090: smbus_read: i2c-0 a=010 f=0000 c=3 BLOCK_DATA
kssif0010-759   [001] ....  1436.202906: smbus_reply: i2c-0 a=010 f=0000 c=3 BLOCK_DATA l=20 [13-12-1c-01-00-00-80-02-1c-02-8f-be-12-00-25-12-41-01-00-00]
kssif0010-759   [001] ....  1436.202908: smbus_result: i2c-0 a=010 f=0000 c=3 BLOCK_DATA rd res=0
-----

So basically the byte count already precedes the data in the dma_buffer,
then the driver sticks desc->rxbytes in front of this resulting in the
trace above.

The first patch tackles this.

The second patch in the series adds a sanity check on the byte count
supplied by the slave device.  This might be a nice to have, but is
probably less critical.

-Steve

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

* [PATCH 1/2] i2c: ismt: Don't duplicate the receive length for block reads
  2017-08-07 21:10 [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Stephen Douthit
@ 2017-08-07 21:10 ` Stephen Douthit
  2017-08-07 21:11 ` [PATCH 2/2] i2c: ismt: Return EMSGSIZE for block reads with bogus length Stephen Douthit
  2017-08-14 19:31 ` [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Wolfram Sang
  2 siblings, 0 replies; 11+ messages in thread
From: Stephen Douthit @ 2017-08-07 21:10 UTC (permalink / raw)
  To: seth.heasley, nhorman; +Cc: wsa, danp, stephend, linux-i2c, linux-kernel

According to Table 15-14 of the C2000 EDS (Intel doc #510524) the
rx data pointed to by the descriptor dptr contains the byte count.

desc->rxbytes reports all bytes read on the wire, including the
"byte count" byte.  So if a device sends 4 bytes in response to a
block read, on the wire and in the DMA buffer we see:

count data1 data2 data3 data4
 0x04  0xde  0xad  0xbe  0xef

That's what we want to return in data->block to the next level.

Instead we were actually prefixing that with desc->rxbytes:

bad
count count data1 data2 data3 data4
 0x05  0x04  0xde  0xad  0xbe  0xef

This was discovered while developing a BMC solution relying on the
ipmi_ssif.c driver which was trying to interpret the bogus length
field as part of the IPMI response.

Signed-off-by: Stephen Douthit <stephend@adiengineering.com>
Tested-by: Dan Priamo <danp@adiengineering.com>
---
 drivers/i2c/busses/i2c-ismt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
index e98e44e..9af2337 100644
--- a/drivers/i2c/busses/i2c-ismt.c
+++ b/drivers/i2c/busses/i2c-ismt.c
@@ -341,8 +341,8 @@ static int ismt_process_desc(const struct ismt_desc *desc,
 			break;
 		case I2C_SMBUS_BLOCK_DATA:
 		case I2C_SMBUS_I2C_BLOCK_DATA:
-			memcpy(&data->block[1], dma_buffer, desc->rxbytes);
-			data->block[0] = desc->rxbytes;
+			memcpy(data->block, dma_buffer, desc->rxbytes);
+			data->block[0] = desc->rxbytes - 1;
 			break;
 		}
 		return 0;
-- 
2.7.5

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

* [PATCH 2/2] i2c: ismt: Return EMSGSIZE for block reads with bogus length
  2017-08-07 21:10 [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Stephen Douthit
  2017-08-07 21:10 ` [PATCH 1/2] i2c: ismt: Don't duplicate the receive length for " Stephen Douthit
@ 2017-08-07 21:11 ` Stephen Douthit
  2017-08-14 19:31 ` [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Wolfram Sang
  2 siblings, 0 replies; 11+ messages in thread
From: Stephen Douthit @ 2017-08-07 21:11 UTC (permalink / raw)
  To: seth.heasley, nhorman; +Cc: wsa, danp, stephend, linux-i2c, linux-kernel

Compare the number of bytes actually seen on the wire to the byte
count field returned by the slave device.

Previously we just overwrote the byte count returned by the slave
with the real byte count and let the caller figure out if the
message was sane.

Signed-off-by: Stephen Douthit <stephend@adiengineering.com>
Tested-by: Dan Priamo <danp@adiengineering.com>
---
 drivers/i2c/busses/i2c-ismt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
index 9af2337..22ffcb7 100644
--- a/drivers/i2c/busses/i2c-ismt.c
+++ b/drivers/i2c/busses/i2c-ismt.c
@@ -341,8 +341,10 @@ static int ismt_process_desc(const struct ismt_desc *desc,
 			break;
 		case I2C_SMBUS_BLOCK_DATA:
 		case I2C_SMBUS_I2C_BLOCK_DATA:
+			if (desc->rxbytes != dma_buffer[0] + 1)
+				return -EMSGSIZE;
+
 			memcpy(data->block, dma_buffer, desc->rxbytes);
-			data->block[0] = desc->rxbytes - 1;
 			break;
 		}
 		return 0;
-- 
2.7.5

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

* Re: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads
  2017-08-07 21:10 [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Stephen Douthit
  2017-08-07 21:10 ` [PATCH 1/2] i2c: ismt: Don't duplicate the receive length for " Stephen Douthit
  2017-08-07 21:11 ` [PATCH 2/2] i2c: ismt: Return EMSGSIZE for block reads with bogus length Stephen Douthit
@ 2017-08-14 19:31 ` Wolfram Sang
  2017-08-28 13:50   ` Stephen Douthit
  2 siblings, 1 reply; 11+ messages in thread
From: Wolfram Sang @ 2017-08-14 19:31 UTC (permalink / raw)
  To: Stephen Douthit; +Cc: seth.heasley, nhorman, danp, linux-i2c, linux-kernel

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

On Mon, Aug 07, 2017 at 05:10:58PM -0400, Stephen Douthit wrote:
> Hello all,
> 
> We ran into an issue where the ipmi_ssif and i2c-ismt drivers don't
> agree on the format for data returned by i2c_smbus_read_block_data()
> 
> Looking at the traffic on the wire with a beagle analyzer:
> -----
> Packet Details   (Values in hex; [S] = Start condition;
>                   [P] = Stop condition; * = No Ack)
> [S] <10:R> 12 1C 01 00 00 80 02 1C 02 8F BE 12 00 25 12 41 01 00 00* [P]
> -----
> 
> Looking at the matching kernel trace:
> -----
> kssif0010-759   [001] ....  1435.891090: smbus_read: i2c-0 a=010 f=0000 c=3 BLOCK_DATA
> kssif0010-759   [001] ....  1436.202906: smbus_reply: i2c-0 a=010 f=0000 c=3 BLOCK_DATA l=20 [13-12-1c-01-00-00-80-02-1c-02-8f-be-12-00-25-12-41-01-00-00]
> kssif0010-759   [001] ....  1436.202908: smbus_result: i2c-0 a=010 f=0000 c=3 BLOCK_DATA rd res=0
> -----
> 
> So basically the byte count already precedes the data in the dma_buffer,
> then the driver sticks desc->rxbytes in front of this resulting in the
> trace above.
> 
> The first patch tackles this.
> 
> The second patch in the series adds a sanity check on the byte count
> supplied by the slave device.  This might be a nice to have, but is
> probably less critical.

Both patches look good to me. Seth, Neil, do you agree?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads
  2017-08-14 19:31 ` [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Wolfram Sang
@ 2017-08-28 13:50   ` Stephen Douthit
  2017-08-29 10:22     ` Wolfram Sang
  0 siblings, 1 reply; 11+ messages in thread
From: Stephen Douthit @ 2017-08-28 13:50 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: seth.heasley, nhorman, danp, linux-i2c, linux-kernel

On 8/14/2017 3:31 PM, Wolfram Sang wrote:
> On Mon, Aug 07, 2017 at 05:10:58PM -0400, Stephen Douthit wrote:
>> Hello all,
>>
>> We ran into an issue where the ipmi_ssif and i2c-ismt drivers don't
>> agree on the format for data returned by i2c_smbus_read_block_data()
>>
>> Looking at the traffic on the wire with a beagle analyzer:
>> -----
>> Packet Details   (Values in hex; [S] = Start condition;
>>                   [P] = Stop condition; * = No Ack)
>> [S] <10:R> 12 1C 01 00 00 80 02 1C 02 8F BE 12 00 25 12 41 01 00 00* [P]
>> -----
>>
>> Looking at the matching kernel trace:
>> -----
>> kssif0010-759   [001] ....  1435.891090: smbus_read: i2c-0 a=010 f=0000 c=3 BLOCK_DATA
>> kssif0010-759   [001] ....  1436.202906: smbus_reply: i2c-0 a=010 f=0000 c=3 BLOCK_DATA l=20 [13-12-1c-01-00-00-80-02-1c-02-8f-be-12-00-25-12-41-01-00-00]
>> kssif0010-759   [001] ....  1436.202908: smbus_result: i2c-0 a=010 f=0000 c=3 BLOCK_DATA rd res=0
>> -----
>>
>> So basically the byte count already precedes the data in the dma_buffer,
>> then the driver sticks desc->rxbytes in front of this resulting in the
>> trace above.
>>
>> The first patch tackles this.
>>
>> The second patch in the series adds a sanity check on the byte count
>> supplied by the slave device.  This might be a nice to have, but is
>> probably less critical.
> 
> Both patches look good to me. Seth, Neil, do you agree?
> 

Ping.

Not sure what the usual review time is, let me know if this is premature.

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

* Re: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads
  2017-08-28 13:50   ` Stephen Douthit
@ 2017-08-29 10:22     ` Wolfram Sang
  2017-08-29 11:35       ` Neil Horman
  0 siblings, 1 reply; 11+ messages in thread
From: Wolfram Sang @ 2017-08-29 10:22 UTC (permalink / raw)
  To: Stephen Douthit; +Cc: seth.heasley, nhorman, danp, linux-i2c, linux-kernel

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


> >> So basically the byte count already precedes the data in the dma_buffer,
> >> then the driver sticks desc->rxbytes in front of this resulting in the
> >> trace above.
> >>
> >> The first patch tackles this.
> >>
> >> The second patch in the series adds a sanity check on the byte count
> >> supplied by the slave device.  This might be a nice to have, but is
> >> probably less critical.
> > 
> > Both patches look good to me. Seth, Neil, do you agree?
> > 
> 
> Ping.
> 
> Not sure what the usual review time is, let me know if this is premature.

I applied both patches to for-next (v4.14) now to get a broader
audience. for-current (v4.13) might have been also applicable, but I
don't want to apply the patches there without the driver maintainer
acks. I hope this works for you.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads
  2017-08-29 10:22     ` Wolfram Sang
@ 2017-08-29 11:35       ` Neil Horman
  2017-08-29 11:49         ` Wolfram Sang
  0 siblings, 1 reply; 11+ messages in thread
From: Neil Horman @ 2017-08-29 11:35 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Stephen Douthit, seth.heasley, danp, linux-i2c, linux-kernel

On Tue, Aug 29, 2017 at 12:22:25PM +0200, Wolfram Sang wrote:
> 
> > >> So basically the byte count already precedes the data in the dma_buffer,
> > >> then the driver sticks desc->rxbytes in front of this resulting in the
> > >> trace above.
> > >>
> > >> The first patch tackles this.
> > >>
> > >> The second patch in the series adds a sanity check on the byte count
> > >> supplied by the slave device.  This might be a nice to have, but is
> > >> probably less critical.
> > > 
> > > Both patches look good to me. Seth, Neil, do you agree?
> > > 
> > 
> > Ping.
> > 
> > Not sure what the usual review time is, let me know if this is premature.
> 
> I applied both patches to for-next (v4.14) now to get a broader
> audience. for-current (v4.13) might have been also applicable, but I
> don't want to apply the patches there without the driver maintainer
> acks. I hope this works for you.
> 

Sorry, I've been on vacation, yes, the patches look good to me

Acked-by: Neil Horman <nhorman@tuxdriver.com>

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

* Re: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads
  2017-08-29 11:35       ` Neil Horman
@ 2017-08-29 11:49         ` Wolfram Sang
  2017-08-29 18:12           ` Dan Priamo
  0 siblings, 1 reply; 11+ messages in thread
From: Wolfram Sang @ 2017-08-29 11:49 UTC (permalink / raw)
  To: Neil Horman; +Cc: Stephen Douthit, seth.heasley, danp, linux-i2c, linux-kernel

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


> Sorry, I've been on vacation, yes, the patches look good to me

All fine, I was just being cautious.

> Acked-by: Neil Horman <nhorman@tuxdriver.com>

Thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* RE: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads
  2017-08-29 11:49         ` Wolfram Sang
@ 2017-08-29 18:12           ` Dan Priamo
  2017-08-29 20:08             ` Wolfram Sang
  0 siblings, 1 reply; 11+ messages in thread
From: Dan Priamo @ 2017-08-29 18:12 UTC (permalink / raw)
  To: Wolfram Sang, Neil Horman
  Cc: Steve Douthit, seth.heasley, linux-i2c, linux-kernel

Hi,

We are using Linux stable kernel version 4.4.y and would like to see these changes included in that version.
So once these patches are merged in, can they be tagged for other Linux stable kernel releases to pick up these changes? 

Thank you!
Dan

-----Original Message-----
From: Wolfram Sang [mailto:wsa@the-dreams.de] 
Sent: Tuesday, August 29, 2017 7:50 AM
To: Neil Horman <nhorman@tuxdriver.com>
Cc: Steve Douthit <stephend@adiengineering.com>; seth.heasley@intel.com; Dan Priamo <danp@adiengineering.com>; linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads


> Sorry, I've been on vacation, yes, the patches look good to me

All fine, I was just being cautious.

> Acked-by: Neil Horman <nhorman@tuxdriver.com>

Thanks!

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

* Re: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads
  2017-08-29 18:12           ` Dan Priamo
@ 2017-08-29 20:08             ` Wolfram Sang
  2017-08-29 20:10               ` Dan Priamo
  0 siblings, 1 reply; 11+ messages in thread
From: Wolfram Sang @ 2017-08-29 20:08 UTC (permalink / raw)
  To: Dan Priamo
  Cc: Neil Horman, Steve Douthit, seth.heasley, linux-i2c, linux-kernel

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

> We are using Linux stable kernel version 4.4.y and would like to see
> these changes included in that version. So once these patches are
> merged in, can they be tagged for other Linux stable kernel releases
> to pick up these changes?

Okay, since I haven't pushed out yet, I can re-apply the bugfix to
for-current and add the stable tag to it.



[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* RE: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads
  2017-08-29 20:08             ` Wolfram Sang
@ 2017-08-29 20:10               ` Dan Priamo
  0 siblings, 0 replies; 11+ messages in thread
From: Dan Priamo @ 2017-08-29 20:10 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Neil Horman, Steve Douthit, seth.heasley, linux-i2c, linux-kernel

Thank you!

-----Original Message-----
From: Wolfram Sang [mailto:wsa@the-dreams.de] 
Sent: Tuesday, August 29, 2017 4:09 PM
To: Dan Priamo <danp@adiengineering.com>
Cc: Neil Horman <nhorman@tuxdriver.com>; Steve Douthit <stephend@adiengineering.com>; seth.heasley@intel.com; linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads

> We are using Linux stable kernel version 4.4.y and would like to see 
> these changes included in that version. So once these patches are 
> merged in, can they be tagged for other Linux stable kernel releases 
> to pick up these changes?

Okay, since I haven't pushed out yet, I can re-apply the bugfix to for-current and add the stable tag to it.

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

end of thread, other threads:[~2017-08-29 20:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-07 21:10 [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Stephen Douthit
2017-08-07 21:10 ` [PATCH 1/2] i2c: ismt: Don't duplicate the receive length for " Stephen Douthit
2017-08-07 21:11 ` [PATCH 2/2] i2c: ismt: Return EMSGSIZE for block reads with bogus length Stephen Douthit
2017-08-14 19:31 ` [PATCH 0/2] i2c: ismt: Fix length handling for SMBus block reads Wolfram Sang
2017-08-28 13:50   ` Stephen Douthit
2017-08-29 10:22     ` Wolfram Sang
2017-08-29 11:35       ` Neil Horman
2017-08-29 11:49         ` Wolfram Sang
2017-08-29 18:12           ` Dan Priamo
2017-08-29 20:08             ` Wolfram Sang
2017-08-29 20:10               ` Dan Priamo

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.