Skip to contentSkip to conversation

wait403: Reproduce undefined INT_MIN negation

PATCH Superseded Richard Palethorpe 3 participants 4 messages Jul 6, 2021 – Jul 7, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wait403: Reproduce undefined INT_MIN negation

---
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/wait4/.gitignore |  1 +
 testcases/kernel/syscalls/wait4/wait403.c  | 40 ++++++++++++++++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 testcases/kernel/syscalls/wait4/wait403.c
runtest/syscalls +1 -0
index 98fe3c02e..128eaadd2 100644
@@ -1663,6 +1663,7 @@ wait02 wait02
 
 wait401 wait401
 wait402 wait402
+wait403 wait403
 
 waitpid01 waitpid01
 waitpid02 waitpid02
testcases/kernel/syscalls/wait4/.gitignore +1 -0
index 9313eb72c..577f73479 100644
@@ -1,2 +1,3 @@
 /wait401
 /wait402
+/wait403
testcases/kernel/syscalls/wait4/wait403.c new file +40 -0
new file mode 100644
index 000000000..262351b7c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 SUSE LLC <[email protected]>
+ */
+
+/*
+ * [Description]
+ *
+ * Check wait4(INT_MIN, ...) is not allowed. The pid is negated before
+ * searching for a group with that pid. Negating INT_MIN is not
+ * defined so UBSAN will be triggered if enabled.
+ *
+ * If the bug is present, but UBSAN is not enabled, then it should
+ * result in ECHILD.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#define _USE_BSD
+#include <sys/types.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static void run(void)
+{
+	int status = 1;
+	struct rusage rusage;
+
+	TST_EXP_FAIL2(wait4(-2147483648, &status, 0, &rusage), ESRCH,
+		      "wait4 fails with ESRCH");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "dd83c161fbcc"},
+	}
+};
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/1 wait403: Reproduce undefined INT_MIN negation

Quoted 1 line · Richard Palethorpe
Quoted 61 lines
---
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/wait4/.gitignore |  1 +
 testcases/kernel/syscalls/wait4/wait403.c  | 40 ++++++++++++++++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 testcases/kernel/syscalls/wait4/wait403.c
runtest/syscalls +1 -0
index 98fe3c02e..128eaadd2 100644
@@ -1663,6 +1663,7 @@ wait02 wait02
 
 wait401 wait401
 wait402 wait402
+wait403 wait403
 
 waitpid01 waitpid01
 waitpid02 waitpid02
testcases/kernel/syscalls/wait4/.gitignore +1 -0
index 9313eb72c..577f73479 100644
@@ -1,2 +1,3 @@
 /wait401
 /wait402
+/wait403
testcases/kernel/syscalls/wait4/wait403.c new file +28 -0
new file mode 100644
index 000000000..262351b7c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 SUSE LLC <[email protected]>
+ */
+
+/*
+ * [Description]
+ *
+ * Check wait4(INT_MIN, ...) is not allowed. The pid is negated before
+ * searching for a group with that pid. Negating INT_MIN is not
+ * defined so UBSAN will be triggered if enabled.
+ *
+ * If the bug is present, but UBSAN is not enabled, then it should
+ * result in ECHILD.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#define _USE_BSD
+#include <sys/types.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static void run(void)
+{
+	int status = 1;
+	struct rusage rusage;

testcases/kernel/syscalls/wait4/wait403.c line 38

Quoted 10 lines
testcases/kernel/syscalls/wait4/wait403.c new file +10 -0
+
+	TST_EXP_FAIL2(wait4(-2147483648, &status, 0, &rusage), ESRCH,
+		      "wait4 fails with ESRCH");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "dd83c161fbcc"},

Possibly needs {}

Quoted 2 lines
testcases/kernel/syscalls/wait4/wait403.c new file +2 -0
+	}
+};
Signature · 2 lines
Thank you,
Richard.
#2 lore raw

PATCH 1/1 wait403: Reproduce undefined INT_MIN negation

In reply to Richard Palethorpe

Hi Richard,

Quoted 55 lines · Richard Palethorpe via ltp
---
  runtest/syscalls                           |  1 +
  testcases/kernel/syscalls/wait4/.gitignore |  1 +
  testcases/kernel/syscalls/wait4/wait403.c  | 40 ++++++++++++++++++++++
  3 files changed, 42 insertions(+)

create mode 100644 testcases/kernel/syscalls/wait4/wait403.c

runtest/syscalls +1 -0
index 98fe3c02e..128eaadd2 100644
@@ -1663,6 +1663,7 @@ wait02 wait02
 
  wait401 wait401
  wait402 wait402
+wait403 wait403
 
  waitpid01 waitpid01
  waitpid02 waitpid02
testcases/kernel/syscalls/wait4/.gitignore +1 -0
index 9313eb72c..577f73479 100644
@@ -1,2 +1,3 @@
  /wait401
  /wait402
+/wait403
testcases/kernel/syscalls/wait4/wait403.c new file +21 -0
new file mode 100644
index 000000000..262351b7c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 SUSE LLC <[email protected]>
+ */
+
+/*
+ * [Description]
+ *
+ * Check wait4(INT_MIN, ...) is not allowed. The pid is negated before
+ * searching for a group with that pid. Negating INT_MIN is not
+ * defined so UBSAN will be triggered if enabled.
+ *
+ * If the bug is present, but UBSAN is not enabled, then it should
+ * result in ECHILD.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#define _USE_BSD
+#include <sys/types.h>
+#include <sys/resource.h>

testcases/kernel/syscalls/wait4/wait403.c line 31

Quoted 10 lines
testcases/kernel/syscalls/wait4/wait403.c new file +10 -0
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static void run(void)
+{
+	int status = 1;
+	struct rusage rusage;
+
+	TST_EXP_FAIL2(wait4(-2147483648, &status, 0, &rusage), ESRCH,
+		      "wait4 fails with ESRCH");

Could this use INT_MIN instead of the literal value? If not a comment would be nice, especially because there is already wait4(INT_MIN, ...) in the description.

testcases/kernel/syscalls/wait4/wait403.c line 40

Quoted 9 lines
testcases/kernel/syscalls/wait4/wait403.c new file +9 -0
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "dd83c161fbcc"},
+	}
+};

Otherwise:

Joerg

#3 lore raw

PATCH 1/1 wait403: Reproduce undefined INT_MIN negation

Hello Joerg,

Quoted 61 lines · Joerg Vehlow

Hi Richard,

Quoted 58 lines · Richard Palethorpe via ltp
---
  runtest/syscalls                           |  1 +
  testcases/kernel/syscalls/wait4/.gitignore |  1 +
  testcases/kernel/syscalls/wait4/wait403.c  | 40 ++++++++++++++++++++++
  3 files changed, 42 insertions(+)

create mode 100644 testcases/kernel/syscalls/wait4/wait403.c

runtest/syscalls +1 -0
index 98fe3c02e..128eaadd2 100644
@@ -1663,6 +1663,7 @@ wait02 wait02
    wait401 wait401
  wait402 wait402
+wait403 wait403
    waitpid01 waitpid01
  waitpid02 waitpid02
testcases/kernel/syscalls/wait4/.gitignore +1 -0
index 9313eb72c..577f73479 100644
@@ -1,2 +1,3 @@
  /wait401
  /wait402
+/wait403
testcases/kernel/syscalls/wait4/wait403.c new file +26 -0
new file mode 100644
index 000000000..262351b7c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 SUSE LLC <[email protected]>
+ */
+
+/*
+ * [Description]
+ *
+ * Check wait4(INT_MIN, ...) is not allowed. The pid is negated before
+ * searching for a group with that pid. Negating INT_MIN is not
+ * defined so UBSAN will be triggered if enabled.
+ *
+ * If the bug is present, but UBSAN is not enabled, then it should
+ * result in ECHILD.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#define _USE_BSD
+#include <sys/types.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static void run(void)
+{
Quoted 8 lines

testcases/kernel/syscalls/wait4/wait403.c line 31

Quoted 5 lines
testcases/kernel/syscalls/wait4/wait403.c new file +5 -0
+	int status = 1;
+	struct rusage rusage;
+
+	TST_EXP_FAIL2(wait4(-2147483648, &status, 0, &rusage), ESRCH,
+		      "wait4 fails with ESRCH");

Could this use INT_MIN instead of the literal value? If not a comment would be nice, especially because there is already wait4(INT_MIN, ...) in the description.

OK, I will roll another patch.

Quoted 12 lines

testcases/kernel/syscalls/wait4/wait403.c line 40

Quoted 9 lines
testcases/kernel/syscalls/wait4/wait403.c new file +9 -0
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "dd83c161fbcc"},
+	}
+};

Otherwise:

Quoted 1 line

Thanks.

Quoted 3 lines

Joerg

Signature · 2 lines
Thank you,
Richard.