From owner-svn-src-stable-9@FreeBSD.ORG Fri Jan 13 00:38:36 2012 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6818D1065687; Fri, 13 Jan 2012 00:38:36 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4B9418FC22; Fri, 13 Jan 2012 00:38:36 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q0D0calH033723; Fri, 13 Jan 2012 00:38:36 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q0D0caJs033721; Fri, 13 Jan 2012 00:38:36 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201201130038.q0D0caJs033721@svn.freebsd.org> From: Eitan Adler Date: Fri, 13 Jan 2012 00:38:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r230039 - stable/9/sys/kern X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jan 2012 00:38:36 -0000 Author: eadler (ports committer) Date: Fri Jan 13 00:38:35 2012 New Revision: 230039 URL: http://svn.freebsd.org/changeset/base/230039 Log: MFC r228470: - Add a sysctl to allow non-root users the ability to set idle priorities. - While here fix up some style nits. Approved by: jhb Modified: stable/9/sys/kern/kern_resource.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/kern_resource.c ============================================================================== --- stable/9/sys/kern/kern_resource.c Fri Jan 13 00:38:00 2012 (r230038) +++ stable/9/sys/kern/kern_resource.c Fri Jan 13 00:38:35 2012 (r230039) @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -273,6 +274,10 @@ donice(struct thread *td, struct proc *p return (0); } +static int unprivileged_idprio; +SYSCTL_INT(_security_bsd, OID_AUTO, unprivileged_idprio, CTLFLAG_RW, + &unprivileged_idprio, 0, "Allow non-root users to set an idle priority"); + /* * Set realtime priority for LWP. */ @@ -321,18 +326,26 @@ sys_rtprio_thread(struct thread *td, str break; /* Disallow setting rtprio in most cases if not superuser. */ -/* - * Realtime priority has to be restricted for reasons which should be - * obvious. However, for idle priority, there is a potential for - * system deadlock if an idleprio process gains a lock on a resource - * that other processes need (and the idleprio process can't run - * due to a CPU-bound normal process). Fix me! XXX - */ -#if 0 - if (RTP_PRIO_IS_REALTIME(rtp.type)) { -#else - if (rtp.type != RTP_PRIO_NORMAL) { -#endif + + /* + * Realtime priority has to be restricted for reasons which + * should be obvious. However, for idleprio processes, there is + * a potential for system deadlock if an idleprio process gains + * a lock on a resource that other processes need (and the + * idleprio process can't run due to a CPU-bound normal + * process). Fix me! XXX + * + * This problem is not only related to idleprio process. + * A user level program can obtain a file lock and hold it + * indefinitely. Additionally, without idleprio processes it is + * still conceivable that a program with low priority will never + * get to run. In short, allowing this feature might make it + * easier to lock a resource indefinitely, but it is not the + * only thing that makes it possible. + */ + if (RTP_PRIO_BASE(rtp.type) == RTP_PRIO_REALTIME || + (RTP_PRIO_BASE(rtp.type) == RTP_PRIO_IDLE && + unprivileged_idprio == 0)) { error = priv_check(td, PRIV_SCHED_RTPRIO); if (error) break; @@ -417,19 +430,14 @@ sys_rtprio(td, uap) if ((error = p_cansched(td, p)) || (error = cierror)) break; - /* Disallow setting rtprio in most cases if not superuser. */ -/* - * Realtime priority has to be restricted for reasons which should be - * obvious. However, for idle priority, there is a potential for - * system deadlock if an idleprio process gains a lock on a resource - * that other processes need (and the idleprio process can't run - * due to a CPU-bound normal process). Fix me! XXX - */ -#if 0 - if (RTP_PRIO_IS_REALTIME(rtp.type)) { -#else - if (rtp.type != RTP_PRIO_NORMAL) { -#endif + /* + * Disallow setting rtprio in most cases if not superuser. + * See the comment in sys_rtprio_thread about idprio + * threads holding a lock. + */ + if (RTP_PRIO_BASE(rtp.type) == RTP_PRIO_REALTIME || + (RTP_PRIO_BASE(rtp.type) == RTP_PRIO_IDLE && + !unprivileged_idprio)) { error = priv_check(td, PRIV_SCHED_RTPRIO); if (error) break;