From owner-svn-src-head@FreeBSD.ORG Sun Oct 26 05:39:42 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D645C60C; Sun, 26 Oct 2014 05:39:42 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 C328FC3C; Sun, 26 Oct 2014 05:39:42 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9Q5dgGr081656; Sun, 26 Oct 2014 05:39:42 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9Q5dgQH081655; Sun, 26 Oct 2014 05:39:42 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201410260539.s9Q5dgQH081655@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sun, 26 Oct 2014 05:39:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273684 - 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-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Oct 2014 05:39:42 -0000 Author: mjg Date: Sun Oct 26 05:39:42 2014 New Revision: 273684 URL: https://svnweb.freebsd.org/changeset/base/273684 Log: Use a temporary buffer in sys_setgroups for requests with <= XU_NGROUPS groups. Submitted by: Tiwei Bie X-Additional: JuniorJobs project MFC after: 2 weeks Modified: head/sys/kern/kern_prot.c Modified: head/sys/kern/kern_prot.c ============================================================================== --- head/sys/kern/kern_prot.c Sun Oct 26 04:44:28 2014 (r273683) +++ head/sys/kern/kern_prot.c Sun Oct 26 05:39:42 2014 (r273684) @@ -806,17 +806,24 @@ int sys_setgroups(struct thread *td, struct setgroups_args *uap) { gid_t *groups = NULL; + gid_t smallgroups[XU_NGROUPS]; + u_int gidsetsize; int error; - if (uap->gidsetsize > ngroups_max + 1) + gidsetsize = uap->gidsetsize; + if (gidsetsize > ngroups_max + 1) return (EINVAL); - groups = malloc(uap->gidsetsize * sizeof(gid_t), M_TEMP, M_WAITOK); - error = copyin(uap->gidset, groups, uap->gidsetsize * sizeof(gid_t)); + if (gidsetsize > XU_NGROUPS) + groups = malloc(gidsetsize * sizeof(gid_t), M_TEMP, M_WAITOK); + else + groups = smallgroups; + error = copyin(uap->gidset, groups, gidsetsize * sizeof(gid_t)); if (error) goto out; - error = kern_setgroups(td, uap->gidsetsize, groups); + error = kern_setgroups(td, gidsetsize, groups); out: - free(groups, M_TEMP); + if (gidsetsize > XU_NGROUPS) + free(groups, M_TEMP); return (error); }