From owner-svn-src-all@freebsd.org Mon Nov 14 13:20:11 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 93077C3DE6F; Mon, 14 Nov 2016 13:20:11 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 601C19B; Mon, 14 Nov 2016 13:20:11 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAEDKAeD089936; Mon, 14 Nov 2016 13:20:10 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAEDKAYN089935; Mon, 14 Nov 2016 13:20:10 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201611141320.uAEDKAYN089935@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 14 Nov 2016 13:20:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r308642 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Nov 2016 13:20:11 -0000 Author: kib Date: Mon Nov 14 13:20:10 2016 New Revision: 308642 URL: https://svnweb.freebsd.org/changeset/base/308642 Log: Initialize reserved bytes in struct mq_attr and its 32compat counterpart, to avoid kernel stack content leak in kmq_setattr(2) syscall. Also slightly simplify the checks around copyout()s. Reported by: Vlad Tsyrklevich PR: 214488 MFC after: 1 week Modified: head/sys/kern/uipc_mqueue.c Modified: head/sys/kern/uipc_mqueue.c ============================================================================== --- head/sys/kern/uipc_mqueue.c Mon Nov 14 12:56:18 2016 (r308641) +++ head/sys/kern/uipc_mqueue.c Mon Nov 14 13:20:10 2016 (r308642) @@ -2242,10 +2242,10 @@ sys_kmq_setattr(struct thread *td, struc } error = kern_kmq_setattr(td, uap->mqd, uap->attr != NULL ? &attr : NULL, &oattr); - if (error != 0) - return (error); - if (uap->oattr != NULL) + if (error == 0 && uap->oattr != NULL) { + bzero(oattr.__reserved, sizeof(oattr.__reserved)); error = copyout(&oattr, uap->oattr, sizeof(oattr)); + } return (error); } @@ -2759,10 +2759,9 @@ freebsd32_kmq_setattr(struct thread *td, } error = kern_kmq_setattr(td, uap->mqd, uap->attr != NULL ? &attr : NULL, &oattr); - if (error != 0) - return (error); - if (uap->oattr != NULL) { + if (error == 0 && uap->oattr != NULL) { mq_attr_to32(&oattr, &oattr32); + bzero(oattr32.__reserved, sizeof(oattr32.__reserved)); error = copyout(&oattr32, uap->oattr, sizeof(oattr32)); } return (error);