ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] syscalls/sockioctl: Make buf a struct ifreq array
@ 2023-03-27 11:02 Teo Couprie Diaz
  2023-03-28  2:50 ` Li Wang
  2023-05-12 11:48 ` Cyril Hrubis
  0 siblings, 2 replies; 5+ messages in thread
From: Teo Couprie Diaz @ 2023-03-27 11:02 UTC (permalink / raw)
  To: ltp

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(-)

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)
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v2] syscalls/sockioctl: Make buf a struct ifreq array
  2023-03-27 11:02 [LTP] [PATCH v2] syscalls/sockioctl: Make buf a struct ifreq array Teo Couprie Diaz
@ 2023-03-28  2:50 ` Li Wang
  2023-05-05 16:57   ` Petr Vorel
  2023-05-12 11:48 ` Cyril Hrubis
  1 sibling, 1 reply; 5+ messages in thread
From: Li Wang @ 2023-03-28  2:50 UTC (permalink / raw)
  To: Teo Couprie Diaz; +Cc: ltp

LGTM.

Reviewed-by: Li Wang <liwang@redhat.com>


-- 
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v2] syscalls/sockioctl: Make buf a struct ifreq array
  2023-03-28  2:50 ` Li Wang
@ 2023-05-05 16:57   ` Petr Vorel
  0 siblings, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2023-05-05 16:57 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

Hi all,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v2] syscalls/sockioctl: Make buf a struct ifreq array
  2023-03-27 11:02 [LTP] [PATCH v2] syscalls/sockioctl: Make buf a struct ifreq array Teo Couprie Diaz
  2023-03-28  2:50 ` Li Wang
@ 2023-05-12 11:48 ` Cyril Hrubis
  2023-05-12 12:25   ` Petr Vorel
  1 sibling, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2023-05-12 11:48 UTC (permalink / raw)
  To: Teo Couprie Diaz; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v2] syscalls/sockioctl: Make buf a struct ifreq array
  2023-05-12 11:48 ` Cyril Hrubis
@ 2023-05-12 12:25   ` Petr Vorel
  0 siblings, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2023-05-12 12:25 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi all,

thanks, merged!

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-12 12:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-27 11:02 [LTP] [PATCH v2] syscalls/sockioctl: Make buf a struct ifreq array Teo Couprie Diaz
2023-03-28  2:50 ` Li Wang
2023-05-05 16:57   ` Petr Vorel
2023-05-12 11:48 ` Cyril Hrubis
2023-05-12 12:25   ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).