Skip to content

Commit ce48029

Browse files
Ada-CDpevik
authored andcommitted
syscalls/sockioctl: Make buf a struct ifreq array
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, a char array, 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. Change buf from a char to a struct ifreq array, as it isn't used for anything else in this test. This guarantees that buff will be properly aligned. Reviewed-by: Li Wang <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]> Signed-off-by: Teo Couprie Diaz <[email protected]>
1 parent 301022b commit ce48029

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

testcases/kernel/syscalls/sockioctl/sockioctl01.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static struct ifreq ifr;
5252
static int sinlen;
5353
static int optval;
5454

55-
static char buf[8192];
55+
static struct ifreq buf[200];
5656

5757
static void setup(void);
5858
static void setup0(void);
@@ -218,7 +218,7 @@ static void setup2(void)
218218
s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
219219
tdat[testno].proto);
220220
ifc.ifc_len = sizeof(buf);
221-
ifc.ifc_buf = buf;
221+
ifc.ifc_buf = (char *)buf;
222222
}
223223

224224
static void setup3(void)

0 commit comments

Comments
 (0)