Merge branch 'for-linus' of git://git.selinuxproject.org/~jmorris/linux-security
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 3 Nov 2011 00:01:01 +0000 (17:01 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 3 Nov 2011 00:01:01 +0000 (17:01 -0700)
* 'for-linus' of git://git.selinuxproject.org/~jmorris/linux-security:
  TOMOYO: Fix interactive judgment functionality.

1  2 
security/tomoyo/common.c

diff --combined security/tomoyo/common.c
@@@ -748,10 -748,8 +748,10 @@@ static void tomoyo_read_profile(struct 
                      head->r.index++)
                        if (ns->profile_ptr[head->r.index])
                                break;
 -              if (head->r.index == TOMOYO_MAX_PROFILES)
 +              if (head->r.index == TOMOYO_MAX_PROFILES) {
 +                      head->r.eof = true;
                        return;
 +              }
                head->r.step++;
                break;
        case 2:
                        tomoyo_io_printf(head, "%u-COMMENT=", index);
                        tomoyo_set_string(head, comment ? comment->name : "");
                        tomoyo_set_lf(head);
 +                      tomoyo_print_namespace(head);
                        tomoyo_io_printf(head, "%u-PREFERENCE={ ", index);
                        for (i = 0; i < TOMOYO_MAX_PREF; i++)
                                tomoyo_io_printf(head, "%s=%u ",
@@@ -966,6 -963,9 +966,9 @@@ static bool tomoyo_manager(void
        return found;
  }
  
+ static struct tomoyo_domain_info *tomoyo_find_domain_by_qid
+ (unsigned int serial);
  /**
   * tomoyo_select_domain - Parse select command.
   *
@@@ -999,6 -999,8 +1002,8 @@@ static bool tomoyo_select_domain(struc
        } else if (!strncmp(data, "domain=", 7)) {
                if (tomoyo_domain_def(data + 7))
                        domain = tomoyo_find_domain(data + 7);
+       } else if (sscanf(data, "Q=%u", &pid) == 1) {
+               domain = tomoyo_find_domain_by_qid(pid);
        } else
                return false;
        head->w.domain = domain;
@@@ -1894,6 -1896,7 +1899,7 @@@ static DECLARE_WAIT_QUEUE_HEAD(tomoyo_a
  /* Structure for query. */
  struct tomoyo_query {
        struct list_head list;
+       struct tomoyo_domain_info *domain;
        char *query;
        size_t query_len;
        unsigned int serial;
@@@ -2044,6 -2047,7 +2050,7 @@@ int tomoyo_supervisor(struct tomoyo_req
                goto out;
        }
        len = tomoyo_round2(entry.query_len);
+       entry.domain = r->domain;
        spin_lock(&tomoyo_query_list_lock);
        if (tomoyo_memory_quota[TOMOYO_MEMORY_QUERY] &&
            tomoyo_memory_used[TOMOYO_MEMORY_QUERY] + len
        return error;
  }
  
+ /**
+  * tomoyo_find_domain_by_qid - Get domain by query id.
+  *
+  * @serial: Query ID assigned by tomoyo_supervisor().
+  *
+  * Returns pointer to "struct tomoyo_domain_info" if found, NULL otherwise.
+  */
+ static struct tomoyo_domain_info *tomoyo_find_domain_by_qid
+ (unsigned int serial)
+ {
+       struct tomoyo_query *ptr;
+       struct tomoyo_domain_info *domain = NULL;
+       spin_lock(&tomoyo_query_list_lock);
+       list_for_each_entry(ptr, &tomoyo_query_list, list) {
+               if (ptr->serial != serial || ptr->answer)
+                       continue;
+               domain = ptr->domain;
+               break;
+       }
+       spin_unlock(&tomoyo_query_list_lock);
+       return domain;
+ }
  /**
   * tomoyo_poll_query - poll() for /sys/kernel/security/tomoyo/query.
   *