[ERD][NEUS7920-76] [COMMON] lib: dss: support to output notifier call functions
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / kernel / audit.c
index be1c28fd4d575d824606f10860f766fc09f8a0c1..d301276bca584170e2d01de37f5372cbf5f4de38 100644 (file)
@@ -85,13 +85,13 @@ static int  audit_initialized;
 #define AUDIT_OFF      0
 #define AUDIT_ON       1
 #define AUDIT_LOCKED   2
-u32            audit_enabled;
-u32            audit_ever_enabled;
+u32            audit_enabled = AUDIT_OFF;
+u32            audit_ever_enabled = !!AUDIT_OFF;
 
 EXPORT_SYMBOL_GPL(audit_enabled);
 
 /* Default state when kernel boots without any parameters. */
-static u32     audit_default;
+static u32     audit_default = AUDIT_OFF;
 
 /* If auditing cannot proceed, audit_failure selects what happens. */
 static u32     audit_failure = AUDIT_FAIL_PRINTK;
@@ -1058,6 +1058,8 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature
                return;
 
        ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_FEATURE_CHANGE);
+       if (!ab)
+               return;
        audit_log_task_info(ab, current);
        audit_log_format(ab, " feature=%s old=%u new=%u old_lock=%u new_lock=%u res=%d",
                         audit_feature_names[which], !!old_feature, !!new_feature,
@@ -1197,25 +1199,28 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
                        pid_t auditd_pid;
                        struct pid *req_pid = task_tgid(current);
 
-                       /* sanity check - PID values must match */
-                       if (new_pid != pid_vnr(req_pid))
+                       /* Sanity check - PID values must match. Setting
+                        * pid to 0 is how auditd ends auditing. */
+                       if (new_pid && (new_pid != pid_vnr(req_pid)))
                                return -EINVAL;
 
                        /* test the auditd connection */
                        audit_replace(req_pid);
 
                        auditd_pid = auditd_pid_vnr();
-                       /* only the current auditd can unregister itself */
-                       if ((!new_pid) && (new_pid != auditd_pid)) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EACCES;
-                       }
-                       /* replacing a healthy auditd is not allowed */
-                       if (auditd_pid && new_pid) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EEXIST;
+                       if (auditd_pid) {
+                               /* replacing a healthy auditd is not allowed */
+                               if (new_pid) {
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EEXIST;
+                               }
+                               /* only current auditd can unregister itself */
+                               if (pid_vnr(req_pid) != auditd_pid) {
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EACCES;
+                               }
                        }
 
                        if (new_pid) {
@@ -1549,8 +1554,6 @@ static int __init audit_init(void)
        register_pernet_subsys(&audit_net_ops);
 
        audit_initialized = AUDIT_INITIALIZED;
-       audit_enabled = audit_default;
-       audit_ever_enabled |= !!audit_default;
 
        kauditd_task = kthread_run(kauditd_thread, NULL, "kauditd");
        if (IS_ERR(kauditd_task)) {
@@ -1572,6 +1575,8 @@ static int __init audit_enable(char *str)
        audit_default = !!simple_strtol(str, NULL, 0);
        if (!audit_default)
                audit_initialized = AUDIT_DISABLED;
+       audit_enabled = audit_default;
+       audit_ever_enabled = !!audit_enabled;
 
        pr_info("%s\n", audit_default ?
                "enabled (after initialization)" : "disabled (until reboot)");