git: 2f4dbe279f6b - main - kqueue: fix recent assertion

Kyle Evans kevans at FreeBSD.org
Fri Oct 1 18:17:53 UTC 2021


The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=2f4dbe279f6b5eb87ec493d96f6943ffdb603ba0

commit 2f4dbe279f6b5eb87ec493d96f6943ffdb603ba0
Author:     Kyle Evans <kevans at FreeBSD.org>
AuthorDate: 2021-10-01 16:59:31 +0000
Commit:     Kyle Evans <kevans at FreeBSD.org>
CommitDate: 2021-10-01 18:17:30 +0000

    kqueue: fix recent assertion
    
    NOTE_ABSTIME may also have a zero timeout, which indicates that we
    should still fire immediately as an absolute time in the past.  A test
    has been added for this one as well.
    
    Fixes:  9c999a259f00 ("kqueue: don't arbitrarily restrict long-past...")
    Point hat:      kevans
    Reported by:    syzbot+1c8d1154f560b3930042 at syzkaller.appspotmail.com
---
 sys/kern/kern_event.c              |  3 ++-
 tests/sys/kqueue/libkqueue/timer.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index 3cd7753d4f6d..c9b50912a22d 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -819,7 +819,8 @@ filt_timerattach(struct knote *kn)
 	error = filt_timervalidate(kn, &to);
 	if (error != 0)
 		return (error);
-	KASSERT((kn->kn_flags & EV_ONESHOT) != 0 || to > 0,
+	KASSERT(to > 0 || (kn->kn_flags & EV_ONESHOT) != 0 ||
+	    (kn->kn_sfflags & NOTE_ABSTIME) != 0,
 	    ("%s: periodic timer has a calculated zero timeout", __func__));
 	KASSERT(to >= 0,
 	    ("%s: timer has a calculated negative timeout", __func__));
diff --git a/tests/sys/kqueue/libkqueue/timer.c b/tests/sys/kqueue/libkqueue/timer.c
index 76dfc99e11f0..330c22c62bc5 100644
--- a/tests/sys/kqueue/libkqueue/timer.c
+++ b/tests/sys/kqueue/libkqueue/timer.c
@@ -247,6 +247,35 @@ test_abstime(void)
     success();
 }
 
+static void
+test_abstime_epoch(void)
+{
+    const char *test_id = "kevent(EVFILT_TIMER (EPOCH), NOTE_ABSTIME)";
+    struct kevent kev;
+
+    test_begin(test_id);
+
+    test_no_kevents();
+
+    EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD, NOTE_ABSTIME, 0,
+        NULL);
+    if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
+        err(1, "%s", test_id);
+
+    /* Retrieve the event */
+    kev.flags = EV_ADD;
+    kev.data = 1;
+    kev.fflags = 0;
+    kevent_cmp(&kev, kevent_get(kqfd));
+
+    /* Delete the event */
+    kev.flags = EV_DELETE;
+    if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
+        err(1, "%s", test_id);
+
+    success();
+}
+
 static void
 test_abstime_preboot(void)
 {
@@ -599,6 +628,7 @@ test_evfilt_timer(void)
     test_oneshot();
     test_periodic();
     test_abstime();
+    test_abstime_epoch();
     test_abstime_preboot();
     test_abstime_postboot();
     test_update();


More information about the dev-commits-src-all mailing list