mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Serge Hallyn <serue@us.ibm.com>
To: serue@us.ibm.com
Cc: Greg KH <greg@kroah.com>,
	rsc@swtch.com, Ashwin Ganti <ashwin.ganti@gmail.com>,
	ericvh@gmail.com, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org, Ron Minnich <rminnich@gmail.com>
Subject: [PATCH 7/8] p9auth: add cap_node timeout
Date: Tue, 16 Feb 2010 16:45:00 -0600	[thread overview]
Message-ID: <1266360301-30081-7-git-send-email-serue@us.ibm.com> (raw)
In-Reply-To: <1266360301-30081-1-git-send-email-serue@us.ibm.com>

From: Serge E. Hallyn <serue@us.ibm.com>

Mark each caphash entry with the current time.  When a new caphash is
added, any entries which were added more than two minutes ago are
discarded.

We may want to make two minutes configurable, or may want to also
discard entries if more than N entries are on the list (to prevent
a forced OOM by a misbehaving privileged process).  The purpose
of this patch is only to prevent gradually consuming more and more
memory due to "legitimate" unused entries.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: Greg KH <greg@kroah.com>
cc: rsc@swtch.com
Cc: Ashwin Ganti <ashwin.ganti@gmail.com>
Cc: ericvh@gmail.com
Cc: devel@linuxdriverproject.org
Cc: linux-kernel@vger.kernel.org
Cc: Ron Minnich <rminnich@gmail.com>
---
 drivers/staging/p9auth/p9auth.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/p9auth/p9auth.c b/drivers/staging/p9auth/p9auth.c
index e94c4fe..6012bd9 100644
--- a/drivers/staging/p9auth/p9auth.c
+++ b/drivers/staging/p9auth/p9auth.c
@@ -40,6 +40,7 @@
 
 struct cap_node {
 	char data[CAP_NODE_SIZE];
+	unsigned long time_created;
 	struct list_head list;
 };
 
@@ -275,6 +276,23 @@ static int grant_id(struct id_set *set)
 	return ret;
 }
 
+/* Expose this through sysctl eventually?  2 min timeout for hashes */
+
+static int cap_timeout = 120;
+static void remove_old_entries(struct cap_dev *dev)
+{
+	struct cap_node *node, *tmp;
+
+	if (dev->head == NULL)
+		return;
+	list_for_each_entry_safe(node, tmp, &dev->head->list, list) {
+		if (node->time_created + HZ * cap_timeout < jiffies) {
+			list_del(&node->list);
+			kfree(node);
+		}
+	}
+}
+
 static int add_caphash_entry(struct cap_dev *dev, char *user_buf, size_t count)
 {
 	struct cap_node *node_ptr;
@@ -290,7 +308,9 @@ static int add_caphash_entry(struct cap_dev *dev, char *user_buf, size_t count)
 	printk(KERN_INFO "Capability being written to /dev/caphash : \n");
 	hexdump(user_buf, count);
 	memcpy(node_ptr->data, user_buf, count);
+	node_ptr->time_created = jiffies;
 	list_add(&(node_ptr->list), &(dev->head->list));
+	remove_old_entries(dev);
 
 	return 0;
 }
-- 
1.6.1


  parent reply	other threads:[~2010-02-16 22:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-16 22:44 [PATCH 1/8] p9auth: set fsuid Serge Hallyn
2010-02-16 22:44 ` [PATCH 2/8] p9auth: split core function out of some set*{u,g}id functions Serge Hallyn
2010-02-16 22:44 ` [PATCH 3/8] p9auth: use setresuid Serge Hallyn
2010-02-16 22:44 ` [PATCH 4/8] p9auth: add CAP_GRANT_ID to authorize use of /dev/caphash Serge Hallyn
2010-02-16 22:44 ` [PATCH 5/8] p9auth cleanup Serge Hallyn
2010-02-16 22:44 ` [PATCH 6/8] p9auth: do groups Serge Hallyn
2010-02-16 22:45 ` Serge Hallyn [this message]
2010-02-16 22:45 ` [PATCH 8/8] p9auth: don't trim entries on write-only open Serge Hallyn
2010-02-25 23:28 ` [PATCH 1/8] p9auth: set fsuid Greg KH
2010-02-26  4:05   ` Serge E. Hallyn
2010-02-26  5:06     ` Greg KH
2010-02-26 18:19       ` Serge E. Hallyn
2010-03-04 22:04         ` Ashwin Ganti
2010-03-05 20:07           ` Serge E. Hallyn

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=1266360301-30081-7-git-send-email-serue@us.ibm.com \
    --to=serue@us.ibm.com \
    --cc=ashwin.ganti@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=ericvh@gmail.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rminnich@gmail.com \
    --cc=rsc@swtch.com \
    /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

all inboxes | Powered by JetHome®