Project

General

Profile

Actions

Bug #6286

closed

codec_ecu_fr_test misaligned access reported by address sanitizer

Added by neels 3 months ago. Updated about 2 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
-
Target version:
-
Start date:
12/04/2023
Due date:
% Done:

100%

Spec Reference:

Description

with --enable-sanitize, I get this:

codec/codec_ecu_fr_test \
    >../../../src/libosmocore/tests/codec/codec_ecu_fr_test.ok
../../../../src/libosmocore/src/codec/ecu_fr.c:297:15: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:298:2: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/core/prbs.c:49:11: runtime error: member access within misaligned address 0x60f0000000d4 for type 'struct osmo_prbs_state', which requires 8 byte alignment
0x60f0000000d4: note: pointer points here
  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/core/prbs.c:50:12: runtime error: member access within misaligned address 0x60f0000000d4 for type 'struct osmo_prbs_state', which requires 8 byte alignment
0x60f0000000d4: note: pointer points here
  00 00 00 00 40 e9 ac 50  42 7f 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:112:12: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:113:16: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 00 00 00 00  d9 ec 9b e2 12 90 1f 80  23 35 59 8c 50 1f 80 5b  ad 3d 4b a0 1f 80 9b 69
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:114:26: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 01 00 00 00  d9 ec 9b e2 12 90 1f 80  23 35 59 8c 50 1f 80 5b  ad 3d 4b a0 1f 80 9b 69
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:241:12: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 01 00 00 00  d9 ec 9b e2 12 90 1f 80  23 35 59 8c 50 1f 80 5b  ad 3d 4b a0 1f 80 9b 69
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:249:19: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 01 00 00 00  d9 ec 9b e2 12 90 1f 80  23 35 59 8c 50 1f 80 5b  ad 3d 4b a0 1f 80 9b 69
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:250:16: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 01 00 00 00  d9 ec 9b e2 12 90 1f 80  23 35 59 8c 50 1f 80 5b  ad 3d 4b a0 1f 80 9b 69
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:253:25: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 02 00 00 00  d9 ec 9b e2 12 90 1f 80  23 35 59 8c 50 1f 80 5b  ad 3d 4b a0 1f 80 9b 69
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:254:19: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 02 00 00 00  d9 ec 9b e2 12 90 1d 80  23 35 59 8c 50 1d 80 5b  ad 3d 4b a0 1d 80 9b 69
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:195:21: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 02 00 00 00  d9 ec 9b e2 12 90 1d 80  23 35 59 8c 50 1d 80 5b  ad 3d 4b a0 1d 80 9b 69
              ^ 
../../../../src/libosmocore/src/core/prbs.c:63:23: runtime error: member access within misaligned address 0x60f0000000d4 for type 'struct osmo_prbs_state', which requires 8 byte alignment
0x60f0000000d4: note: pointer points here
  00 00 00 00 40 e9 ac 50  42 7f 00 00 01 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/core/prbs.c:55:7: runtime error: member access within misaligned address 0x60f0000000d4 for type 'struct osmo_prbs_state', which requires 8 byte alignment
0x60f0000000d4: note: pointer points here
  00 00 00 00 40 e9 ac 50  42 7f 00 00 01 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/core/prbs.c:55:15: runtime error: member access within misaligned address 0x60f0000000d4 for type 'struct osmo_prbs_state', which requires 8 byte alignment
0x60f0000000d4: note: pointer points here
  00 00 00 00 40 e9 ac 50  42 7f 00 00 01 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/core/prbs.c:57:8: runtime error: member access within misaligned address 0x60f0000000d4 for type 'struct osmo_prbs_state', which requires 8 byte alignment
0x60f0000000d4: note: pointer points here
  00 00 00 00 40 e9 ac 50  42 7f 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/core/prbs.c:57:24: runtime error: member access within misaligned address 0x60f0000000d4 for type 'struct osmo_prbs_state', which requires 8 byte alignment
0x60f0000000d4: note: pointer points here
  00 00 00 00 40 e9 ac 50  42 7f 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/core/prbs.c:57:16: runtime error: member access within misaligned address 0x60f0000000d4 for type 'struct osmo_prbs_state', which requires 8 byte alignment
0x60f0000000d4: note: pointer points here
  00 00 00 00 40 e9 ac 50  42 7f 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:196:21: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 02 00 00 00  d9 ec 9b e2 12 90 1d 80  23 35 59 8c 50 1d 80 5b  ad 3d 4b a0 1d 80 9b 69
              ^ 
../../../../src/libosmocore/src/codec/ecu_fr.c:257:17: runtime error: member access within misaligned address 0x60f0000000a4 for type 'struct fr_ecu_state', which requires 8 byte alignment
0x60f0000000a4: note: pointer points here
  01 00 00 00 02 00 00 00  d9 ec 9b e2 12 90 00 00  23 35 59 8c 50 00 00 5b  ad 3d 4b a0 00 00 9b 69
              ^ 
Actions #1

Updated by laforge 3 months ago

  • Assignee set to dexter

Assigning to dexter, I think he implemente the ECU stuff?

Actions #2

Updated by dexter 3 months ago

  • Status changed from New to In Progress
Actions #3

Updated by dexter 3 months ago

  • % Done changed from 0 to 10

This is indeed an interesting problem. I think the reason why we see this error is because the member data0 in struct osmo_ecu_state is already out of alignment. In ecu_fr_init.c we store struct fr_ecu_state at that location. So struct fr_ecu_state is also out of alignment.

What makes me wonder though is that that in our msgb implementation we do the same trick: We have a zero length _data0 member at the end of the struct msgb and then we simply allocate more memory and use _data0 to store all kinds of data, also structs and there was never an alignment problem. At the moment I do not see how struct osmo_ecu_state is different. Is _data0 in struct msgb aligned by chance?

https://gerrit.osmocom.org/c/libosmocore/+/35212 ecu: force alignment of member data in struct osmo_ecu_state [NEW]

Actions #4

Updated by laforge 3 months ago

On Mon, Dec 04, 2023 at 11:37:27AM +0000, dexter wrote:

What makes me wonder though is that that in our msgb implementation we do the same trick: We have a zero length _data0 member at the end of the struct msgb and then we simply allocate more memory and use _data0 to store all kinds of data, also structs and there was never an alignment problem. At the moment I do not see how struct osmo_ecu_state is different. Is _data0 in struct msgb aligned by chance?

this may be the case, given that the elements immediately ahead of it are pointers, which usually have the
"worst" (largest) alignment requirements of the given architecture.

In case it's not known: the 'pahole' tool can be used to look at how data structures are laid out in memory.

struct osmo_ecu_state {
enum osmo_ecu_codec        codec;                /*     0     4 */
uint8_t                    data[];               /*     4     0 */

/* size: 4, cachelines: 1, members: 2 */
/* last cacheline: 4 bytes */
};

vs:

struct msgb {
struct llist_head          list;                 /*     0    16 */
union {
void *             dst;                  /*    16     8 */
struct gsm_bts_trx * trx;                /*    16     8 */
};                                               /*    16     8 */
struct gsm_lchan *         lchan;                /*    24     8 */
unsigned char *            l1h;                  /*    32     8 */
unsigned char *            l2h;                  /*    40     8 */
unsigned char *            l3h;                  /*    48     8 */
unsigned char *            l4h;                  /*    56     8 */
/* --- cacheline 1 boundary (64 bytes) --- */
long unsigned int          cb[5];                /*    64    40 */
uint16_t                   data_len;             /*   104     2 */
uint16_t                   len;                  /*   106     2 */

/* XXX 4 bytes hole, try to pack */

unsigned char *            head;                 /*   112     8 */
unsigned char *            tail;                 /*   120     8 */
/* --- cacheline 2 boundary (128 bytes) --- */
unsigned char *            data;                 /*   128     8 */
unsigned char              _data[];              /*   136     0 */

/* size: 136, cachelines: 3, members: 14 */
/* sum members: 132, holes: 1, sum holes: 4 */
/* last cacheline: 8 bytes */
};
Actions #5

Updated by dexter 3 months ago

  • % Done changed from 10 to 50

Thanks for the hint. This explains why struct msgb is fine. We could do the same in struct osmo_ecu_state as well:

https://gerrit.osmocom.org/c/libosmocore/+/35212 ecu: force alignment of member data in struct osmo_ecu_state

Actions #6

Updated by dexter about 2 months ago

  • Status changed from In Progress to Resolved
  • % Done changed from 50 to 100
Actions

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)