Bug 128304 - vn_pollrecord(3) derefs NULL if v_addpollinfo() fails
Summary: vn_pollrecord(3) derefs NULL if v_addpollinfo() fails
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 7.0-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-22 23:50 UTC by Doug White
Modified: 2018-01-03 05:16 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Doug White freebsd_committer freebsd_triage 2008-10-22 23:50:00 UTC
The first few lines of vn_pollrecord() are:

	if (vp->v_pollinfo == NULL)
		v_addpollinfo(vp);
	mtx_lock(&vp->v_pollinfo->vpi_lock);

v_addpollinfo() leaves vp->v_pollinfo NULL if the malloc attempt fails. vfs_kqfilter() checks for failure, but this function does not.  If allocation were to fail then the mtx_lock() call would result in a null pointer dereference panic.

Fix: 

vn_pollrecord() should ensure v_addpollinfo() succeeds in allocating the pollinfo lists. However vn_pollrecord() uses its return value to convey the original event mask so there does not appear to be a method to return an error value (ENOMEM, etc.) in the current implementation.
How-To-Repeat: Problem was found by code inspection.
Comment 1 Mateusz Guzik 2008-10-23 12:57:43 UTC
Hi.

failure of uma_zalloc() would cause null pointer dereference in
v_addpollinfo() anyway (due to mtx_init() call).

From commit message for rev 1.142 of sys/vm/uma_core.c:

Remove uma_zalloc_arg() hack, which coerced M_WAITOK to M_NOWAIT when
allocations were made using improper flags in interrupt context.
Replace with a simple WITNESS warning call.  This restores the
invariant that M_WAITOK allocations will always succeed or die
horribly trying, which is relied on by many UMA consumers.

So it's ok to rely on M_WAITOK (which v_addpollinfo() does) and additional
null check in vfs_kqfilter() can be removed as being meaningles.

Thanks,
--
Mateusz Guzik
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:01:20 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped