diff options
| author | Richard Guy Briggs <rgb@redhat.com> | 2019-04-08 12:50:57 -0400 |
|---|---|---|
| committer | Paul Moore <paul@paul-moore.com> | 2019-04-08 18:10:35 -0400 |
| commit | 699c1868a743f530081f429058616a2dd5d8a4b2 (patch) | |
| tree | 0981898759941fbcc0df283993f9446463c95b0a | |
| parent | a1aa08a01f734d48a8f76b12aca9f4e4adae7649 (diff) | |
audit: purge unnecessary list_empty calls
The original conditions that led to the use of list_empty() to optimize
list_for_each_entry_rcu() in auditfilter.c and auditsc.c code have been
removed without removing the list_empty() call, but this code example
has been copied several times. Remove the unnecessary list_empty()
calls.
Please see upstream github issue
https://github.com/linux-audit/audit-kernel/issues/112
Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
| -rw-r--r-- | kernel/auditfilter.c | 2 | ||||
| -rw-r--r-- | kernel/auditsc.c | 64 |
2 files changed, 27 insertions, 39 deletions
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 63f8b3f26fab..2c3c2f349b23 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c | |||
| @@ -1315,8 +1315,6 @@ int audit_filter(int msgtype, unsigned int listtype) | |||
| 1315 | int ret = 1; /* Audit by default */ | 1315 | int ret = 1; /* Audit by default */ |
| 1316 | 1316 | ||
| 1317 | rcu_read_lock(); | 1317 | rcu_read_lock(); |
| 1318 | if (list_empty(&audit_filter_list[listtype])) | ||
| 1319 | goto unlock_and_return; | ||
| 1320 | list_for_each_entry_rcu(e, &audit_filter_list[listtype], list) { | 1318 | list_for_each_entry_rcu(e, &audit_filter_list[listtype], list) { |
| 1321 | int i, result = 0; | 1319 | int i, result = 0; |
| 1322 | 1320 | ||
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 98a98e6dca05..51a2ceb3a1ca 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
| @@ -771,15 +771,13 @@ static enum audit_state audit_filter_syscall(struct task_struct *tsk, | |||
| 771 | return AUDIT_DISABLED; | 771 | return AUDIT_DISABLED; |
| 772 | 772 | ||
| 773 | rcu_read_lock(); | 773 | rcu_read_lock(); |
| 774 | if (!list_empty(list)) { | 774 | list_for_each_entry_rcu(e, list, list) { |
| 775 | list_for_each_entry_rcu(e, list, list) { | 775 | if (audit_in_mask(&e->rule, ctx->major) && |
| 776 | if (audit_in_mask(&e->rule, ctx->major) && | 776 | audit_filter_rules(tsk, &e->rule, ctx, NULL, |
| 777 | audit_filter_rules(tsk, &e->rule, ctx, NULL, | 777 | &state, false)) { |
| 778 | &state, false)) { | 778 | rcu_read_unlock(); |
| 779 | rcu_read_unlock(); | 779 | ctx->current_state = state; |
| 780 | ctx->current_state = state; | 780 | return state; |
| 781 | return state; | ||
| 782 | } | ||
| 783 | } | 781 | } |
| 784 | } | 782 | } |
| 785 | rcu_read_unlock(); | 783 | rcu_read_unlock(); |
| @@ -798,9 +796,6 @@ static int audit_filter_inode_name(struct task_struct *tsk, | |||
| 798 | struct audit_entry *e; | 796 | struct audit_entry *e; |
| 799 | enum audit_state state; | 797 | enum audit_state state; |
| 800 | 798 | ||
| 801 | if (list_empty(list)) | ||
| 802 | return 0; | ||
| 803 | |||
| 804 | list_for_each_entry_rcu(e, list, list) { | 799 | list_for_each_entry_rcu(e, list, list) { |
| 805 | if (audit_in_mask(&e->rule, ctx->major) && | 800 | if (audit_in_mask(&e->rule, ctx->major) && |
| 806 | audit_filter_rules(tsk, &e->rule, ctx, n, &state, false)) { | 801 | audit_filter_rules(tsk, &e->rule, ctx, n, &state, false)) { |
| @@ -808,7 +803,6 @@ static int audit_filter_inode_name(struct task_struct *tsk, | |||
| 808 | return 1; | 803 | return 1; |
| 809 | } | 804 | } |
| 810 | } | 805 | } |
| 811 | |||
| 812 | return 0; | 806 | return 0; |
| 813 | } | 807 | } |
| 814 | 808 | ||
| @@ -1945,18 +1939,16 @@ void __audit_inode(struct filename *name, const struct dentry *dentry, | |||
| 1945 | return; | 1939 | return; |
| 1946 | 1940 | ||
| 1947 | rcu_read_lock(); | 1941 | rcu_read_lock(); |
| 1948 | if (!list_empty(list)) { | 1942 | list_for_each_entry_rcu(e, list, list) { |
| 1949 | list_for_each_entry_rcu(e, list, list) { | 1943 | for (i = 0; i < e->rule.field_count; i++) { |
| 1950 | for (i = 0; i < e->rule.field_count; i++) { | 1944 | struct audit_field *f = &e->rule.fields[i]; |
| 1951 | struct audit_field *f = &e->rule.fields[i]; | 1945 | |
| 1952 | 1946 | if (f->type == AUDIT_FSTYPE | |
| 1953 | if (f->type == AUDIT_FSTYPE | 1947 | && audit_comparator(inode->i_sb->s_magic, |
| 1954 | && audit_comparator(inode->i_sb->s_magic, | 1948 | f->op, f->val) |
| 1955 | f->op, f->val) | 1949 | && e->rule.action == AUDIT_NEVER) { |
| 1956 | && e->rule.action == AUDIT_NEVER) { | 1950 | rcu_read_unlock(); |
| 1957 | rcu_read_unlock(); | 1951 | return; |
| 1958 | return; | ||
| 1959 | } | ||
| 1960 | } | 1952 | } |
| 1961 | } | 1953 | } |
| 1962 | } | 1954 | } |
| @@ -2065,18 +2057,16 @@ void __audit_inode_child(struct inode *parent, | |||
| 2065 | return; | 2057 | return; |
| 2066 | 2058 | ||
| 2067 | rcu_read_lock(); | 2059 | rcu_read_lock(); |
| 2068 | if (!list_empty(list)) { | 2060 | list_for_each_entry_rcu(e, list, list) { |
| 2069 | list_for_each_entry_rcu(e, list, list) { | 2061 | for (i = 0; i < e->rule.field_count; i++) { |
| 2070 | for (i = 0; i < e->rule.field_count; i++) { | 2062 | struct audit_field *f = &e->rule.fields[i]; |
| 2071 | struct audit_field *f = &e->rule.fields[i]; | 2063 | |
| 2072 | 2064 | if (f->type == AUDIT_FSTYPE | |
| 2073 | if (f->type == AUDIT_FSTYPE | 2065 | && audit_comparator(parent->i_sb->s_magic, |
| 2074 | && audit_comparator(parent->i_sb->s_magic, | 2066 | f->op, f->val) |
| 2075 | f->op, f->val) | 2067 | && e->rule.action == AUDIT_NEVER) { |
| 2076 | && e->rule.action == AUDIT_NEVER) { | 2068 | rcu_read_unlock(); |
| 2077 | rcu_read_unlock(); | 2069 | return; |
| 2078 | return; | ||
| 2079 | } | ||
| 2080 | } | 2070 | } |
| 2081 | } | 2071 | } |
| 2082 | } | 2072 | } |
