<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>[PATCH] New capability CAP_RND_ADD for solely allowing addition of entropy</title>
        <description> I was interested in modifying haveged to drop privileges after opening
/dev/random but discovered this was not possible because it uses the
ioctl RNDADDENTROPY which requires CAP_SYS_ADMIN.

Retaining CAP_SYS_ADMIN after dropping GID/UID would defeat the point
of doing so, so this program must always run with UID 0 and/or
CAP_SYS_ADMIN, which is undesirable.

I attach a patch to add a new capability CAP_RND_ADD, which allows the
use of ioctls RNDADDENTROPY and RNDADDTOENTCNT. It further modifies
drivers/char/random.c to also check for this capability before returning
-EPERM.

==================

--- a/drivers/char/random.c    2012-07-14 02:52:10.781202854 +0100
+++ b/drivers/char/random.c    2012-07-14 02:52:55.369201089 +0100
@@ -1154,14 +1154,14 @@
              return -EFAULT;
          return 0;
      case RNDADDTOENTCNT:
-        if (!capable(CAP_SYS_ADMIN))
+        if (!capable(CAP_SYS_ADMIN) &amp;amp;&amp;amp; !capable(CAP_RND_ADD))
              return -EPERM;
          if (get_user(ent_count, p))
              return -EFAULT;
          credit_entropy_bits(&amp;amp;input_pool, ent_count);
          return 0;
      case RNDADDENTROPY:
-        if (!capable(CAP_SYS_ADMIN))
+        if (!capable(CAP_SYS_ADMIN) &amp;amp;&amp;amp; !capable(CAP_RND_ADD))
              return -EPERM;
          if (get_user(ent_count, p++))
              return -EFAULT;
--- a/include/linux/capability.h    2012-07-14 03:15:52.378624902 +0100
+++ b/include/linux/capability.h    2012-07-14 03:16:47.508624928 +0100
@@ -364,7 +364,18 @@

  #define CAP_EPOLLWAKEUP      36

-#define CAP_LAST_CAP         CAP_EPOLLWAKEUP
+/* Allow adding of random entropy and updating entropy estimate,
+   but not clearing the entropy pool (see drivers/char/random.c)
+   Introduced so that software like haveged can drop gid/uid
+   on startup and drop all capabilities except this one.
+   Otherwise it would require CAP_SYS_ADMIN, which would
+   defeat the point of dropping gid/uid. */
+
+#define CAP_RND_ADD          37
+
+
+
+#define CAP_LAST_CAP         CAP_RND_ADD

  #define cap_valid(x) ((x) &amp;gt;= 0 &amp;amp;&amp;amp; (x) &amp;lt;= CAP_LAST_CAP)



--
To unsubscribe from this list: send the line &amp;quot;unsubscribe linux-kernel&amp;quot; in
the body of a message to &amp;#109;&amp;#97;&amp;#106;&amp;#111;&amp;#114;&amp;#100;&amp;#111;&amp;#109;&amp;#111;&amp;#64;&amp;#118;&amp;#103;&amp;#101;&amp;#114;&amp;#46;&amp;#107;&amp;#101;&amp;#114;&amp;#110;&amp;#101;&amp;#108;&amp;#46;&amp;#111;&amp;#114;&amp;#103;
More majordomo info at  [vger.kernel.org]
Please read the FAQ at  [www.tux.org]</description>
        <link>http://choon.net/forum/read.php?21,1178712,1178712#msg-1178712</link>
        <lastBuildDate>Sun, 26 May 2013 16:41:23 +0800</lastBuildDate>
        <generator>Phorum 5.2.19</generator>
        <item>
            <guid>http://choon.net/forum/read.php?21,1178712,1178712#msg-1178712</guid>
            <title>[PATCH] New capability CAP_RND_ADD for solely allowing addition of entropy</title>
            <link>http://choon.net/forum/read.php?21,1178712,1178712#msg-1178712</link>
            <description><![CDATA[ I was interested in modifying haveged to drop privileges after opening<br />
/dev/random but discovered this was not possible because it uses the<br />
ioctl RNDADDENTROPY which requires CAP_SYS_ADMIN.<br />
<br />
Retaining CAP_SYS_ADMIN after dropping GID/UID would defeat the point<br />
of doing so, so this program must always run with UID 0 and/or<br />
CAP_SYS_ADMIN, which is undesirable.<br />
<br />
I attach a patch to add a new capability CAP_RND_ADD, which allows the<br />
use of ioctls RNDADDENTROPY and RNDADDTOENTCNT. It further modifies<br />
drivers/char/random.c to also check for this capability before returning<br />
-EPERM.<br />
<br />
==================<br />
<br />
--- a/drivers/char/random.c    2012-07-14 02:52:10.781202854 +0100<br />
+++ b/drivers/char/random.c    2012-07-14 02:52:55.369201089 +0100<br />
@@ -1154,14 +1154,14 @@<br />
              return -EFAULT;<br />
          return 0;<br />
      case RNDADDTOENTCNT:<br />
-        if (!capable(CAP_SYS_ADMIN))<br />
+        if (!capable(CAP_SYS_ADMIN) &amp;&amp; !capable(CAP_RND_ADD))<br />
              return -EPERM;<br />
          if (get_user(ent_count, p))<br />
              return -EFAULT;<br />
          credit_entropy_bits(&amp;input_pool, ent_count);<br />
          return 0;<br />
      case RNDADDENTROPY:<br />
-        if (!capable(CAP_SYS_ADMIN))<br />
+        if (!capable(CAP_SYS_ADMIN) &amp;&amp; !capable(CAP_RND_ADD))<br />
              return -EPERM;<br />
          if (get_user(ent_count, p++))<br />
              return -EFAULT;<br />
--- a/include/linux/capability.h    2012-07-14 03:15:52.378624902 +0100<br />
+++ b/include/linux/capability.h    2012-07-14 03:16:47.508624928 +0100<br />
@@ -364,7 +364,18 @@<br />
<br />
  #define CAP_EPOLLWAKEUP      36<br />
<br />
-#define CAP_LAST_CAP         CAP_EPOLLWAKEUP<br />
+/* Allow adding of random entropy and updating entropy estimate,<br />
+   but not clearing the entropy pool (see drivers/char/random.c)<br />
+   Introduced so that software like haveged can drop gid/uid<br />
+   on startup and drop all capabilities except this one.<br />
+   Otherwise it would require CAP_SYS_ADMIN, which would<br />
+   defeat the point of dropping gid/uid. */<br />
+<br />
+#define CAP_RND_ADD          37<br />
+<br />
+<br />
+<br />
+#define CAP_LAST_CAP         CAP_RND_ADD<br />
<br />
  #define cap_valid(x) ((x) &gt;= 0 &amp;&amp; (x) &lt;= CAP_LAST_CAP)<br />
<br />
<br />
<br />
--<br />
To unsubscribe from this list: send the line &quot;unsubscribe linux-kernel&quot; in<br />
the body of a message to <a href="mailto:&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;">&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;</a><br />
More majordomo info at  [<a href="http://vger.kernel.org/majordomo-info.html"  rel="nofollow">vger.kernel.org</a>]<br />
Please read the FAQ at  [<a href="http://www.tux.org/lkml/"  rel="nofollow">www.tux.org</a>]]]></description>
            <dc:creator>Aaron Jones</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Sat, 14 Jul 2012 10:29:01 +0800</pubDate>
        </item>
    </channel>
</rss>
