Module Name: src Committed By: riastradh Date: Tue Jun 28 11:41:32 UTC 2022
Modified Files: src/sys/kern: uipc_syscalls.c Log Message: recvmmsg(2): Avoid arithmetic overflow in timeout calculations. XXX This is not right -- it doesn't actually do anything to time out... Reported-by: syzbot+784209d76a94fcc64...@syzkaller.appspotmail.com To generate a diff of this commit: cvs rdiff -u -r1.203 -r1.204 src/sys/kern/uipc_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/uipc_syscalls.c diff -u src/sys/kern/uipc_syscalls.c:1.203 src/sys/kern/uipc_syscalls.c:1.204 --- src/sys/kern/uipc_syscalls.c:1.203 Mon Jun 27 04:06:48 2022 +++ src/sys/kern/uipc_syscalls.c Tue Jun 28 11:41:32 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.203 2022/06/27 04:06:48 riastradh Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.204 2022/06/28 11:41:32 riastradh Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.203 2022/06/27 04:06:48 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.204 2022/06/28 11:41:32 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_pipe.h" @@ -1042,7 +1042,12 @@ sys_recvmmsg(struct lwp *l, const struct if ((error = copyin(SCARG(uap, timeout), &ts, sizeof(ts))) != 0) return error; getnanotime(&now); - timespecadd(&now, &ts, &ts); + if (timespecaddok(&now, &ts)) { + timespecadd(&now, &ts, &ts); + } else { + ts.tv_sec = __type_max(time_t); + ts.tv_nsec = 999999999L; + } } s = SCARG(uap, s); @@ -1109,8 +1114,7 @@ sys_recvmmsg(struct lwp *l, const struct if (SCARG(uap, timeout)) { getnanotime(&now); - timespecsub(&now, &ts, &now); - if (now.tv_sec > 0) + if (timespeccmp(&ts, &now, <)) break; }