hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/kernel/auditfilter.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* auditfilter.c -- filtering of audit events
23 *
34 * Copyright 2003-2004 Red Hat, Inc.
45 * Copyright 2005 Hewlett-Packard Development Company, L.P.
56 * Copyright 2005 IBM Corporation
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, write to the Free Software
19
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
207 */
218
229 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -335,7 +322,7 @@
335322 /* check if an audit field is valid */
336323 static int audit_field_valid(struct audit_entry *entry, struct audit_field *f)
337324 {
338
- switch(f->type) {
325
+ switch (f->type) {
339326 case AUDIT_MSGTYPE:
340327 if (entry->rule.listnr != AUDIT_FILTER_EXCLUDE &&
341328 entry->rule.listnr != AUDIT_FILTER_USER)
....@@ -347,7 +334,7 @@
347334 break;
348335 }
349336
350
- switch(entry->rule.listnr) {
337
+ switch (entry->rule.listnr) {
351338 case AUDIT_FILTER_FS:
352339 switch(f->type) {
353340 case AUDIT_FSTYPE:
....@@ -358,9 +345,16 @@
358345 }
359346 }
360347
361
- switch(f->type) {
362
- default:
363
- return -EINVAL;
348
+ /* Check for valid field type and op */
349
+ switch (f->type) {
350
+ case AUDIT_ARG0:
351
+ case AUDIT_ARG1:
352
+ case AUDIT_ARG2:
353
+ case AUDIT_ARG3:
354
+ case AUDIT_PERS: /* <uapi/linux/personality.h> */
355
+ case AUDIT_DEVMINOR:
356
+ /* all ops are valid */
357
+ break;
364358 case AUDIT_UID:
365359 case AUDIT_EUID:
366360 case AUDIT_SUID:
....@@ -373,44 +367,51 @@
373367 case AUDIT_FSGID:
374368 case AUDIT_OBJ_GID:
375369 case AUDIT_PID:
376
- case AUDIT_PERS:
377370 case AUDIT_MSGTYPE:
378371 case AUDIT_PPID:
379372 case AUDIT_DEVMAJOR:
380
- case AUDIT_DEVMINOR:
381373 case AUDIT_EXIT:
382374 case AUDIT_SUCCESS:
383375 case AUDIT_INODE:
384376 case AUDIT_SESSIONID:
377
+ case AUDIT_SUBJ_SEN:
378
+ case AUDIT_SUBJ_CLR:
379
+ case AUDIT_OBJ_LEV_LOW:
380
+ case AUDIT_OBJ_LEV_HIGH:
381
+ case AUDIT_SADDR_FAM:
385382 /* bit ops are only useful on syscall args */
386383 if (f->op == Audit_bitmask || f->op == Audit_bittest)
387384 return -EINVAL;
388385 break;
389
- case AUDIT_ARG0:
390
- case AUDIT_ARG1:
391
- case AUDIT_ARG2:
392
- case AUDIT_ARG3:
393386 case AUDIT_SUBJ_USER:
394387 case AUDIT_SUBJ_ROLE:
395388 case AUDIT_SUBJ_TYPE:
396
- case AUDIT_SUBJ_SEN:
397
- case AUDIT_SUBJ_CLR:
398389 case AUDIT_OBJ_USER:
399390 case AUDIT_OBJ_ROLE:
400391 case AUDIT_OBJ_TYPE:
401
- case AUDIT_OBJ_LEV_LOW:
402
- case AUDIT_OBJ_LEV_HIGH:
403392 case AUDIT_WATCH:
404393 case AUDIT_DIR:
405394 case AUDIT_FILTERKEY:
406
- break;
407395 case AUDIT_LOGINUID_SET:
408
- if ((f->val != 0) && (f->val != 1))
409
- return -EINVAL;
410
- /* FALL THROUGH */
411396 case AUDIT_ARCH:
412397 case AUDIT_FSTYPE:
398
+ case AUDIT_PERM:
399
+ case AUDIT_FILETYPE:
400
+ case AUDIT_FIELD_COMPARE:
401
+ case AUDIT_EXE:
402
+ /* only equal and not equal valid ops */
413403 if (f->op != Audit_not_equal && f->op != Audit_equal)
404
+ return -EINVAL;
405
+ break;
406
+ default:
407
+ /* field not recognized */
408
+ return -EINVAL;
409
+ }
410
+
411
+ /* Check for select valid field values */
412
+ switch (f->type) {
413
+ case AUDIT_LOGINUID_SET:
414
+ if ((f->val != 0) && (f->val != 1))
414415 return -EINVAL;
415416 break;
416417 case AUDIT_PERM:
....@@ -425,11 +426,14 @@
425426 if (f->val > AUDIT_MAX_FIELD_COMPARE)
426427 return -EINVAL;
427428 break;
428
- case AUDIT_EXE:
429
- if (f->op != Audit_not_equal && f->op != Audit_equal)
429
+ case AUDIT_SADDR_FAM:
430
+ if (f->val >= AF_MAX)
430431 return -EINVAL;
431432 break;
433
+ default:
434
+ break;
432435 }
436
+
433437 return 0;
434438 }
435439
....@@ -677,7 +681,7 @@
677681 data->values[i] = AUDIT_UID_UNSET;
678682 break;
679683 }
680
- /* fallthrough if set */
684
+ fallthrough; /* if set */
681685 default:
682686 data->values[i] = f->val;
683687 }
....@@ -1098,7 +1102,7 @@
10981102 if (!audit_enabled)
10991103 return;
11001104
1101
- ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE);
1105
+ ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_CONFIG_CHANGE);
11021106 if (!ab)
11031107 return;
11041108 audit_log_session_info(ab);
....@@ -1208,7 +1212,6 @@
12081212 case Audit_bittest:
12091213 return ((left & right) == right);
12101214 default:
1211
- BUG();
12121215 return 0;
12131216 }
12141217 }
....@@ -1231,7 +1234,6 @@
12311234 case Audit_bitmask:
12321235 case Audit_bittest:
12331236 default:
1234
- BUG();
12351237 return 0;
12361238 }
12371239 }
....@@ -1254,7 +1256,6 @@
12541256 case Audit_bitmask:
12551257 case Audit_bittest:
12561258 default:
1257
- BUG();
12581259 return 0;
12591260 }
12601261 }
....@@ -1297,12 +1298,12 @@
12971298 * @parentlen: length of the parent if known. Passing in AUDIT_NAME_FULL
12981299 * here indicates that we must compute this value.
12991300 */
1300
-int audit_compare_dname_path(const char *dname, const char *path, int parentlen)
1301
+int audit_compare_dname_path(const struct qstr *dname, const char *path, int parentlen)
13011302 {
13021303 int dlen, pathlen;
13031304 const char *p;
13041305
1305
- dlen = strlen(dname);
1306
+ dlen = dname->len;
13061307 pathlen = strlen(path);
13071308 if (pathlen < dlen)
13081309 return 1;
....@@ -1313,7 +1314,7 @@
13131314
13141315 p = path + parentlen;
13151316
1316
- return strncmp(p, dname, dlen);
1317
+ return strncmp(p, dname->name, dlen);
13171318 }
13181319
13191320 int audit_filter(int msgtype, unsigned int listtype)
....@@ -1322,8 +1323,6 @@
13221323 int ret = 1; /* Audit by default */
13231324
13241325 rcu_read_lock();
1325
- if (list_empty(&audit_filter_list[listtype]))
1326
- goto unlock_and_return;
13271326 list_for_each_entry_rcu(e, &audit_filter_list[listtype], list) {
13281327 int i, result = 0;
13291328
....@@ -1362,7 +1361,7 @@
13621361 if (f->lsm_rule) {
13631362 security_task_getsecid(current, &sid);
13641363 result = security_audit_rule_match(sid,
1365
- f->type, f->op, f->lsm_rule, NULL);
1364
+ f->type, f->op, f->lsm_rule);
13661365 }
13671366 break;
13681367 case AUDIT_EXE: