Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern sendmsg(2): Avoid buffer overrun in ktrace of inval...



details:   https://anonhg.NetBSD.org/src/rev/a277c82f362d
branches:  trunk
changeset: 368186:a277c82f362d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Jun 27 04:06:48 2022 +0000

description:
sendmsg(2): Avoid buffer overrun in ktrace of invalid cmsghdr.

Reported-by: syzbot+efded148140b23425f5c%syzkaller.appspotmail.com@localhost

diffstat:

 sys/kern/uipc_syscalls.c |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (29 lines):

diff -r 11f71fe3b0ff -r a277c82f362d sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c  Mon Jun 27 03:56:37 2022 +0000
+++ b/sys/kern/uipc_syscalls.c  Mon Jun 27 04:06:48 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_syscalls.c,v 1.202 2021/10/02 17:37:21 thorpej Exp $      */
+/*     $NetBSD: uipc_syscalls.c,v 1.203 2022/06/27 04:06:48 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.202 2021/10/02 17:37:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.203 2022/06/27 04:06:48 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pipe.h"
@@ -1627,6 +1627,10 @@
                mhdr.msg_controllen = buflen;
                for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&mhdr); cmsg;
                    cmsg = CMSG_NXTHDR(&mhdr, cmsg)) {
+                       KASSERT(((char *)cmsg - mtod(m, char *)) <= buflen);
+                       if (cmsg->cmsg_len >
+                           buflen - ((char *)cmsg - mtod(m, char *)))
+                               break;
                        ktrkuser(mbuftypes[type], cmsg, cmsg->cmsg_len);
                }
                return 0;



Home | Main Index | Thread Index | Old Index