Message ID | 20230327110234.266785-1-teo.coupriediaz@arm.com |
---|---|
State | Accepted |
Headers | show |
Series | [v2] syscalls/sockioctl: Make buf a struct ifreq array | expand |
LGTM.
Reviewed-by: Li Wang <liwang@redhat.com>
Hi all,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Hi all, thanks, merged! Kind regards, Petr
diff --git a/testcases/kernel/syscalls/sockioctl/sockioctl01.c b/testcases/kernel/syscalls/sockioctl/sockioctl01.c index 51dac9c16309..ff3738f327ef 100644 --- a/testcases/kernel/syscalls/sockioctl/sockioctl01.c +++ b/testcases/kernel/syscalls/sockioctl/sockioctl01.c @@ -52,7 +52,7 @@ static struct ifreq ifr; static int sinlen; static int optval; -static char buf[8192]; +static struct ifreq buf[200]; static void setup(void); static void setup0(void); @@ -218,7 +218,7 @@ static void setup2(void) s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type, tdat[testno].proto); ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = buf; + ifc.ifc_buf = (char *)buf; } static void setup3(void)
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. Signed-off-by: Teo Couprie Diaz <teo.coupriediaz@arm.com> --- I changed the cast from Cyril suggestion from (void*) to (char*) just to be consistent with the type of (struct ifconf).ifc_buf. From my understanding this should be equivalent. v2: - As per Cyril comments, make buf a struct ifreq array rather than align it with __attribute__ - Update commit message accordingly CI Build: https://github.com/Teo-CD/ltp/actions/runs/4531482995 testcases/kernel/syscalls/sockioctl/sockioctl01.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)