Re: svn commit: r228470 - head/sys/kern

2011-12-13 Thread Pawel Jakub Dawidek
On Tue, Dec 13, 2011 at 02:00:28PM +, Eitan Adler wrote:
> Author: eadler (ports committer)
> Date: Tue Dec 13 14:00:27 2011
> New Revision: 228470
> URL: http://svn.freebsd.org/changeset/base/228470
> 
> Log:
>   - Add a sysctl to allow non-root users the ability to set idle
>   priorities.
[...]

I'd suggest using consistent style with those two:

[...]
> + unprivileged_idprio == 0)) {
[...]
> + !unprivileged_idprio)) {
[...]

Because it should be either 0 or 1, the latter is better.

-- 
Pawel Jakub Dawidek   http://www.wheelsystems.com
FreeBSD committer http://www.FreeBSD.org
Am I Evil? Yes, I Am! http://yomoli.com


pgpZzK2DiyF99.pgp
Description: PGP signature


svn commit: r228470 - head/sys/kern

2011-12-13 Thread Eitan Adler
Author: eadler (ports committer)
Date: Tue Dec 13 14:00:27 2011
New Revision: 228470
URL: http://svn.freebsd.org/changeset/base/228470

Log:
  - Add a sysctl to allow non-root users the ability to set idle
  priorities.
  
  - While here fix up some style nits.
  
  Discussed with: cperciva (breifly)
  Reviewed by:  pjd (earlier version)
  Reviewed by:  bde
  Approved by:  jhb
  MFC after:1 month

Modified:
  head/sys/kern/kern_resource.c

Modified: head/sys/kern/kern_resource.c
==
--- head/sys/kern/kern_resource.c   Tue Dec 13 13:38:03 2011
(r228469)
+++ head/sys/kern/kern_resource.c   Tue Dec 13 14:00:27 2011
(r228470)
@@ -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;
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"