From nobody@FreeBSD.org Mon Jun 23 15:41:06 2008 Return-Path: Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DD04A10656C6 for ; Mon, 23 Jun 2008 15:41:06 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id C71038FC3F for ; Mon, 23 Jun 2008 15:41:06 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m5NFf6ck016285 for ; Mon, 23 Jun 2008 15:41:06 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.2/8.14.1/Submit) id m5NFf60j016284; Mon, 23 Jun 2008 15:41:06 GMT (envelope-from nobody) Message-Id: <200806231541.m5NFf60j016284@www.freebsd.org> Date: Mon, 23 Jun 2008 15:41:06 GMT From: Taylor R Campbell To: freebsd-gnats-submit@FreeBSD.org Subject: kernel performs inadequate check for incorrect lengths when sending file descriptors over sockets X-Send-Pr-Version: www-3.1 X-GNATS-Notify: >Number: 124908 >Category: kern >Synopsis: [socket] kernel performs inadequate check for incorrect lengths when sending file descriptors over sockets >Confidential: no >Severity: serious >Priority: medium >Responsible: rwatson >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Jun 23 15:50:00 UTC 2008 >Closed-Date: >Last-Modified: Sun Jul 06 09:03:55 UTC 2008 >Originator: Taylor R Campbell >Release: >Organization: >Environment: I have no FreeBSD machine of my own, but someone kindly offered to run a test program on a machine with the following uname -a output: FreeBSD dns.deafhogs.org 7.0-RELEASE-p2 FreeBSD 7.0-RELEASE-p2 #1: Thu Jun 19 06:47:36 EDT 2008 chaulmark@nfs.deafhogs.org:/usr/obj/usr/src/sys/GENERIC i386 >Description: In src/kern/sys/uipc_usrreq.c (rev 1.214), the function unp_internalize does not adequately check that the lengths in control message headers are correct, and as a consequence may calculate a negative number of file descriptors in the user-supplied buffer, leading potentially to disaster later on. (Thanks to Michael van Elst and Martin Husemann for alerting me to this issue in NetBSD.) >How-To-Repeat: Download the program Compile it with gcc -DFAIL -g -Wall fbsd-fail.c -o fbsd-fail Run it with ./fbsd-fail foobar sendmsg(2) should return EINVAL, but it doesn't; instead it has random effects, such as returning EBADF, which suggests that the kernel might be examining and passing to other processes file descriptors that the user did not request. >Fix: Add the following test to the list of conditions in unp_internalize for which it will return EINVAL: cm->cmsg_len < CMSG_ALIGN(sizeof(struct cmsghdr)) >Release-Note: >Audit-Trail: Responsible-Changed-From-To: freebsd-bugs->rwatson Responsible-Changed-By: rwatson Responsible-Changed-When: Tue Jun 24 13:11:20 UTC 2008 Responsible-Changed-Why: Take ownership of this PR since I've spent some time with this code. http://www.freebsd.org/cgi/query-pr.cgi?pr=124908 >Unformatted: