From owner-freebsd-bugs@FreeBSD.ORG Mon Jun 23 15:50:01 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E270106566B for ; Mon, 23 Jun 2008 15:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 5686E8FC1D for ; Mon, 23 Jun 2008 15:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m5NFo1Q2015159 for ; Mon, 23 Jun 2008 15:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m5NFo1bK015158; Mon, 23 Jun 2008 15:50:01 GMT (envelope-from gnats) Resent-Date: Mon, 23 Jun 2008 15:50:01 GMT Resent-Message-Id: <200806231550.m5NFo1bK015158@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Taylor R Campbell 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 X-Send-Pr-Version: www-3.1 Cc: Subject: kern/124908: kernel performs inadequate check for incorrect lengths when sending file descriptors over sockets X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jun 2008 15:50:01 -0000 >Number: 124908 >Category: kern >Synopsis: kernel performs inadequate check for incorrect lengths when sending file descriptors over sockets >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >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: >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: >Unformatted: