オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Diff of /branches/ccs-patch/security/ccsecurity/policy_io.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2958 by kumaneko, Wed Aug 26 09:43:56 2009 UTC revision 3162 by kumaneko, Mon Nov 9 06:10:32 2009 UTC
# Line 3  Line 3 
3   *   *
4   * Copyright (C) 2005-2009  NTT DATA CORPORATION   * Copyright (C) 2005-2009  NTT DATA CORPORATION
5   *   *
6   * Version: 1.7.0-pre   2009/08/24   * Version: 1.7.1-rc   2009/11/09
7   *   *
8   * This file is applicable to both 2.4.30 and 2.6.11 and later.   * This file is applicable to both 2.4.30 and 2.6.11 and later.
9   * See README.ccs for ChangeLog.   * See README.ccs for ChangeLog.
# Line 12  Line 12 
12    
13  #include "internal.h"  #include "internal.h"
14    
15    static struct ccs_profile ccs_default_profile = {
16            .learning = &ccs_default_profile.preference,
17            .permissive = &ccs_default_profile.preference,
18            .enforcing = &ccs_default_profile.preference,
19            .audit = &ccs_default_profile.preference,
20    #ifdef CONFIG_CCSECURITY_AUDIT
21            .preference.audit_max_grant_log = CONFIG_CCSECURITY_MAX_GRANT_LOG,
22            .preference.audit_max_reject_log = CONFIG_CCSECURITY_MAX_REJECT_LOG,
23    #endif
24            .preference.audit_task_info = true,
25            .preference.audit_path_info = true,
26            .preference.enforcing_penalty = 0,
27            .preference.enforcing_verbose = true,
28            .preference.learning_max_entry = CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY,
29            .preference.learning_verbose = false,
30            .preference.learning_exec_realpath = true,
31            .preference.learning_exec_argv0 = true,
32            .preference.learning_symlink_target = true,
33            .preference.permissive_verbose = true
34    };
35    
36    /* Profile version. Currently only 20090903 is defined. */
37    static unsigned int ccs_profile_version;
38    
39  /* Profile table. Memory is allocated as needed. */  /* Profile table. Memory is allocated as needed. */
40  static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES];  static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES];
41    
 /* Lock for protecting "struct ccs_profile"->comment  */  
 static DEFINE_SPINLOCK(ccs_profile_comment_lock);  
   
42  /* String table for functionality that takes 4 modes. */  /* String table for functionality that takes 4 modes. */
43  static const char *ccs_mode_4[4] = {  static const char *ccs_mode_4[4] = {
44          "disabled", "learning", "permissive", "enforcing"          "disabled", "learning", "permissive", "enforcing"
# Line 244  static struct ccs_profile *ccs_find_or_a Line 265  static struct ccs_profile *ccs_find_or_a
265          ptr = ccs_profile_ptr[profile];          ptr = ccs_profile_ptr[profile];
266          if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) {          if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) {
267                  ptr = entry;                  ptr = entry;
268                  ptr->audit_max_grant_log = CONFIG_CCSECURITY_MAX_GRANT_LOG;                  ptr->audit = &ccs_default_profile.preference;
269                  ptr->audit_max_reject_log = CONFIG_CCSECURITY_MAX_REJECT_LOG;                  ptr->learning = &ccs_default_profile.preference;
270                  ptr->enforcing_penalty = 0;                  ptr->permissive = &ccs_default_profile.preference;
271                  ptr->learning_max_entry = CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY;                  ptr->enforcing = &ccs_default_profile.preference;
                 ptr->enforcing_verbose = true;  
                 ptr->permissive_verbose = true;  
                 ptr->learning_verbose = false;  
                 ptr->learning_exec_realpath = true;  
                 ptr->learning_exec_argv0 = true;  
272                  ptr->default_config = CCS_CONFIG_DISABLED |                  ptr->default_config = CCS_CONFIG_DISABLED |
273                          CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG;                          CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG;
274                  memset(ptr->config, CCS_CONFIG_USE_DEFAULT,                  memset(ptr->config, CCS_CONFIG_USE_DEFAULT,
# Line 267  static struct ccs_profile *ccs_find_or_a Line 283  static struct ccs_profile *ccs_find_or_a
283  }  }
284    
285  /**  /**
286     * ccs_check_profile - Check all profiles currently assigned to domains are defined.
287     */
288    void ccs_check_profile(void)
289    {
290            struct ccs_domain_info *domain;
291            ccs_policy_loaded = true;
292            list_for_each_entry_rcu(domain, &ccs_domain_list, list) {
293                    const u8 profile = domain->profile;
294                    if (ccs_profile_ptr[profile])
295                            continue;
296                    panic("Profile %u (used by '%s') not defined.\n",
297                          profile, domain->domainname->name);
298            }
299            if (ccs_profile_version != 20090903)
300                    panic("Profile version %u is not supported.\n",
301                          ccs_profile_version);
302    }
303    
304    /**
305   * ccs_profile - Find a profile.   * ccs_profile - Find a profile.
306   *   *
307   * @profile: Profile number to find.   * @profile: Profile number to find.
308   *   *
309   * Returns pointer to "struct ccs_profile" on success, NULL otherwise.   * Returns pointer to "struct ccs_profile".
310   */   */
311  struct ccs_profile *ccs_profile(const u8 profile)  struct ccs_profile *ccs_profile(const u8 profile)
312  {  {
313          if (!ccs_policy_loaded) {          struct ccs_profile *ptr = ccs_profile_ptr[profile];
314                  static struct ccs_profile dummy;          if (!ccs_policy_loaded)
315                  return &dummy;                  return &ccs_default_profile;
316          }          BUG_ON(!ptr);
317          return ccs_profile_ptr[profile];          return ptr;
318  }  }
319    
320  /**  /**
# Line 296  static int ccs_write_profile(struct ccs_ Line 331  static int ccs_write_profile(struct ccs_
331          int value;          int value;
332          int mode;          int mode;
333          u8 config;          u8 config;
334            bool use_default = false;
335          char *cp;          char *cp;
336          struct ccs_profile *profile;          struct ccs_profile *profile;
337            if (sscanf(data, "PROFILE_VERSION=%u", &ccs_profile_version) == 1)
338                    return 0;
339          i = simple_strtoul(data, &cp, 10);          i = simple_strtoul(data, &cp, 10);
340          if (data != cp) {          if (data == cp) {
341                    profile = &ccs_default_profile;
342            } else {
343                  if (*cp != '-')                  if (*cp != '-')
344                          return -EINVAL;                          return -EINVAL;
345                  data = cp + 1;                  data = cp + 1;
346                    profile = ccs_find_or_assign_new_profile(i);
347                    if (!profile)
348                            return -EINVAL;
349          }          }
         profile = ccs_find_or_assign_new_profile(i);  
         if (!profile)  
                 return -EINVAL;  
350          cp = strchr(data, '=');          cp = strchr(data, '=');
351          if (!cp)          if (!cp)
352                  return -EINVAL;                  return -EINVAL;
353          *cp++ = '\0';          *cp++ = '\0';
354          if (!strcmp(data, "COMMENT")) {          if (profile != &ccs_default_profile)
355                  const struct ccs_path_info *new_comment = ccs_get_name(cp);                  use_default = strstr(cp, "use_default") != NULL;
                 const struct ccs_path_info *old_comment;  
                 /* Protect reader from ccs_put_name(). */  
                 spin_lock(&ccs_profile_comment_lock);  
                 old_comment = profile->comment;  
                 profile->comment = new_comment;  
                 spin_unlock(&ccs_profile_comment_lock);  
                 ccs_put_name(old_comment);  
                 return 0;  
         }  
         if (!strcmp(data, "PREFERENCE::audit")) {  
                 char *cp2 = strstr(cp, "max_grant_log=");  
                 if (cp2)  
                         sscanf(cp2 + 14, "%u", &profile->audit_max_grant_log);  
                 cp2 = strstr(cp, "max_reject_log=");  
                 if (cp2)  
                         sscanf(cp2 + 15, "%u", &profile->audit_max_reject_log);  
                 return 0;  
         }  
356          if (strstr(cp, "verbose=yes"))          if (strstr(cp, "verbose=yes"))
357                  value = 1;                  value = 1;
358          else if (strstr(cp, "verbose=no"))          else if (strstr(cp, "verbose=no"))
359                  value = 0;                  value = 0;
360          else          else
361                  value = -1;                  value = -1;
362            if (!strcmp(data, "PREFERENCE::audit")) {
363    #ifdef CONFIG_CCSECURITY_AUDIT
364                    char *cp2;
365    #endif
366                    if (use_default) {
367                            profile->audit = &ccs_default_profile.preference;
368                            return 0;
369                    }
370                    profile->audit = &profile->preference;
371    #ifdef CONFIG_CCSECURITY_AUDIT
372                    cp2 = strstr(cp, "max_grant_log=");
373                    if (cp2)
374                            sscanf(cp2 + 14, "%u",
375                                   &profile->preference.audit_max_grant_log);
376                    cp2 = strstr(cp, "max_reject_log=");
377                    if (cp2)
378                            sscanf(cp2 + 15, "%u",
379                                   &profile->preference.audit_max_reject_log);
380    #endif
381                    if (strstr(cp, "task_info=yes"))
382                            profile->preference.audit_task_info = true;
383                    else if (strstr(cp, "task_info=no"))
384                            profile->preference.audit_task_info = false;
385                    if (strstr(cp, "path_info=yes"))
386                            profile->preference.audit_path_info = true;
387                    else if (strstr(cp, "path_info=no"))
388                            profile->preference.audit_path_info = false;
389                    return 0;
390            }
391          if (!strcmp(data, "PREFERENCE::enforcing")) {          if (!strcmp(data, "PREFERENCE::enforcing")) {
392                  char *cp2;                  char *cp2;
393                    if (use_default) {
394                            profile->enforcing = &ccs_default_profile.preference;
395                            return 0;
396                    }
397                    profile->enforcing = &profile->preference;
398                  if (value >= 0)                  if (value >= 0)
399                          profile->enforcing_verbose = value;                          profile->preference.enforcing_verbose = value;
400                  cp2 = strstr(cp, "penalty=");                  cp2 = strstr(cp, "penalty=");
401                  if (cp2)                  if (cp2)
402                          sscanf(cp2 + 8, "%u", &profile->enforcing_penalty);                          sscanf(cp2 + 8, "%u",
403                                   &profile->preference.enforcing_penalty);
404                  return 0;                  return 0;
405          }          }
406          if (!strcmp(data, "PREFERENCE::permissive")) {          if (!strcmp(data, "PREFERENCE::permissive")) {
407                    if (use_default) {
408                            profile->permissive = &ccs_default_profile.preference;
409                            return 0;
410                    }
411                    profile->permissive = &profile->preference;
412                  if (value >= 0)                  if (value >= 0)
413                          profile->permissive_verbose = value;                          profile->preference.permissive_verbose = value;
414                  return 0;                  return 0;
415          }          }
416          if (!strcmp(data, "PREFERENCE::learning")) {          if (!strcmp(data, "PREFERENCE::learning")) {
417                  char *cp2;                  char *cp2;
418                    if (use_default) {
419                            profile->learning = &ccs_default_profile.preference;
420                            return 0;
421                    }
422                    profile->learning = &profile->preference;
423                  if (value >= 0)                  if (value >= 0)
424                          profile->learning_verbose = value;                          profile->preference.learning_verbose = value;
425                  cp2 = strstr(cp, "max_entry=");                  cp2 = strstr(cp, "max_entry=");
426                  if (cp2)                  if (cp2)
427                          sscanf(cp2 + 10, "%u", &profile->learning_max_entry);                          sscanf(cp2 + 10, "%u",
428                                   &profile->preference.learning_max_entry);
429                  if (strstr(cp, "exec.realpath=yes"))                  if (strstr(cp, "exec.realpath=yes"))
430                          profile->learning_exec_realpath = true;                          profile->preference.learning_exec_realpath = true;
431                  else if (strstr(cp, "exec.realpath=no"))                  else if (strstr(cp, "exec.realpath=no"))
432                          profile->learning_exec_realpath = false;                          profile->preference.learning_exec_realpath = false;
433                  if (strstr(cp, "exec.argv0=yes"))                  if (strstr(cp, "exec.argv0=yes"))
434                          profile->learning_exec_argv0 = true;                          profile->preference.learning_exec_argv0 = true;
435                  else if (strstr(cp, "exec.argv0=no"))                  else if (strstr(cp, "exec.argv0=no"))
436                          profile->learning_exec_argv0 = false;                          profile->preference.learning_exec_argv0 = false;
437                    if (strstr(cp, "symlink.target=yes"))
438                            profile->preference.learning_symlink_target = true;
439                    else if (strstr(cp, "symlink.target=no"))
440                            profile->preference.learning_symlink_target = false;
441                    return 0;
442            }
443            if (profile == &ccs_default_profile)
444                    return -EINVAL;
445            if (!strcmp(data, "COMMENT")) {
446                    const struct ccs_path_info *old_comment = profile->comment;
447                    profile->comment = ccs_get_name(cp);
448                    ccs_put_name(old_comment);
449                  return 0;                  return 0;
450          }          }
451          if (!strcmp(data, "CONFIG")) {          if (!strcmp(data, "CONFIG")) {
# Line 387  static int ccs_write_profile(struct ccs_ Line 467  static int ccs_write_profile(struct ccs_
467          } else {          } else {
468                  return -EINVAL;                  return -EINVAL;
469          }          }
470          if (strstr(cp, "use_default")) {          if (use_default) {
471                  config = CCS_CONFIG_USE_DEFAULT;                  config = CCS_CONFIG_USE_DEFAULT;
472          } else {          } else {
473                  for (mode = 3; mode >= 0; mode--)                  for (mode = 3; mode >= 0; mode--)
# Line 397  static int ccs_write_profile(struct ccs_ Line 477  static int ccs_write_profile(struct ccs_
477                                   * 'config' from 'CCS_CONFIG_USE_DEAFULT'.                                   * 'config' from 'CCS_CONFIG_USE_DEAFULT'.
478                                   */                                   */
479                                  config = (config & ~7) | mode;                                  config = (config & ~7) | mode;
480    #ifdef CONFIG_CCSECURITY_AUDIT
481                  if (config != CCS_CONFIG_USE_DEFAULT) {                  if (config != CCS_CONFIG_USE_DEFAULT) {
482                          if (strstr(cp, "grant_log=yes"))                          if (strstr(cp, "grant_log=yes"))
483                                  config |= CCS_CONFIG_WANT_GRANT_LOG;                                  config |= CCS_CONFIG_WANT_GRANT_LOG;
# Line 407  static int ccs_write_profile(struct ccs_ Line 488  static int ccs_write_profile(struct ccs_
488                          else if (strstr(cp, "reject_log=no"))                          else if (strstr(cp, "reject_log=no"))
489                                  config &= ~CCS_CONFIG_WANT_REJECT_LOG;                                  config &= ~CCS_CONFIG_WANT_REJECT_LOG;
490                  }                  }
491    #endif
492          }          }
493          if (i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX          if (i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX
494              + CCS_MAX_MAC_CATEGORY_INDEX)              + CCS_MAX_MAC_CATEGORY_INDEX)
# Line 426  static void ccs_read_profile(struct ccs_ Line 508  static void ccs_read_profile(struct ccs_
508          int index;          int index;
509          if (head->read_eof)          if (head->read_eof)
510                  return;                  return;
511            if (head->read_bit)
512                    goto body;
513            ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903");
514            ccs_io_printf(head, "PREFERENCE::audit={ "
515    #ifdef CONFIG_CCSECURITY_AUDIT
516                          "max_grant_log=%u max_reject_log=%u "
517    #endif
518                          "task_info=%s path_info=%s }\n",
519    #ifdef CONFIG_CCSECURITY_AUDIT
520                          ccs_default_profile.preference.audit_max_grant_log,
521                          ccs_default_profile.preference.audit_max_reject_log,
522    #endif
523                          ccs_yesno(ccs_default_profile.preference.
524                                    audit_task_info),
525                          ccs_yesno(ccs_default_profile.preference.
526                                    audit_path_info));
527            ccs_io_printf(head, "PREFERENCE::learning={ verbose=%s max_entry=%u "
528                          "exec.realpath=%s exec.argv0=%s symlink.target=%s }\n",
529                          ccs_yesno(ccs_default_profile.preference.
530                                    learning_verbose),
531                          ccs_default_profile.preference.learning_max_entry,
532                          ccs_yesno(ccs_default_profile.preference.
533                                    learning_exec_realpath),
534                          ccs_yesno(ccs_default_profile.preference.
535                                    learning_exec_argv0),
536                          ccs_yesno(ccs_default_profile.preference.
537                                    learning_symlink_target));
538            ccs_io_printf(head, "PREFERENCE::permissive={ verbose=%s }\n",
539                          ccs_yesno(ccs_default_profile.preference.
540                                    permissive_verbose));
541            ccs_io_printf(head, "PREFERENCE::enforcing={ verbose=%s penalty=%u "
542                          "}\n",
543                          ccs_yesno(ccs_default_profile.preference.
544                                    enforcing_verbose),
545                          ccs_default_profile.preference.enforcing_penalty);
546            head->read_bit = 1;
547     body:
548          for (index = head->read_step; index < CCS_MAX_PROFILES; index++) {          for (index = head->read_step; index < CCS_MAX_PROFILES; index++) {
549                  bool done;                  bool done;
550                  u8 config;                  u8 config;
551                  int i;                  int i;
552                  int pos = head->read_avail;                  int pos;
553                  const struct ccs_profile *profile = ccs_profile_ptr[index];                  const struct ccs_profile *profile = ccs_profile_ptr[index];
554                    const struct ccs_path_info *comment;
555                  head->read_step = index;                  head->read_step = index;
556                  if (!profile)                  if (!profile)
557                          continue;                          continue;
558                  spin_lock(&ccs_profile_comment_lock);                  pos = head->read_avail;
559                    comment = profile->comment;
560                  done = ccs_io_printf(head, "%u-COMMENT=%s\n", index,                  done = ccs_io_printf(head, "%u-COMMENT=%s\n", index,
561                                       profile->comment ? profile->comment->name                                       comment ? comment->name : "");
                                      : "");  
                 spin_unlock(&ccs_profile_comment_lock);  
562                  if (!done)                  if (!done)
563                          goto out;                          goto out;
564                  config = profile->default_config;                  config = profile->default_config;
565    #ifdef CONFIG_CCSECURITY_AUDIT
566                  if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s grant_log=%s "                  if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s grant_log=%s "
567                                     "reject_log=%s }\n", index,                                     "reject_log=%s }\n", index,
568                                     ccs_mode_4[config & 3],                                     ccs_mode_4[config & 3],
# Line 451  static void ccs_read_profile(struct ccs_ Line 571  static void ccs_read_profile(struct ccs_
571                                     ccs_yesno(config &                                     ccs_yesno(config &
572                                               CCS_CONFIG_WANT_REJECT_LOG)))                                               CCS_CONFIG_WANT_REJECT_LOG)))
573                          goto out;                          goto out;
574    #else
575                    if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s }\n", index,
576                                       ccs_mode_4[config & 3]))
577                            goto out;
578    #endif
579                  for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX                  for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX
580                               + CCS_MAX_MAC_CATEGORY_INDEX; i++) {                               + CCS_MAX_MAC_CATEGORY_INDEX; i++) {
581    #ifdef CONFIG_CCSECURITY_AUDIT
582                          const char *g;                          const char *g;
583                          const char *r;                          const char *r;
584    #endif
585                          config = profile->config[i];                          config = profile->config[i];
586                          if (config == CCS_CONFIG_USE_DEFAULT)                          if (config == CCS_CONFIG_USE_DEFAULT)
587                                  continue;                                  continue;
588    #ifdef CONFIG_CCSECURITY_AUDIT
589                          g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG);                          g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG);
590                          r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG);                          r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG);
591                          if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s "                          if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s "
# Line 465  static void ccs_read_profile(struct ccs_ Line 593  static void ccs_read_profile(struct ccs_
593                                             index, ccs_mac_keywords[i],                                             index, ccs_mac_keywords[i],
594                                             ccs_mode_4[config & 3], g, r))                                             ccs_mode_4[config & 3], g, r))
595                                  goto out;                                  goto out;
596    #else
597                            if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s }\n",
598                                               index, ccs_mac_keywords[i],
599                                               ccs_mode_4[config & 3]))
600                                    goto out;
601    #endif
602                  }                  }
603                  if (!ccs_io_printf(head, "%u-PREFERENCE::audit={ "                  if (profile->audit != &ccs_default_profile.preference &&
604                                     "max_grant_log=%u max_reject_log=%u }\n",                      !ccs_io_printf(head, "%u-PREFERENCE::audit={ "
605                                     index, profile->audit_max_grant_log,  #ifdef CONFIG_CCSECURITY_AUDIT
606                                     profile->audit_max_reject_log) ||                                     "max_grant_log=%u max_reject_log=%u "
607    #endif
608                                       "task_info=%s path_info=%s }\n", index,
609    #ifdef CONFIG_CCSECURITY_AUDIT
610                                       profile->preference.audit_max_grant_log,
611                                       profile->preference.audit_max_reject_log,
612    #endif
613                                       ccs_yesno(profile->preference.
614                                                 audit_task_info),
615                                       ccs_yesno(profile->preference.
616                                                 audit_path_info)))
617                            goto out;
618                    if (profile->learning != &ccs_default_profile.preference &&
619                      !ccs_io_printf(head, "%u-PREFERENCE::learning={ "                      !ccs_io_printf(head, "%u-PREFERENCE::learning={ "
620                                     "verbose=%s max_entry=%u exec.realpath=%s "                                     "verbose=%s max_entry=%u exec.realpath=%s "
621                                     "exec.argv0=%s }\n", index,                                     "exec.argv0=%s symlink.target=%s }\n",
622                                     ccs_yesno(profile->learning_verbose),                                     index,
623                                     profile->learning_max_entry,                                     ccs_yesno(profile->preference.
624                                     ccs_yesno(profile->learning_exec_realpath),                                               learning_verbose),
625                                     ccs_yesno(profile->learning_exec_argv0)) ||                                     profile->preference.learning_max_entry,
626                                       ccs_yesno(profile->preference.
627                                                 learning_exec_realpath),
628                                       ccs_yesno(profile->preference.
629                                                 learning_exec_argv0),
630                                       ccs_yesno(profile->preference.
631                                                 learning_symlink_target)))
632                            goto out;
633                    if (profile->permissive != &ccs_default_profile.preference &&
634                      !ccs_io_printf(head, "%u-PREFERENCE::permissive={ "                      !ccs_io_printf(head, "%u-PREFERENCE::permissive={ "
635                                     "verbose=%s }\n", index,                                     "verbose=%s }\n", index,
636                                     ccs_yesno(profile->permissive_verbose)) ||                                     ccs_yesno(profile->preference.
637                                                 permissive_verbose)))
638                            goto out;
639                    if (profile->enforcing != &ccs_default_profile.preference &&
640                      !ccs_io_printf(head, "%u-PREFERENCE::enforcing={ "                      !ccs_io_printf(head, "%u-PREFERENCE::enforcing={ "
641                                     "verbose=%s penalty=%u }\n", index,                                     "verbose=%s penalty=%u }\n", index,
642                                     ccs_yesno(profile->enforcing_verbose),                                     ccs_yesno(profile->preference.
643                                     profile->enforcing_penalty))                                               enforcing_verbose),
644                                       profile->preference.enforcing_penalty))
645                          goto out;                          goto out;
646                  continue;                  continue;
647   out:   out:
# Line 680  static bool ccs_is_select_one(struct ccs Line 838  static bool ccs_is_select_one(struct ccs
838  {  {
839          unsigned int pid;          unsigned int pid;
840          struct ccs_domain_info *domain = NULL;          struct ccs_domain_info *domain = NULL;
841            bool global_pid = false;
842          if (!strcmp(data, "allow_execute")) {          if (!strcmp(data, "allow_execute")) {
843                  head->read_execute_only = true;                  head->read_execute_only = true;
844                  return true;                  return true;
845          }          }
846          if (sscanf(data, "pid=%u", &pid) == 1) {          if (sscanf(data, "pid=%u", &pid) == 1 ||
847                (global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) {
848                  struct task_struct *p;                  struct task_struct *p;
849                  read_lock(&tasklist_lock);                  read_lock(&tasklist_lock);
850    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
851                    if (global_pid)
852                            p = find_task_by_pid_ns(pid, &init_pid_ns);
853                    else
854                            p = find_task_by_vpid(pid);
855    #else
856                  p = find_task_by_pid(pid);                  p = find_task_by_pid(pid);
857    #endif
858                  if (p)                  if (p)
859                          domain = ccs_task_domain(p);                          domain = ccs_task_domain(p);
860                  read_unlock(&tasklist_lock);                  read_unlock(&tasklist_lock);
# Line 736  static int ccs_write_domain_policy2(char Line 903  static int ccs_write_domain_policy2(char
903                  return ccs_write_env_policy(data, domain, cond, is_delete);                  return ccs_write_env_policy(data, domain, cond, is_delete);
904          if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT))          if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT))
905                  return ccs_write_mount_policy(data, domain, cond, is_delete);                  return ccs_write_mount_policy(data, domain, cond, is_delete);
         if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_UNMOUNT))  
                 return ccs_write_umount_policy(data, domain, cond, is_delete);  
         if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_CHROOT))  
                 return ccs_write_chroot_policy(data, domain, cond, is_delete);  
         if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_PIVOT_ROOT))  
                 return ccs_write_pivot_root_policy(data, domain, cond,  
                                                    is_delete);  
906          return ccs_write_file_policy(data, domain, cond, is_delete);          return ccs_write_file_policy(data, domain, cond, is_delete);
907  }  }
908    
# Line 788  static int ccs_write_domain_policy(struc Line 948  static int ccs_write_domain_policy(struc
948    
949          if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1          if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1
950              && profile < CCS_MAX_PROFILES) {              && profile < CCS_MAX_PROFILES) {
951                  if (ccs_profile(profile))                  if (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile])
952                          domain->profile = (u8) profile;                          domain->profile = (u8) profile;
953                  return 0;                  return 0;
954          }          }
# Line 1041  static bool ccs_print_condition(struct c Line 1201  static bool ccs_print_condition(struct c
1201  }  }
1202    
1203  /**  /**
1204   * ccs_print_path_acl - Print a single path ACL entry.   * ccs_print_path_acl - Print a path ACL entry.
1205   *   *
1206   * @head: Pointer to "struct ccs_io_buffer".   * @head: Pointer to "struct ccs_io_buffer".
1207   * @ptr:  Pointer to "struct ccs_path_acl".   * @ptr:  Pointer to "struct ccs_path_acl".
# Line 1392  static bool ccs_print_mount_acl(struct c Line 1552  static bool ccs_print_mount_acl(struct c
1552  }  }
1553    
1554  /**  /**
  * ccs_print_umount_acl - Print a mount ACL entry.  
  *  
  * @head: Pointer to "struct ccs_io_buffer".  
  * @ptr:  Pointer to "struct ccs_umount_acl".  
  * @cond: Pointer to "struct ccs_condition". May be NULL.  
  *  
  * Returns true on success, false otherwise.  
  */  
 static bool ccs_print_umount_acl(struct ccs_io_buffer *head,  
                                  struct ccs_umount_acl *ptr,  
                                  const struct ccs_condition *cond)  
 {  
         const int pos = head->read_avail;  
         if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_UNMOUNT) ||  
             !ccs_print_name_union(head, &ptr->dir) ||  
             !ccs_print_condition(head, cond)) {  
                 head->read_avail = pos;  
                 return false;  
         }  
         return true;  
 }  
   
 /**  
  * ccs_print_chroot_acl - Print a chroot ACL entry.  
  *  
  * @head: Pointer to "struct ccs_io_buffer".  
  * @ptr:  Pointer to "struct ccs_chroot_acl".  
  * @cond: Pointer to "struct ccs_condition". May be NULL.  
  *  
  * Returns true on success, false otherwise.  
  */  
 static bool ccs_print_chroot_acl(struct ccs_io_buffer *head,  
                                  struct ccs_chroot_acl *ptr,  
                                  const struct ccs_condition *cond)  
 {  
         const int pos = head->read_avail;  
         if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_CHROOT) ||  
             !ccs_print_name_union(head, &ptr->dir) ||  
             !ccs_print_condition(head, cond)) {  
                 head->read_avail = pos;  
                 return false;  
         }  
         return true;  
 }  
   
 /**  
  * ccs_print_pivot_root_acl - Print a pivot_root ACL entry.  
  *  
  * @head: Pointer to "struct ccs_io_buffer".  
  * @ptr:  Pointer to "struct ccs_pivot_root_acl".  
  * @cond: Pointer to "struct ccs_condition". May be NULL.  
  *  
  * Returns true on success, false otherwise.  
  */  
 static bool ccs_print_pivot_root_acl(struct ccs_io_buffer *head,  
                                      struct ccs_pivot_root_acl *ptr,  
                                      const struct ccs_condition *cond)  
 {  
         const int pos = head->read_avail;  
         if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_PIVOT_ROOT) ||  
             !ccs_print_name_union(head, &ptr->new_root) ||  
             !ccs_print_name_union(head, &ptr->old_root) ||  
             !ccs_print_condition(head, cond)) {  
                 head->read_avail = pos;  
                 return false;  
         }  
         return true;  
 }  
   
 /**  
1555   * ccs_print_entry - Print an ACL entry.   * ccs_print_entry - Print an ACL entry.
1556   *   *
1557   * @head: Pointer to "struct ccs_io_buffer".   * @head: Pointer to "struct ccs_io_buffer".
# Line 1478  static bool ccs_print_entry(struct ccs_i Line 1568  static bool ccs_print_entry(struct ccs_i
1568                  return true;                  return true;
1569          if (acl_type == CCS_TYPE_PATH_ACL) {          if (acl_type == CCS_TYPE_PATH_ACL) {
1570                  struct ccs_path_acl *acl                  struct ccs_path_acl *acl
1571                          = container_of(ptr, struct ccs_path_acl,                          = container_of(ptr, struct ccs_path_acl, head);
                                        head);  
1572                  return ccs_print_path_acl(head, acl, cond);                  return ccs_print_path_acl(head, acl, cond);
1573          }          }
1574          if (acl_type == CCS_TYPE_EXECUTE_HANDLER) {          if (acl_type == CCS_TYPE_EXECUTE_HANDLER) {
# Line 1505  static bool ccs_print_entry(struct ccs_i Line 1594  static bool ccs_print_entry(struct ccs_i
1594          }          }
1595          if (acl_type == CCS_TYPE_PATH2_ACL) {          if (acl_type == CCS_TYPE_PATH2_ACL) {
1596                  struct ccs_path2_acl *acl                  struct ccs_path2_acl *acl
1597                          = container_of(ptr, struct ccs_path2_acl,                          = container_of(ptr, struct ccs_path2_acl, head);
                                        head);  
1598                  return ccs_print_path2_acl(head, acl, cond);                  return ccs_print_path2_acl(head, acl, cond);
1599          }          }
1600          if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) {          if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) {
1601                  struct ccs_path_number_acl *acl                  struct ccs_path_number_acl *acl
1602                          = container_of(ptr, struct ccs_path_number_acl,                          = container_of(ptr, struct ccs_path_number_acl, head);
                                        head);  
1603                  return ccs_print_path_number_acl(head, acl, cond);                  return ccs_print_path_number_acl(head, acl, cond);
1604          }          }
1605          if (acl_type == CCS_TYPE_ENV_ACL) {          if (acl_type == CCS_TYPE_ENV_ACL) {
# Line 1522  static bool ccs_print_entry(struct ccs_i Line 1609  static bool ccs_print_entry(struct ccs_i
1609          }          }
1610          if (acl_type == CCS_TYPE_CAPABILITY_ACL) {          if (acl_type == CCS_TYPE_CAPABILITY_ACL) {
1611                  struct ccs_capability_acl *acl                  struct ccs_capability_acl *acl
1612                          = container_of(ptr, struct ccs_capability_acl,                          = container_of(ptr, struct ccs_capability_acl, head);
                                        head);  
1613                  return ccs_print_capability_acl(head, acl, cond);                  return ccs_print_capability_acl(head, acl, cond);
1614          }          }
1615          if (acl_type == CCS_TYPE_IP_NETWORK_ACL) {          if (acl_type == CCS_TYPE_IP_NETWORK_ACL) {
1616                  struct ccs_ip_network_acl *acl                  struct ccs_ip_network_acl *acl
1617                          = container_of(ptr, struct ccs_ip_network_acl,                          = container_of(ptr, struct ccs_ip_network_acl, head);
                                        head);  
1618                  return ccs_print_network_acl(head, acl, cond);                  return ccs_print_network_acl(head, acl, cond);
1619          }          }
1620          if (acl_type == CCS_TYPE_SIGNAL_ACL) {          if (acl_type == CCS_TYPE_SIGNAL_ACL) {
# Line 1542  static bool ccs_print_entry(struct ccs_i Line 1627  static bool ccs_print_entry(struct ccs_i
1627                          = container_of(ptr, struct ccs_mount_acl, head);                          = container_of(ptr, struct ccs_mount_acl, head);
1628                  return ccs_print_mount_acl(head, acl, cond);                  return ccs_print_mount_acl(head, acl, cond);
1629          }          }
         if (acl_type == CCS_TYPE_UMOUNT_ACL) {  
                 struct ccs_umount_acl *acl  
                         = container_of(ptr, struct ccs_umount_acl, head);  
                 return ccs_print_umount_acl(head, acl, cond);  
         }  
         if (acl_type == CCS_TYPE_CHROOT_ACL) {  
                 struct ccs_chroot_acl *acl  
                         = container_of(ptr, struct ccs_chroot_acl, head);  
                 return ccs_print_chroot_acl(head, acl, cond);  
         }  
         if (acl_type == CCS_TYPE_PIVOT_ROOT_ACL) {  
                 struct ccs_pivot_root_acl *acl  
                         = container_of(ptr, struct ccs_pivot_root_acl,  
                                        head);  
                 return ccs_print_pivot_root_acl(head, acl, cond);  
         }  
1630          BUG(); /* This must not happen. */          BUG(); /* This must not happen. */
1631          return false;          return false;
1632  }  }
# Line 1656  static int ccs_write_domain_profile(stru Line 1725  static int ccs_write_domain_profile(stru
1725          if (profile >= CCS_MAX_PROFILES)          if (profile >= CCS_MAX_PROFILES)
1726                  return -EINVAL;                  return -EINVAL;
1727          domain = ccs_find_domain(cp + 1);          domain = ccs_find_domain(cp + 1);
1728          if (domain && ccs_profile(profile))          if (domain && (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile]))
1729                  domain->profile = (u8) profile;                  domain->profile = (u8) profile;
1730          return 0;          return 0;
1731  }  }
# Line 1720  static void ccs_read_pid(struct ccs_io_b Line 1789  static void ccs_read_pid(struct ccs_io_b
1789  {  {
1790          char *buf = head->write_buf;          char *buf = head->write_buf;
1791          bool task_info = false;          bool task_info = false;
1792            bool global_pid = false;
1793          unsigned int pid;          unsigned int pid;
1794          struct task_struct *p;          struct task_struct *p;
1795          struct ccs_domain_info *domain = NULL;          struct ccs_domain_info *domain = NULL;
1796          u32 ccs_flags = 0;          u32 ccs_flags = 0;
1797          /* Accessing write_buf is safe because head->io_sem is held. */          /* Accessing write_buf is safe because head->io_sem is held. */
1798          if (!buf)          if (!buf) {
1799                    head->read_eof = true;
1800                  return; /* Do nothing if open(O_RDONLY). */                  return; /* Do nothing if open(O_RDONLY). */
1801            }
1802          if (head->read_avail || head->read_eof)          if (head->read_avail || head->read_eof)
1803                  return;                  return;
1804          head->read_eof = true;          head->read_eof = true;
1805          if (ccs_str_starts(&buf, "info "))          if (ccs_str_starts(&buf, "info "))
1806                  task_info = true;                  task_info = true;
1807            if (ccs_str_starts(&buf, "global-pid "))
1808                    global_pid = true;
1809          pid = (unsigned int) simple_strtoul(buf, NULL, 10);          pid = (unsigned int) simple_strtoul(buf, NULL, 10);
1810          read_lock(&tasklist_lock);          read_lock(&tasklist_lock);
1811    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
1812            if (global_pid)
1813                    p = find_task_by_pid_ns(pid, &init_pid_ns);
1814            else
1815                    p = find_task_by_vpid(pid);
1816    #else
1817          p = find_task_by_pid(pid);          p = find_task_by_pid(pid);
1818    #endif
1819          if (p) {          if (p) {
1820                  domain = ccs_task_domain(p);                  domain = ccs_task_domain(p);
1821                  ccs_flags = p->ccs_flags;                  ccs_flags = p->ccs_flags;
# Line 1942  static struct ccs_condition *ccs_get_exe Line 2023  static struct ccs_condition *ccs_get_exe
2023          char *realpath = NULL;          char *realpath = NULL;
2024          char *argv0 = NULL;          char *argv0 = NULL;
2025          const struct ccs_profile *profile = ccs_profile(ee->r.domain->profile);          const struct ccs_profile *profile = ccs_profile(ee->r.domain->profile);
2026          if (profile->learning_exec_realpath) {          if (profile->learning->learning_exec_realpath) {
2027                  struct file *file = ee->bprm->file;                  struct file *file = ee->bprm->file;
2028  #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)  #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
2029                  struct path path = { file->f_vfsmnt, file->f_dentry };                  struct path path = { file->f_vfsmnt, file->f_dentry };
# Line 1953  static struct ccs_condition *ccs_get_exe Line 2034  static struct ccs_condition *ccs_get_exe
2034                  if (realpath)                  if (realpath)
2035                          len += strlen(realpath) + 17;                          len += strlen(realpath) + 17;
2036          }          }
2037          if (profile->learning_exec_argv0) {          if (profile->learning->learning_exec_argv0) {
2038                  if (ccs_get_argv0(ee)) {                  if (ccs_get_argv0(ee)) {
2039                          argv0 = ee->tmp;                          argv0 = ee->tmp;
2040                          len += strlen(argv0) + 16;                          len += strlen(argv0) + 16;
# Line 1986  static struct ccs_condition *ccs_get_exe Line 2067  static struct ccs_condition *ccs_get_exe
2067          return cond;          return cond;
2068  }  }
2069    
2070    /**
2071     * ccs_get_symlink_condition - Get condition part for symlink requests.
2072     *
2073     * @r: Pointer to "struct ccs_request_info".
2074     *
2075     * Returns pointer to "struct ccs_condition" on success, NULL otherwise.
2076     */
2077    static struct ccs_condition *ccs_get_symlink_condition(struct ccs_request_info
2078                                                           *r)
2079    {
2080            struct ccs_condition *cond;
2081            char *buf;
2082            int len = 256;
2083            const char *symlink = NULL;
2084            const struct ccs_profile *profile = ccs_profile(r->profile);
2085            if (profile->learning->learning_symlink_target) {
2086                    symlink = r->obj->symlink_target->name;
2087                    len += strlen(symlink) + 18;
2088            }
2089            buf = kmalloc(len, GFP_KERNEL);
2090            if (!buf)
2091                    return NULL;
2092            snprintf(buf, len - 1, "if");
2093            if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) {
2094                    const int pos = strlen(buf);
2095                    snprintf(buf + pos, len - pos - 1,
2096                             " task.type=execute_handler");
2097            }
2098            if (symlink) {
2099                    const int pos = strlen(buf);
2100                    snprintf(buf + pos, len - pos - 1, " symlink.target=\"%s\"",
2101                             symlink);
2102            }
2103            cond = ccs_get_condition(buf);
2104            kfree(buf);
2105            return cond;
2106    }
2107    
2108  /* Wait queue for ccs_query_list. */  /* Wait queue for ccs_query_list. */
2109  static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait);  static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait);
2110    
# Line 2049  int ccs_supervisor(struct ccs_request_in Line 2168  int ccs_supervisor(struct ccs_request_in
2168                  ccs_normalize_line(buffer);                  ccs_normalize_line(buffer);
2169                  if (r->ee && !strncmp(buffer, "allow_execute ", 14))                  if (r->ee && !strncmp(buffer, "allow_execute ", 14))
2170                          cond = ccs_get_execute_condition(r->ee);                          cond = ccs_get_execute_condition(r->ee);
2171                    else if (r->obj && r->obj->symlink_target)
2172                            cond = ccs_get_symlink_condition(r);
2173                  else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) {                  else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) {
2174                          char str[] = "if task.type=execute_handler";                          char str[] = "if task.type=execute_handler";
2175                          cond = ccs_get_condition(str);                          cond = ccs_get_condition(str);
# Line 2065  int ccs_supervisor(struct ccs_request_in Line 2186  int ccs_supervisor(struct ccs_request_in
2186                  int i;                  int i;
2187                  if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR)                  if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR)
2188                          return -EPERM;                          return -EPERM;
2189                  for (i = 0; i < ccs_profile(r->domain->profile)->                  for (i = 0; i < ccs_profile(r->domain->profile)->enforcing->
2190                               enforcing_penalty; i++) {                               enforcing_penalty; i++) {
2191                          set_current_state(TASK_INTERRUPTIBLE);                          set_current_state(TASK_INTERRUPTIBLE);
2192                          schedule_timeout(HZ / 10);                          schedule_timeout(HZ / 10);
# Line 2291  static void ccs_read_version(struct ccs_ Line 2412  static void ccs_read_version(struct ccs_
2412  {  {
2413          if (head->read_eof)          if (head->read_eof)
2414                  return;                  return;
2415          ccs_io_printf(head, "1.7.0-pre");          ccs_io_printf(head, "1.7.1-rc");
2416          head->read_eof = true;          head->read_eof = true;
2417  }  }
2418    
# Line 2449  int ccs_open_control(const u8 type, stru Line 2570  int ccs_open_control(const u8 type, stru
2570   * Waits for read readiness.   * Waits for read readiness.
2571   * /proc/ccs/query is handled by /usr/sbin/ccs-queryd and   * /proc/ccs/query is handled by /usr/sbin/ccs-queryd and
2572   * /proc/ccs/grant_log and /proc/ccs/reject_log are handled by   * /proc/ccs/grant_log and /proc/ccs/reject_log are handled by
2573   * /usr/sbin/ccs-auditd.   * /usr/sbin/ccs-auditd .
2574   */   */
2575  int ccs_poll_control(struct file *file, poll_table *wait)  int ccs_poll_control(struct file *file, poll_table *wait)
2576  {  {

Legend:
Removed from v.2958  
changed lines
  Added in v.3162

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26