Skip to contentSkip to conversation

b43: Fix possible unaligned u32 access

PATCH In review Michael Buesch 4 participants 10 messages Jun 4, 2009 – Jun 6, 2009 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 b43: Fix possible unaligned u32 access

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if the structure element is accessed through a local pointer.

---

Please queue this bugfix.

drivers/net/wireless/b43/xmit.c +2 -3
index a63d888..55f36a7 100644
@@ -118,7 +118,6 @@ u8 b43_plcp_get_ratecode_ofdm(const u8 bitrate)
 void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
 			   const u16 octets, const u8 bitrate)
 {
-	__le32 *data = &(plcp->data);
 	__u8 *raw = plcp->raw;
 
 	if (b43_is_ofdm_rate(bitrate)) {
@@ -127,7 +126,7 @@ void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
 		d = b43_plcp_get_ratecode_ofdm(bitrate);
 		B43_WARN_ON(octets & 0xF000);
 		d |= (octets << 5);
-		*data = cpu_to_le32(d);
+		plcp->data = cpu_to_le32(d);
 	} else {
 		u32 plen;
 
@@ -141,7 +140,7 @@ void b43_generate_plcp_hdr(struct b43_plcp_hdr4 *plcp,
 				raw[1] = 0x04;
 		} else
 			raw[1] = 0x04;
-		*data |= cpu_to_le32(plen << 16);
+		plcp->data |= cpu_to_le32(plen << 16);
 		raw[0] = b43_plcp_get_ratecode_cck(bitrate);
 	}
 }
Signature · 1 line
Greetings, Michael.
#1 lore raw
Quoted 9 lines · Michael Buesch

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if the structure element is accessed through a local pointer.

That seems pretty brain-dead...can you cite a source for this information? The patch seems like a no-op...

John

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#2 lore raw

Quoting "John W. Linville" <[email protected]>:

Quoted 6 lines · Michael Buesch
Quoted 5 lines

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if

Quoted 8 lines

the

Quoted 4 lines

structure element is accessed through a local pointer.

That seems pretty brain-dead...can you cite a source for this information?

The test I did with the attached test case in the first post.

I don't see why gcc should propagate packed structure info to assignment. That will be impossible to handle (think of passing it to function parameter).

Quoted 1 line

The patch seems like a no-op...

At least the code produced on mips is different.

Matthieu

#3 lore raw
Quoted 9 lines · On Fri, Jun 05, 2009 at 05:03:57PM +0200, [email protected] wrote:

Quoting "John W. Linville" <[email protected]>:

Quoted 7 lines · Michael Buesch
Quoted 5 lines

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if

the

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

structure element is accessed through a local pointer.

That seems pretty brain-dead...can you cite a source for this information?

The test I did with the attached test case in the first post.

Link?

Quoted 2 lines

I don't see why gcc should propagate packed structure info to assignment. That will be impossible to handle (think of passing it to function parameter).

Perhaps this is obvious to you, but it isn't to me.

Quoted 3 lines
Quoted 2 lines

The patch seems like a no-op...

At least the code produced on mips is different.

Then why aren't you trying to get the mips gcc guys to fix it?

John

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#4 lore raw
Quoted 17 lines · John W. Linville
Quoted 16 lines · On Fri, Jun 05, 2009 at 05:03:57PM +0200, [email protected] wrote:

Quoting "John W. Linville" <[email protected]>:

Quoted 14 lines · Michael Buesch
Quoted 5 lines

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if

the

Quoted 4 lines

structure element is accessed through a local pointer.

That seems pretty brain-dead...can you cite a source for this information?

Quoted 8 lines
Quoted 1 line

The test I did with the attached test case in the first post.

Link?

Quoted 2 lines

I don't see why gcc should propagate packed structure info to assignment. That will be impossible to handle (think of passing it to function parameter).

Perhaps this is obvious to you, but it isn't to me.

OK, I got an explanation from Kyle McMartin that I grok...

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

The patch seems like a no-op...

At least the code produced on mips is different.

Then why aren't you trying to get the mips gcc guys to fix it?

Still worth wondering...anyway, the patch is fine -- I just didn't grok the explanation.

John

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#5 lore raw
In reply to John W. Linville
Quoted 8 lines · On Friday 05 June 2009 14:25:03 John W. Linville wrote:
Quoted 7 lines · Michael Buesch

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if the structure element is accessed through a local pointer.

Quoted 7 lines
Quoted 2 lines

That seems pretty brain-dead...can you cite a source for this information? The patch seems like a no-op...

John

struct foo {
	int data;
} __attribute__((packed));

struct foo foo;
int *d = &foo->data;
foo->data = x; /* Works for unaligned */
*d = y; /* Does not work for unaligned */

Signature · 1 line
Greetings, Michael.
#6 lore raw
Quoted 17 lines · Michael Buesch
Quoted 8 lines · On Friday 05 June 2009 14:25:03 John W. Linville wrote:
Quoted 7 lines · Michael Buesch

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if the structure element is accessed through a local pointer.

Quoted 7 lines
Quoted 2 lines

That seems pretty brain-dead...can you cite a source for this information? The patch seems like a no-op...

John

Quoted 8 lines
struct foo {
	int data;
} __attribute__((packed));

struct foo foo;
int *d = &foo->data;
foo->data = x; /* Works for unaligned */
*d = y; /* Does not work for unaligned */

Why not?

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#7 lore raw
Quoted 22 lines · On Friday 05 June 2009 20:50:48 John W. Linville wrote:
Quoted 21 lines · Michael Buesch
Quoted 8 lines · On Friday 05 June 2009 14:25:03 John W. Linville wrote:
Quoted 7 lines · Michael Buesch

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if the structure element is accessed through a local pointer.

Quoted 7 lines
Quoted 2 lines

That seems pretty brain-dead...can you cite a source for this information? The patch seems like a no-op...

John

struct foo {
	int data;
} __attribute__((packed));
Quoted 7 lines
Quoted 4 lines

struct foo foo;
int *d = &foo->data;
foo->data = x; /* Works for unaligned */
*d = y; /* Does not work for unaligned */

Why not?

Because some compilers don't carry the "packed" attribute of "data" though the "d" pointer. So foo->data is a "packed" access, while *d might not.

Signature · 1 line
Greetings, Michael.
#8 lore raw
In reply to John W. Linville

From: "John W. Linville" <[email protected]>
Date: Fri, 5 Jun 2009 14:50:48 -0400

Quoted 22 lines · Michael Buesch
Quoted 21 lines · On Friday 05 June 2009 14:25:03 John W. Linville wrote:
Quoted 8 lines · Michael Buesch
Quoted 7 lines

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if the structure element is accessed through a local pointer.

Quoted 7 lines
Quoted 2 lines

That seems pretty brain-dead...can you cite a source for this information? The patch seems like a no-op...

John

struct foo {
	int data;
} __attribute__((packed));
Quoted 6 lines
Quoted 4 lines

struct foo foo;
int *d = &foo->data;
foo->data = x; /* Works for unaligned */
*d = y; /* Does not work for unaligned */

Why not?

Because "int *" does not have the packed attribute.

#9 lore raw
In reply to John W. Linville

From: "John W. Linville" <[email protected]>
Date: Fri, 5 Jun 2009 08:25:03 -0400

Quoted 8 lines · Michael Buesch
Quoted 7 lines

From: Matthieu CASTET <[email protected]>

Fix possible unaligned u32 access in b43_generate_plcp_hdr(). Unaligned data is read/write with a u32 pointer instead of using the packed structure. Some versions of gcc ignore the "packed" attribute, if the structure element is accessed through a local pointer.

Quoted 5 lines
Quoted 2 lines

That seems pretty brain-dead...can you cite a source for this information? The patch seems like a no-op...

The "packed" attribute simply doesn't propagate. It isn't a GCC bug. Look at this:

struct foo {
	u32 x;
} attribute((packed));

u32 bar(struct foo *p)

{
	u32 *p = &p->x;

	return *p;
}

That will (correctly) do a 32-bit aligned load, only doing the "return p->x;" will proply respect the packed attribute.