From: "George C. Wilson" <ltcgcw@us.ibm.com>
To: linux-audit@redhat.com
Subject: Subject: [PATCH] Fix audit_list{,_rules} deadlock
Date: Tue, 25 Apr 2006 16:16:44 -0500 [thread overview]
Message-ID: <20060425211644.GA18366@us.ibm.com> (raw)
Following is Serge's patch:
From: Serge Hallyn <serue@us.ibm.com>
Subject: [PATCH] Fix audit_list{,_rules} deadlock
The audit_list and audit_list_rules functions send all stored audit
rules to userspace over netlink from a kthread. They do this entirely
from under the audit_netlink_mutex. If the netlink buffer gets to
being too large, then netlink will wait for the receiver to grab the
contents. But the receiver is in audit_receive, which also grabs
the audit_netlink_mutex. Deadlock.
This patch makes audit_list{,_rules} form a list of rules under the
mutex, then drop the mutex, then send the list.
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
---
kernel/auditfilter.c | 54
+++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index 63aa039..b2e656f 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -510,12 +510,22 @@ static inline int audit_del_rule(struct
/* List rules using struct audit_rule. Exists for backward
* compatibility with userspace. */
+struct au_rule_list {
+ union {
+ struct audit_rule *rule;
+ struct audit_rule_data *data;
+ } u;
+ struct list_head next;
+};
+
static int audit_list(void *_dest)
{
int pid, seq;
int *dest = _dest;
struct audit_entry *entry;
int i;
+ LIST_HEAD(sendlist);
+ struct au_rule_list *r, *r1;
pid = dest[0];
seq = dest[1];
@@ -532,14 +542,27 @@ static int audit_list(void *_dest)
rule = audit_krule_to_rule(&entry->rule);
if (unlikely(!rule))
break;
- audit_send_reply(pid, seq, AUDIT_LIST, 0, 1,
- rule, sizeof(*rule));
- kfree(rule);
+ r = kmalloc(sizeof(*r), GFP_KERNEL);
+ if (unlikely(!r)) {
+ kfree(rule);
+ break;
+ }
+ r->u.rule = rule;
+ list_add(&r->next, &sendlist);
}
}
- audit_send_reply(pid, seq, AUDIT_LIST, 1, 1, NULL, 0);
mutex_unlock(&audit_netlink_mutex);
+
+ list_for_each_entry_safe(r, r1, &sendlist, next) {
+ audit_send_reply(pid, seq, AUDIT_LIST, 0, 1,
+ r->u.rule, sizeof(*r->u.rule));
+ list_del(&r->next);
+ kfree(r->u.rule);
+ kfree(r);
+ }
+
+ audit_send_reply(pid, seq, AUDIT_LIST, 1, 1, NULL, 0);
return 0;
}
@@ -549,6 +572,8 @@ static int audit_list_rules(void *_dest)
int pid, seq;
int *dest = _dest;
struct audit_entry *e;
+ LIST_HEAD(sendlist);
+ struct au_rule_list *r, *r1;
int i;
pid = dest[0];
@@ -566,14 +591,27 @@ static int audit_list_rules(void *_dest)
data = audit_krule_to_data(&e->rule);
if (unlikely(!data))
break;
- audit_send_reply(pid, seq, AUDIT_LIST_RULES, 0, 1,
- data, sizeof(*data));
- kfree(data);
+ r = kmalloc(sizeof(*r), GFP_KERNEL);
+ if (unlikely(!r)) {
+ kfree(data);
+ break;
+ }
+ r->u.data = data;
+ list_add(&r->next, &sendlist);
}
}
+ mutex_unlock(&audit_netlink_mutex);
+
+ list_for_each_entry_safe(r, r1, &sendlist, next) {
+ audit_send_reply(pid, seq, AUDIT_LIST_RULES, 0, 1,
+ r->u.data, sizeof(*r->u.data));
+ list_del(&r->next);
+ kfree(r->u.data);
+ kfree(r);
+ }
+
audit_send_reply(pid, seq, AUDIT_LIST_RULES, 1, 1, NULL, 0);
- mutex_unlock(&audit_netlink_mutex);
return 0;
}
--
George Wilson <ltcgcw@us.ibm.com>
IBM Linux Technology Center
reply other threads:[~2006-04-25 21:16 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=20060425211644.GA18366@us.ibm.com \
--to=ltcgcw@us.ibm.com \
--cc=linux-audit@redhat.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