Skip to contentSkip to conversation

resend: unaligned access in irda protocol stack

PATCH In review Luke Yang 2 participants 2 messages Jul 11, 2006 Networking

lore
Share & tools
lore

Luke Yang

author
#0 lore raw

PATCH 1/1 resend: unaligned access in irda protocol stack

Hi all,

I decided to regenerat and resend a whold patch for this:

For "struct irda_device_info" in irda.h:
struct irda_device_info {

      __u32       saddr;    /* Address of local interface */
      __u32       daddr;    /* Address of remote device */
      char        info[22]; /* Description */
      __u8        charset;  /* Charset used for description */
      __u8        hints[2]; /* Hint bits */

};
The "hints" member aligns at the third byte of a word, an odd
address. So if we visit "hints" as a short in irlmp.c and discorery.c:

  u16ho(irlmp->discovery_cmd.data.hints) = irlmp->hints.word;

will cause alignment problem on some machines. Architectures with strict alignment rules do not allow 16-bit read on an odd address.

discovery.c |    5 +++--
irlmp.c     |    7 ++++---
2 files changed, 7 insertions(+), 5 deletions(-)
net/irda/discovery.c +0 -0
index 3fefc82..5ddf3e5 100644
@@ -38,6 +38,7 @@ #include <net/irda/irda.h>

#include <net/irda/irlmp.h>

#include <net/irda/discovery.h>
+#include <asm/unaligned.h>

/*
* Function irlmp_add_discovery (cachelog, discovery)
@@ -86,7 +87,7 @@ void irlmp_add_discovery(hashbin_t *cach

                        */
                       hashbin_remove_this(cachelog, (irda_queue_t *) node);
                       /* Check if hints bits are unchanged */
-                       if(u16ho(node->data.hints) == u16ho(new->data.hints))
+                       if(get_unaligned(node->data.hints) ==
get_unaligned(new->data.hints))
                               /* Set time of first discovery for this node */
                               new->firststamp = node->firststamp;
                       kfree(node);

@@ -280,7 +281,7 @@ struct irda_device_info *irlmp_copy_disc
/* Mask out the ones we don't want :
* We want to match the discovery mask, and to get only
* the most recent one (unless we want old ones) */
- if ((u16ho(discovery->data.hints) & mask) &&
+ if ((get_unaligned(discovery->data.hints) & mask) &&

                   ((old_entries) ||
                    ((jiffies - discovery->firststamp) < j_timeout)) ) {
                       /* Create buffer as needed.
net/irda/irlmp.c +0 -0
index 129ad64..ee74f73 100644
@@ -42,7 +42,6 @@ #include <net/irda/irlap.h>

#include <net/irda/iriap.h>
#include <net/irda/irlmp.h>
#include <net/irda/irlmp_frame.h>
-
#include <asm/unaligned.h>

static __u8 irlmp_find_free_slsap(void);
@@ -1063,7 +1062,7 @@ void irlmp_discovery_expiry(discinfo_t *

               for(i = 0; i < number; i++) {
                       /* Check if we should notify client */
                       if ((client->expir_callback) &&
-                           (client->hint_mask.word & u16ho(expiries[i].hints)
+                           (client->hint_mask.word &
get_unaligned(expiries[i].hints)
                            & 0x7f7f) )
                               client->expir_callback(&(expiries[i]),
                                                      EXPIRY_TIMEOUT,

@@ -1083,11 +1082,13 @@ void irlmp_discovery_expiry(discinfo_t *
*/
discovery_t *irlmp_get_discovery_response(void)
{

+       __u16 *data_hintsp;
       IRDA_DEBUG(4, "%s()\n", __FUNCTION__);

       IRDA_ASSERT(irlmp != NULL, return NULL;);
-       u16ho(irlmp->discovery_rsp.data.hints) = irlmp->hints.word;
+       data_hintsp = (__u16 *) irlmp->discovery_rsp.data.hints;
+       put_unaligned(irlmp->hints.word, data_hintsp);

/*
* Set character set for device name (we use ASCII), and

Signature · 3 lines
Best regards,
Luke Yang
[email protected]
net/irda/discovery.c +3 -2
index 3fefc82..5ddf3e5 100644
@@ -38,6 +38,7 @@ #include <net/irda/irda.h>
 #include <net/irda/irlmp.h>
 
 #include <net/irda/discovery.h>
+#include <asm/unaligned.h>
 
 /*
  * Function irlmp_add_discovery (cachelog, discovery)
@@ -86,7 +87,7 @@ void irlmp_add_discovery(hashbin_t *cach
 			 */
 			hashbin_remove_this(cachelog, (irda_queue_t *) node);
 			/* Check if hints bits are unchanged */
-			if(u16ho(node->data.hints) == u16ho(new->data.hints))
+			if(get_unaligned(node->data.hints) == get_unaligned(new->data.hints))
 				/* Set time of first discovery for this node */
 				new->firststamp = node->firststamp;
 			kfree(node);
@@ -280,7 +281,7 @@ struct irda_device_info *irlmp_copy_disc
 		/* Mask out the ones we don't want :
 		 * We want to match the discovery mask, and to get only
 		 * the most recent one (unless we want old ones) */
-		if ((u16ho(discovery->data.hints) & mask) &&
+		if ((get_unaligned(discovery->data.hints) & mask) &&
 		    ((old_entries) ||
 		     ((jiffies - discovery->firststamp) < j_timeout)) ) {
 			/* Create buffer as needed.
net/irda/irlmp.c +4 -3
index 129ad64..ee74f73 100644
@@ -42,7 +42,6 @@ #include <net/irda/irlap.h>
 #include <net/irda/iriap.h>
 #include <net/irda/irlmp.h>
 #include <net/irda/irlmp_frame.h>
-
 #include <asm/unaligned.h>
 
 static __u8 irlmp_find_free_slsap(void);
@@ -1063,7 +1062,7 @@ void irlmp_discovery_expiry(discinfo_t *
 		for(i = 0; i < number; i++) {
 			/* Check if we should notify client */
 			if ((client->expir_callback) &&
-			    (client->hint_mask.word & u16ho(expiries[i].hints)
+			    (client->hint_mask.word & get_unaligned(expiries[i].hints)
 			     & 0x7f7f) )
 				client->expir_callback(&(expiries[i]),
 						       EXPIRY_TIMEOUT,
@@ -1083,11 +1082,13 @@ void irlmp_discovery_expiry(discinfo_t *
  */
 discovery_t *irlmp_get_discovery_response(void)
 {
+	__u16 *data_hintsp;
 	IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
 	IRDA_ASSERT(irlmp != NULL, return NULL;);
 
-	u16ho(irlmp->discovery_rsp.data.hints) = irlmp->hints.word;
+	data_hintsp = (__u16 *) irlmp->discovery_rsp.data.hints;
+	put_unaligned(irlmp->hints.word, data_hintsp);
 
 	/*
 	 *  Set character set for device name (we use ASCII), and
Acked-by on v1 1/1
#1 lore raw

Selon Luke Yang <[email protected]>:

Quoted 10 lines

The "hints" member aligns at the third byte of a word, an odd
address. So if we visit "hints" as a short in irlmp.c and discorery.c:

   u16ho(irlmp->discovery_cmd.data.hints) = irlmp->hints.word;

will cause alignment problem on some machines. Architectures with
strict alignment rules do not allow 16-bit read on an odd address.

Dave, I can add this patch to my IrDA queue, unless you want to apply it immediatly.

Cheers,
Samuel.

Quoted 81 lines
 discovery.c |    5 +++--
 irlmp.c     |    7 ++++---
 2 files changed, 7 insertions(+), 5 deletions(-)
net/irda/discovery.c +2 -1
index 3fefc82..5ddf3e5 100644
@@ -38,6 +38,7 @@ #include <net/irda/irda.h>
 #include <net/irda/irlmp.h>
 
 #include <net/irda/discovery.h>
+#include <asm/unaligned.h>
 
 /*
  * Function irlmp_add_discovery (cachelog, discovery)
@@ -86,7 +87,7 @@ void irlmp_add_discovery(hashbin_t *cach
                         */
                        hashbin_remove_this(cachelog, (irda_queue_t *) node);
                        /* Check if hints bits are unchanged */
-                       if(u16ho(node->data.hints) == u16ho(new->data.hints))
+                       if(get_unaligned(node->data.hints) ==
 get_unaligned(new->data.hints))
                                /* Set time of first discovery for this node
 */
                                new->firststamp = node->firststamp;
                        kfree(node);
net/irda/discovery.c +1 -1
@@ -280,7 +281,7 @@ struct irda_device_info *irlmp_copy_disc
                /* Mask out the ones we don't want :
                 * We want to match the discovery mask, and to get only
                 * the most recent one (unless we want old ones) */
-               if ((u16ho(discovery->data.hints) & mask) &&
+               if ((get_unaligned(discovery->data.hints) & mask) &&
                    ((old_entries) ||
                     ((jiffies - discovery->firststamp) < j_timeout)) ) {
                        /* Create buffer as needed.
net/irda/irlmp.c +1 -2
index 129ad64..ee74f73 100644
@@ -42,7 +42,6 @@ #include <net/irda/irlap.h>
 #include <net/irda/iriap.h>
 #include <net/irda/irlmp.h>
 #include <net/irda/irlmp_frame.h>
-
 #include <asm/unaligned.h>
 
 static __u8 irlmp_find_free_slsap(void);
@@ -1063,7 +1062,7 @@ void irlmp_discovery_expiry(discinfo_t *
                for(i = 0; i < number; i++) {
                        /* Check if we should notify client */
                        if ((client->expir_callback) &&
-                           (client->hint_mask.word &
 u16ho(expiries[i].hints)
+                           (client->hint_mask.word &
 get_unaligned(expiries[i].hints)
                             & 0x7f7f) )
                                client->expir_callback(&(expiries[i]),
                                                       EXPIRY_TIMEOUT,
net/irda/irlmp.c +3 -2
@@ -1083,11 +1082,13 @@ void irlmp_discovery_expiry(discinfo_t *
  */
 discovery_t *irlmp_get_discovery_response(void)
 {
+       __u16 *data_hintsp;
        IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
 
        IRDA_ASSERT(irlmp != NULL, return NULL;);
 
-       u16ho(irlmp->discovery_rsp.data.hints) = irlmp->hints.word;
+       data_hintsp = (__u16 *) irlmp->discovery_rsp.data.hints;
+       put_unaligned(irlmp->hints.word, data_hintsp);
 
        /*
         *  Set character set for device name (we use ASCII), and
 
 
--

Best regards,
Luke Yang
[email protected]

Signature · 4 lines
Samuel Ortiz
[email protected]
http://www.sortiz.org
Phone: (+358)-504-868-344