public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Aaron Jones <aaronmdjones@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] New capability CAP_RND_ADD for solely allowing addition of entropy
Date: Sat, 14 Jul 2012 03:27:50 +0100	[thread overview]
Message-ID: <5000D926.2020307@gmail.com> (raw)

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) && !capable(CAP_RND_ADD))
              return -EPERM;
          if (get_user(ent_count, p))
              return -EFAULT;
          credit_entropy_bits(&input_pool, ent_count);
          return 0;
      case RNDADDENTROPY:
-        if (!capable(CAP_SYS_ADMIN))
+        if (!capable(CAP_SYS_ADMIN) && !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) >= 0 && (x) <= CAP_LAST_CAP)




                 reply	other threads:[~2012-07-14  2:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5000D926.2020307@gmail.com \
    --to=aaronmdjones@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox