|
 |
0b26f7 |
commit 7c987a5ccb31df80456d53a094e47f81310f549b
|
|
 |
0b26f7 |
Author: Nikita Popov <npv1310@gmail.com>
|
|
 |
0b26f7 |
Date: Thu Aug 12 16:09:50 2021 +0530
|
|
 |
0b26f7 |
|
|
 |
0b26f7 |
librt: add test (bug 28213)
|
|
 |
0b26f7 |
|
|
 |
0b26f7 |
This test implements following logic:
|
|
 |
0b26f7 |
1) Create POSIX message queue.
|
|
 |
0b26f7 |
Register a notification with mq_notify (using NULL attributes).
|
|
 |
0b26f7 |
Then immediately unregister the notification with mq_notify.
|
|
 |
0b26f7 |
Helper thread in a vulnerable version of glibc
|
|
 |
0b26f7 |
should cause NULL pointer dereference after these steps.
|
|
 |
0b26f7 |
2) Once again, register the same notification.
|
|
 |
0b26f7 |
Try to send a dummy message.
|
|
 |
0b26f7 |
Test is considered successfulif the dummy message
|
|
 |
0b26f7 |
is successfully received by the callback function.
|
|
 |
0b26f7 |
|
|
 |
0b26f7 |
Signed-off-by: Nikita Popov <npv1310@gmail.com>
|
|
 |
0b26f7 |
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
|
 |
0b26f7 |
(cherry picked from commit 4cc79c217744743077bf7a0ec5e0a4318f1e6641)
|
|
 |
0b26f7 |
|
|
 |
0b26f7 |
diff --git a/rt/Makefile b/rt/Makefile
|
|
 |
0b26f7 |
index 113cea03a5b75613..910e7759956d7ae9 100644
|
|
 |
0b26f7 |
--- a/rt/Makefile
|
|
 |
0b26f7 |
+++ b/rt/Makefile
|
|
 |
0b26f7 |
@@ -74,6 +74,7 @@ tests := tst-shm tst-timer tst-timer2 \
|
|
 |
0b26f7 |
tst-aio7 tst-aio8 tst-aio9 tst-aio10 \
|
|
 |
0b26f7 |
tst-mqueue1 tst-mqueue2 tst-mqueue3 tst-mqueue4 \
|
|
 |
0b26f7 |
tst-mqueue5 tst-mqueue6 tst-mqueue7 tst-mqueue8 tst-mqueue9 \
|
|
 |
0b26f7 |
+ tst-bz28213 \
|
|
 |
0b26f7 |
tst-timer3 tst-timer4 tst-timer5 \
|
|
 |
0b26f7 |
tst-cpuclock2 tst-cputimer1 tst-cputimer2 tst-cputimer3 \
|
|
 |
0b26f7 |
tst-shm-cancel \
|
|
 |
0b26f7 |
diff --git a/rt/tst-bz28213.c b/rt/tst-bz28213.c
|
|
 |
0b26f7 |
new file mode 100644
|
|
 |
0b26f7 |
index 0000000000000000..0c096b5a0ad4170a
|
|
 |
0b26f7 |
--- /dev/null
|
|
 |
0b26f7 |
+++ b/rt/tst-bz28213.c
|
|
 |
0b26f7 |
@@ -0,0 +1,101 @@
|
|
 |
0b26f7 |
+/* Bug 28213: test for NULL pointer dereference in mq_notify.
|
|
 |
0b26f7 |
+ Copyright (C) The GNU Toolchain Authors.
|
|
 |
0b26f7 |
+ This file is part of the GNU C Library.
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
 |
0b26f7 |
+ modify it under the terms of the GNU Lesser General Public
|
|
 |
0b26f7 |
+ License as published by the Free Software Foundation; either
|
|
 |
0b26f7 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
 |
0b26f7 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
 |
0b26f7 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
 |
0b26f7 |
+ Lesser General Public License for more details.
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ You should have received a copy of the GNU Lesser General Public
|
|
 |
0b26f7 |
+ License along with the GNU C Library; if not, see
|
|
 |
0b26f7 |
+ <https://www.gnu.org/licenses/>. */
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+#include <errno.h>
|
|
 |
0b26f7 |
+#include <sys/types.h>
|
|
 |
0b26f7 |
+#include <sys/stat.h>
|
|
 |
0b26f7 |
+#include <fcntl.h>
|
|
 |
0b26f7 |
+#include <unistd.h>
|
|
 |
0b26f7 |
+#include <mqueue.h>
|
|
 |
0b26f7 |
+#include <signal.h>
|
|
 |
0b26f7 |
+#include <stdlib.h>
|
|
 |
0b26f7 |
+#include <string.h>
|
|
 |
0b26f7 |
+#include <support/check.h>
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+static mqd_t m = -1;
|
|
 |
0b26f7 |
+static const char msg[] = "hello";
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+static void
|
|
 |
0b26f7 |
+check_bz28213_cb (union sigval sv)
|
|
 |
0b26f7 |
+{
|
|
 |
0b26f7 |
+ char buf[sizeof (msg)];
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ (void) sv;
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ TEST_VERIFY_EXIT ((size_t) mq_receive (m, buf, sizeof (buf), NULL)
|
|
 |
0b26f7 |
+ == sizeof (buf));
|
|
 |
0b26f7 |
+ TEST_VERIFY_EXIT (memcmp (buf, msg, sizeof (buf)) == 0);
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ exit (0);
|
|
 |
0b26f7 |
+}
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+static void
|
|
 |
0b26f7 |
+check_bz28213 (void)
|
|
 |
0b26f7 |
+{
|
|
 |
0b26f7 |
+ struct sigevent sev;
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ memset (&sev, '\0', sizeof (sev));
|
|
 |
0b26f7 |
+ sev.sigev_notify = SIGEV_THREAD;
|
|
 |
0b26f7 |
+ sev.sigev_notify_function = check_bz28213_cb;
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ /* Step 1: Register & unregister notifier.
|
|
 |
0b26f7 |
+ Helper thread should receive NOTIFY_REMOVED notification.
|
|
 |
0b26f7 |
+ In a vulnerable version of glibc, NULL pointer dereference follows. */
|
|
 |
0b26f7 |
+ TEST_VERIFY_EXIT (mq_notify (m, &sev) == 0);
|
|
 |
0b26f7 |
+ TEST_VERIFY_EXIT (mq_notify (m, NULL) == 0);
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ /* Step 2: Once again, register notification.
|
|
 |
0b26f7 |
+ Try to send one message.
|
|
 |
0b26f7 |
+ Test is considered successful, if the callback does exit (0). */
|
|
 |
0b26f7 |
+ TEST_VERIFY_EXIT (mq_notify (m, &sev) == 0);
|
|
 |
0b26f7 |
+ TEST_VERIFY_EXIT (mq_send (m, msg, sizeof (msg), 1) == 0);
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ /* Wait... */
|
|
 |
0b26f7 |
+ pause ();
|
|
 |
0b26f7 |
+}
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+static int
|
|
 |
0b26f7 |
+do_test (void)
|
|
 |
0b26f7 |
+{
|
|
 |
0b26f7 |
+ static const char m_name[] = "/bz28213_queue";
|
|
 |
0b26f7 |
+ struct mq_attr m_attr;
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ memset (&m_attr, '\0', sizeof (m_attr));
|
|
 |
0b26f7 |
+ m_attr.mq_maxmsg = 1;
|
|
 |
0b26f7 |
+ m_attr.mq_msgsize = sizeof (msg);
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ m = mq_open (m_name,
|
|
 |
0b26f7 |
+ O_RDWR | O_CREAT | O_EXCL,
|
|
 |
0b26f7 |
+ 0600,
|
|
 |
0b26f7 |
+ &m_attr);
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ if (m < 0)
|
|
 |
0b26f7 |
+ {
|
|
 |
0b26f7 |
+ if (errno == ENOSYS)
|
|
 |
0b26f7 |
+ FAIL_UNSUPPORTED ("POSIX message queues are not implemented\n");
|
|
 |
0b26f7 |
+ FAIL_EXIT1 ("Failed to create POSIX message queue: %m\n");
|
|
 |
0b26f7 |
+ }
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ TEST_VERIFY_EXIT (mq_unlink (m_name) == 0);
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ check_bz28213 ();
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+ return 0;
|
|
 |
0b26f7 |
+}
|
|
 |
0b26f7 |
+
|
|
 |
0b26f7 |
+#include <support/test-driver.c>
|