Skip to contentSkip to conversation

semctl09: Fix heap smash

PATCH New Martin Doucha 2 participants 2 messages Jan 15, 2021 – Jan 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 semctl09: Fix heap smash

semctl() expects pointer to a buffer as its fourth argument, not pointer to a pointer. Passing &un.buf results in heap smash that corrupts internal LTP data structures on some archs.

---
 testcases/kernel/syscalls/ipc/semctl/semctl09.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ipc/semctl/semctl09.c +6 -2
index 131bfbc07..d36ba62e5 100644
@@ -51,11 +51,15 @@ static union semun un;
  */
 static inline int do_semctl(int semid, int semnum, int cmd)
 {
+	struct semid_ds info;
+
+	un.buf = &info;
+
 	switch (tst_variant) {
 	case 0:
-		return tst_syscall(__NR_semctl, semid, semnum, cmd, &un.buf);
+		return tst_syscall(__NR_semctl, semid, semnum, cmd, un);
 	case 1:
-		return semctl(semid, semnum, cmd, &un.buf);
+		return semctl(semid, semnum, cmd, un);
 	}
 	return -1;
 }
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/1 semctl09: Fix heap smash

Hi Martin
LGTM, pushed. Thanks.

Best Regards
Yang Xu

Quoted 32 lines

semctl() expects pointer to a buffer as its fourth argument, not pointer to a pointer. Passing&un.buf results in heap smash that corrupts internal LTP data structures on some archs.

---
  testcases/kernel/syscalls/ipc/semctl/semctl09.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ipc/semctl/semctl09.c +6 -2
index 131bfbc07..d36ba62e5 100644
@@ -51,11 +51,15 @@ static union semun un;
   */
  static inline int do_semctl(int semid, int semnum, int cmd)
  {
+	struct semid_ds info;
+
+	un.buf =&info;
+
  	switch (tst_variant) {
  	case 0:
-		return tst_syscall(__NR_semctl, semid, semnum, cmd,&un.buf);
+		return tst_syscall(__NR_semctl, semid, semnum, cmd, un);
  	case 1:
-		return semctl(semid, semnum, cmd,&un.buf);
+		return semctl(semid, semnum, cmd, un);
  	}
  	return -1;
  }