From 32a1fb0d3d0d193d9f8c618d4464d472e894318c Mon Sep 17 00:00:00 2001 From: Mahdi Mokhtari Date: Fri, 10 Mar 2017 10:09:44 +0000 Subject: [PATCH] Fix NULL pointer dereference and panic with shm file pread/pwrite. PR: 217429 Reported by: Tim Newsham Reviewed by: kib Approved by: dchagin MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D9844 --- sys/kern/sys_generic.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index e9a622c7c8e8..3a96d909bb60 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -334,7 +334,8 @@ kern_preadv(td, fd, auio, offset) return (error); if (!(fp->f_ops->fo_flags & DFLAG_SEEKABLE)) error = ESPIPE; - else if (offset < 0 && fp->f_vnode->v_type != VCHR) + else if (offset < 0 && + (fp->f_vnode == NULL || fp->f_vnode->v_type != VCHR)) error = EINVAL; else error = dofileread(td, fd, fp, auio, offset, FOF_OFFSET); @@ -548,7 +549,8 @@ kern_pwritev(td, fd, auio, offset) return (error); if (!(fp->f_ops->fo_flags & DFLAG_SEEKABLE)) error = ESPIPE; - else if (offset < 0 && fp->f_vnode->v_type != VCHR) + else if (offset < 0 && + (fp->f_vnode == NULL || fp->f_vnode->v_type != VCHR)) error = EINVAL; else error = dofilewrite(td, fd, fp, auio, offset, FOF_OFFSET);