Skip to content

Commit

Permalink
syscalls/sockioctl: Align buffer to struct ifreq
Browse files Browse the repository at this point in the history
In setup3, the following line can lead to an undefined behavior:
  ifr = *(struct ifreq *)ifc.ifc_buf;

Indeed, at this point it can be assumed that ifc.ifc_buf is suitably
aligned for struct ifreq.
However, ifc.ifc_buf is assigned to buf which has no alignment
constraints. This means there exists cases where buf is not suitably
aligned to load a struct ifreq, which can generate a SIGBUS.

Force the alignment of buf to that of struct ifreq.

Signed-off-by: Teo Couprie Diaz <teo.coupriediaz@arm.com>
  • Loading branch information
Teo-CD committed Mar 23, 2023
1 parent d0bd0e0 commit f890655
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion testcases/kernel/syscalls/sockioctl/sockioctl01.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ static struct ifreq ifr;
static int sinlen;
static int optval;

static char buf[8192];
/*
* buf has no alignment constraints by default. However, it is used to load
* a struct ifreq in setup3, which requires it to have an appropriate alignment
* to prevent a possible undefined behavior.
*/
static char buf[8192]
__attribute__((aligned(__alignof__(struct ifreq))));

static void setup(void);
static void setup0(void);
Expand Down

0 comments on commit f890655

Please sign in to comment.