Skip to contentSkip to conversation

platform/surface: aggregator: Fix access of unaligned value

PATCH Superseded Maximilian Luz 3 participants 5 messages Feb 10, 2021 – Feb 11, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Maximilian Luz

author maintainer
#0 lore raw

PATCH 1/1 platform/surface: aggregator: Fix access of unaligned value

The raw message frame length is unaligned and explicitly marked as little endian. It should not be accessed without the appropriatte accessor functions. Fix this.

Fixes c167b9c7e3d6 ("platform/surface: Add Surface Aggregator subsystem")
---
 drivers/platform/surface/aggregator/ssh_packet_layer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/surface/aggregator/ssh_packet_layer.c +2 -1
index 583315db8b02..9a78188d8d1c 100644
@@ -1774,7 +1774,8 @@ static size_t ssh_ptl_rx_eval(struct ssh_ptl *ptl, struct ssam_span *source)
 		break;
 	}
 
-	return aligned.ptr - source->ptr + SSH_MESSAGE_LENGTH(frame->len);
+	return aligned.ptr - source->ptr
+		+ SSH_MESSAGE_LENGTH(get_unaligned_le16(&frame->len));
 }
 
 static int ssh_ptl_rx_threadfn(void *data)
Signature · 1 line
2.30.0
Acked-by on v1 1/1
#1 lore raw
Quoted 28 lines · Maximilian Luz

The raw message frame length is unaligned and explicitly marked as little endian. It should not be accessed without the appropriatte accessor functions. Fix this.

Fixes c167b9c7e3d6 ("platform/surface: Add Surface Aggregator subsystem")
---
 drivers/platform/surface/aggregator/ssh_packet_layer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/surface/aggregator/ssh_packet_layer.c +2 -1
index 583315db8b02..9a78188d8d1c 100644
@@ -1774,7 +1774,8 @@ static size_t ssh_ptl_rx_eval(struct ssh_ptl *ptl, struct ssam_span *source)
 		break;
 	}
 
-	return aligned.ptr - source->ptr + SSH_MESSAGE_LENGTH(frame->len);
+	return aligned.ptr - source->ptr
+		+ SSH_MESSAGE_LENGTH(get_unaligned_le16(&frame->len));
 }
 
 static int ssh_ptl_rx_threadfn(void *data)
Signature · 1 line
2.30.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Maximilian Luz
Quoted 3 lines · Maximilian Luz

The raw message frame length is unaligned and explicitly marked as little endian. It should not be accessed without the appropriatte accessor functions. Fix this.

Though a few nit-picks below.

Quoted 12 lines
Fixes c167b9c7e3d6 ("platform/surface: Add Surface Aggregator subsystem")
---
 drivers/platform/surface/aggregator/ssh_packet_layer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/surface/aggregator/ssh_packet_layer.c +0 -0
index 583315db8b02..9a78188d8d1c 100644

drivers/platform/surface/aggregator/ssh_packet_layer.c static size_t ssh_ptl_rx_eval(struct ssh_ptl *ptl, struct ssam_span *source) · line 1778

Quoted 6 lines
drivers/platform/surface/aggregator/ssh_packet_layer.c +2 -1
@@ -1774,7 +1774,8 @@ static size_t ssh_ptl_rx_eval(struct ssh_ptl *ptl, struct ssam_span *source)
 		break;
 	}
 
-	return aligned.ptr - source->ptr + SSH_MESSAGE_LENGTH(frame->len);
+	return aligned.ptr - source->ptr
+		+ SSH_MESSAGE_LENGTH(get_unaligned_le16(&frame->len));

I would leave + on previous line.
Also it's possible to annotate temporary variable and use it, but it seems not worth to do.

Side question: Do you think the below is correct (& operator)?

        sp.len = get_unaligned_le16(&((struct ssh_frame *)sf.ptr)->len);

To me seems like you take an address to len member rather its value.

Quoted 3 lines
drivers/platform/surface/aggregator/ssh_packet_layer.c +0 -0
 }
 
 static int ssh_ptl_rx_threadfn(void *data)
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#3 lore raw
Quoted 23 lines · Andy Shevchenko
Quoted 3 lines · Maximilian Luz

The raw message frame length is unaligned and explicitly marked as little endian. It should not be accessed without the appropriatte accessor functions. Fix this.

Though a few nit-picks below.

Quoted 15 lines
Fixes c167b9c7e3d6 ("platform/surface: Add Surface Aggregator subsystem")
---
  drivers/platform/surface/aggregator/ssh_packet_layer.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/surface/aggregator/ssh_packet_layer.c +0 -0
index 583315db8b02..9a78188d8d1c 100644
@@ -1774,7 +1774,8 @@ static size_t ssh_ptl_rx_eval(struct ssh_ptl *ptl, struct ssam_span *source)
  		break;
  	}
 
Quoted 5 lines

drivers/platform/surface/aggregator/ssh_packet_layer.c static size_t ssh_ptl_rx_eval(struct ssh_ptl *ptl, struct ssam_span *source) · line 1778

Quoted 3 lines
drivers/platform/surface/aggregator/ssh_packet_layer.c +2 -1
-	return aligned.ptr - source->ptr + SSH_MESSAGE_LENGTH(frame->len);
+	return aligned.ptr - source->ptr
+		+ SSH_MESSAGE_LENGTH(get_unaligned_le16(&frame->len));

I would leave + on previous line.

I can fix that if it bugs you.

Quoted 2 lines

Also it's possible to annotate temporary variable and use it, but it seems not worth to do.

Now that you mention it, we already have the correct frame length in payload.len. Let me draft up a new patch with that.

Quoted 5 lines

Side question: Do you think the below is correct (& operator)?

         sp.len = get_unaligned_le16(&((struct ssh_frame *)sf.ptr)->len);

To me seems like you take an address to len member rather its value.

That's the point though, no? The signature is

u16 get_unaligned_le16(const void *p)

so we do want a pointer to the len member. So I believe that is correct.

Quoted 5 lines
Quoted 4 lines
drivers/platform/surface/aggregator/ssh_packet_layer.c +0 -0
  }
 
  static int ssh_ptl_rx_threadfn(void *data)
#4 lore raw
Quoted 5 lines · Maximilian Luz
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Maximilian Luz

The raw message frame length is unaligned and explicitly marked as little endian. It should not be accessed without the appropriatte accessor functions. Fix this.

...

Quoted 5 lines
Quoted 2 lines

Also it's possible to annotate temporary variable and use it, but it seems not worth to do.

Now that you mention it, we already have the correct frame length in payload.len. Let me draft up a new patch with that.

Good!

Quoted 11 lines
Quoted 5 lines

Side question: Do you think the below is correct (& operator)?

         sp.len = get_unaligned_le16(&((struct ssh_frame *)sf.ptr)->len);

To me seems like you take an address to len member rather its value.

That's the point though, no? The signature is

u16 get_unaligned_le16(const void *p)

so we do want a pointer to the len member. So I believe that is correct.

Indeed. I messed up with le16_to_cpu().

Signature · 2 lines
With Best Regards,
Andy Shevchenko