forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/security/apparmor/policy.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AppArmor security module
34 *
....@@ -5,12 +6,6 @@
56 *
67 * Copyright (C) 1998-2008 Novell/SUSE
78 * Copyright 2009-2010 Canonical Ltd.
8
- *
9
- * This program is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU General Public License as
11
- * published by the Free Software Foundation, version 2 of the
12
- * License.
13
- *
149 *
1510 * AppArmor policy is based around profiles, which contain the rules a
1611 * task is confined by. Every task in the system has a profile attached
....@@ -192,9 +187,9 @@
192187 {
193188 struct aa_data *data = ptr;
194189
195
- kzfree(data->data);
196
- kzfree(data->key);
197
- kzfree(data);
190
+ kfree_sensitive(data->data);
191
+ kfree_sensitive(data->key);
192
+ kfree_sensitive(data);
198193 }
199194
200195 /**
....@@ -222,16 +217,19 @@
222217 aa_put_profile(rcu_access_pointer(profile->parent));
223218
224219 aa_put_ns(profile->ns);
225
- kzfree(profile->rename);
220
+ kfree_sensitive(profile->rename);
226221
227222 aa_free_file_rules(&profile->file);
228223 aa_free_cap_rules(&profile->caps);
229224 aa_free_rlimit_rules(&profile->rlimits);
230225
231226 for (i = 0; i < profile->xattr_count; i++)
232
- kzfree(profile->xattrs[i]);
233
- kzfree(profile->xattrs);
234
- kzfree(profile->dirname);
227
+ kfree_sensitive(profile->xattrs[i]);
228
+ kfree_sensitive(profile->xattrs);
229
+ for (i = 0; i < profile->secmark_count; i++)
230
+ kfree_sensitive(profile->secmark[i].label);
231
+ kfree_sensitive(profile->secmark);
232
+ kfree_sensitive(profile->dirname);
235233 aa_put_dfa(profile->xmatch);
236234 aa_put_dfa(profile->policy.dfa);
237235
....@@ -239,13 +237,14 @@
239237 rht = profile->data;
240238 profile->data = NULL;
241239 rhashtable_free_and_destroy(rht, aa_free_data, NULL);
242
- kzfree(rht);
240
+ kfree_sensitive(rht);
243241 }
244242
245
- kzfree(profile->hash);
243
+ kfree_sensitive(profile->hash);
246244 aa_put_loaddata(profile->rawdata);
245
+ aa_label_destroy(&profile->label);
247246
248
- kzfree(profile);
247
+ kfree_sensitive(profile);
249248 }
250249
251250 /**
....@@ -584,7 +583,7 @@
584583 {
585584 if (profile) {
586585 if (profile->label.flags & FLAG_IMMUTIBLE) {
587
- *info = "cannot replace immutible profile";
586
+ *info = "cannot replace immutable profile";
588587 return -EPERM;
589588 } else if (noreplace) {
590589 *info = "profile already exists";
....@@ -858,7 +857,7 @@
858857 ssize_t aa_replace_profiles(struct aa_ns *policy_ns, struct aa_label *label,
859858 u32 mask, struct aa_loaddata *udata)
860859 {
861
- const char *ns_name, *info = NULL;
860
+ const char *ns_name = NULL, *info = NULL;
862861 struct aa_ns *ns = NULL;
863862 struct aa_load_ent *ent, *tmp;
864863 struct aa_loaddata *rawdata_ent;
....@@ -1045,6 +1044,7 @@
10451044 out:
10461045 aa_put_ns(ns);
10471046 aa_put_loaddata(udata);
1047
+ kfree(ns_name);
10481048
10491049 if (error)
10501050 return error;
....@@ -1125,7 +1125,7 @@
11251125
11261126 if (!name) {
11271127 /* remove namespace - can only happen if fqname[0] == ':' */
1128
- mutex_lock_nested(&ns->parent->lock, ns->level);
1128
+ mutex_lock_nested(&ns->parent->lock, ns->parent->level);
11291129 __aa_bump_ns_revision(ns);
11301130 __aa_remove_ns(ns);
11311131 mutex_unlock(&ns->parent->lock);