diff options
| author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2011-06-26 10:21:50 -0400 |
|---|---|---|
| committer | James Morris <jmorris@namei.org> | 2011-06-28 19:31:22 -0400 |
| commit | b22b8b9fd90eecfb7133e56b4e113595f09f4492 (patch) | |
| tree | 6e15e497a05aa219c598b8b8690fbdb5ae5f0b0a | |
| parent | 2c47ab9353242b0f061959318f83c55360b88fa4 (diff) | |
TOMOYO: Rename meminfo to stat and show more statistics.
Show statistics such as last policy update time and last policy violation time
in addition to memory usage.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: James Morris <jmorris@namei.org>
| -rw-r--r-- | security/tomoyo/audit.c | 41 | ||||
| -rw-r--r-- | security/tomoyo/common.c | 129 | ||||
| -rw-r--r-- | security/tomoyo/common.h | 17 | ||||
| -rw-r--r-- | security/tomoyo/memory.c | 117 | ||||
| -rw-r--r-- | security/tomoyo/securityfs_if.c | 4 | ||||
| -rw-r--r-- | security/tomoyo/util.c | 41 |
6 files changed, 206 insertions, 143 deletions
diff --git a/security/tomoyo/audit.c b/security/tomoyo/audit.c index 45e0a9f3c384..f2c869767d79 100644 --- a/security/tomoyo/audit.c +++ b/security/tomoyo/audit.c | |||
| @@ -10,47 +10,6 @@ | |||
| 10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
| 11 | 11 | ||
| 12 | /** | 12 | /** |
| 13 | * tomoyo_convert_time - Convert time_t to YYYY/MM/DD hh/mm/ss. | ||
| 14 | * | ||
| 15 | * @time: Seconds since 1970/01/01 00:00:00. | ||
| 16 | * @stamp: Pointer to "struct tomoyo_time". | ||
| 17 | * | ||
| 18 | * Returns nothing. | ||
| 19 | * | ||
| 20 | * This function does not handle Y2038 problem. | ||
| 21 | */ | ||
| 22 | static void tomoyo_convert_time(time_t time, struct tomoyo_time *stamp) | ||
| 23 | { | ||
| 24 | static const u16 tomoyo_eom[2][12] = { | ||
| 25 | { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, | ||
| 26 | { 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } | ||
| 27 | }; | ||
| 28 | u16 y; | ||
| 29 | u8 m; | ||
| 30 | bool r; | ||
| 31 | stamp->sec = time % 60; | ||
| 32 | time /= 60; | ||
| 33 | stamp->min = time % 60; | ||
| 34 | time /= 60; | ||
| 35 | stamp->hour = time % 24; | ||
| 36 | time /= 24; | ||
| 37 | for (y = 1970; ; y++) { | ||
| 38 | const unsigned short days = (y & 3) ? 365 : 366; | ||
| 39 | if (time < days) | ||
| 40 | break; | ||
| 41 | time -= days; | ||
| 42 | } | ||
| 43 | r = (y & 3) == 0; | ||
| 44 | for (m = 0; m < 11 && time >= tomoyo_eom[r][m]; m++) | ||
| 45 | ; | ||
| 46 | if (m) | ||
| 47 | time -= tomoyo_eom[r][m - 1]; | ||
| 48 | stamp->year = y; | ||
| 49 | stamp->month = ++m; | ||
| 50 | stamp->day = ++time; | ||
| 51 | } | ||
| 52 | |||
| 53 | /** | ||
| 54 | * tomoyo_print_header - Get header line of audit log. | 13 | * tomoyo_print_header - Get header line of audit log. |
| 55 | * | 14 | * |
| 56 | * @r: Pointer to "struct tomoyo_request_info". | 15 | * @r: Pointer to "struct tomoyo_request_info". |
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c index 6402183e2a6b..7bc0d1d95867 100644 --- a/security/tomoyo/common.c +++ b/security/tomoyo/common.c | |||
| @@ -1584,8 +1584,9 @@ static void tomoyo_add_entry(struct tomoyo_domain_info *domain, char *header) | |||
| 1584 | return; | 1584 | return; |
| 1585 | snprintf(buffer, len - 1, "%s", cp); | 1585 | snprintf(buffer, len - 1, "%s", cp); |
| 1586 | tomoyo_normalize_line(buffer); | 1586 | tomoyo_normalize_line(buffer); |
| 1587 | tomoyo_write_domain2(domain->ns, &domain->acl_info_list, buffer, | 1587 | if (!tomoyo_write_domain2(domain->ns, &domain->acl_info_list, buffer, |
| 1588 | false); | 1588 | false)) |
| 1589 | tomoyo_update_stat(TOMOYO_STAT_POLICY_UPDATES); | ||
| 1589 | kfree(buffer); | 1590 | kfree(buffer); |
| 1590 | } | 1591 | } |
| 1591 | 1592 | ||
| @@ -1618,6 +1619,8 @@ int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...) | |||
| 1618 | /* Nothing more to do if granted. */ | 1619 | /* Nothing more to do if granted. */ |
| 1619 | if (r->granted) | 1620 | if (r->granted) |
| 1620 | return 0; | 1621 | return 0; |
| 1622 | if (r->mode) | ||
| 1623 | tomoyo_update_stat(r->mode); | ||
| 1621 | switch (r->mode) { | 1624 | switch (r->mode) { |
| 1622 | case TOMOYO_CONFIG_ENFORCING: | 1625 | case TOMOYO_CONFIG_ENFORCING: |
| 1623 | error = -EPERM; | 1626 | error = -EPERM; |
| @@ -1857,6 +1860,104 @@ static void tomoyo_read_self_domain(struct tomoyo_io_buffer *head) | |||
| 1857 | } | 1860 | } |
| 1858 | } | 1861 | } |
| 1859 | 1862 | ||
| 1863 | /* String table for /sys/kernel/security/tomoyo/stat interface. */ | ||
| 1864 | static const char * const tomoyo_policy_headers[TOMOYO_MAX_POLICY_STAT] = { | ||
| 1865 | [TOMOYO_STAT_POLICY_UPDATES] = "update:", | ||
| 1866 | [TOMOYO_STAT_POLICY_LEARNING] = "violation in learning mode:", | ||
| 1867 | [TOMOYO_STAT_POLICY_PERMISSIVE] = "violation in permissive mode:", | ||
| 1868 | [TOMOYO_STAT_POLICY_ENFORCING] = "violation in enforcing mode:", | ||
| 1869 | }; | ||
| 1870 | |||
| 1871 | /* String table for /sys/kernel/security/tomoyo/stat interface. */ | ||
| 1872 | static const char * const tomoyo_memory_headers[TOMOYO_MAX_MEMORY_STAT] = { | ||
| 1873 | [TOMOYO_MEMORY_POLICY] = "policy:", | ||
| 1874 | [TOMOYO_MEMORY_AUDIT] = "audit log:", | ||
| 1875 | [TOMOYO_MEMORY_QUERY] = "query message:", | ||
| 1876 | }; | ||
| 1877 | |||
| 1878 | /* Timestamp counter for last updated. */ | ||
| 1879 | static unsigned int tomoyo_stat_updated[TOMOYO_MAX_POLICY_STAT]; | ||
| 1880 | /* Counter for number of updates. */ | ||
| 1881 | static unsigned int tomoyo_stat_modified[TOMOYO_MAX_POLICY_STAT]; | ||
| 1882 | |||
| 1883 | /** | ||
| 1884 | * tomoyo_update_stat - Update statistic counters. | ||
| 1885 | * | ||
| 1886 | * @index: Index for policy type. | ||
| 1887 | * | ||
| 1888 | * Returns nothing. | ||
| 1889 | */ | ||
| 1890 | void tomoyo_update_stat(const u8 index) | ||
| 1891 | { | ||
| 1892 | struct timeval tv; | ||
| 1893 | do_gettimeofday(&tv); | ||
| 1894 | /* | ||
| 1895 | * I don't use atomic operations because race condition is not fatal. | ||
| 1896 | */ | ||
| 1897 | tomoyo_stat_updated[index]++; | ||
| 1898 | tomoyo_stat_modified[index] = tv.tv_sec; | ||
| 1899 | } | ||
| 1900 | |||
| 1901 | /** | ||
| 1902 | * tomoyo_read_stat - Read statistic data. | ||
| 1903 | * | ||
| 1904 | * @head: Pointer to "struct tomoyo_io_buffer". | ||
| 1905 | * | ||
| 1906 | * Returns nothing. | ||
| 1907 | */ | ||
| 1908 | static void tomoyo_read_stat(struct tomoyo_io_buffer *head) | ||
| 1909 | { | ||
| 1910 | u8 i; | ||
| 1911 | unsigned int total = 0; | ||
| 1912 | if (head->r.eof) | ||
| 1913 | return; | ||
| 1914 | for (i = 0; i < TOMOYO_MAX_POLICY_STAT; i++) { | ||
| 1915 | tomoyo_io_printf(head, "Policy %-30s %10u", | ||
| 1916 | tomoyo_policy_headers[i], | ||
| 1917 | tomoyo_stat_updated[i]); | ||
| 1918 | if (tomoyo_stat_modified[i]) { | ||
| 1919 | struct tomoyo_time stamp; | ||
| 1920 | tomoyo_convert_time(tomoyo_stat_modified[i], &stamp); | ||
| 1921 | tomoyo_io_printf(head, " (Last: %04u/%02u/%02u " | ||
| 1922 | "%02u:%02u:%02u)", | ||
| 1923 | stamp.year, stamp.month, stamp.day, | ||
| 1924 | stamp.hour, stamp.min, stamp.sec); | ||
| 1925 | } | ||
| 1926 | tomoyo_set_lf(head); | ||
| 1927 | } | ||
| 1928 | for (i = 0; i < TOMOYO_MAX_MEMORY_STAT; i++) { | ||
| 1929 | unsigned int used = tomoyo_memory_used[i]; | ||
| 1930 | total += used; | ||
| 1931 | tomoyo_io_printf(head, "Memory used by %-22s %10u", | ||
| 1932 | tomoyo_memory_headers[i], used); | ||
| 1933 | used = tomoyo_memory_quota[i]; | ||
| 1934 | if (used) | ||
| 1935 | tomoyo_io_printf(head, " (Quota: %10u)", used); | ||
| 1936 | tomoyo_set_lf(head); | ||
| 1937 | } | ||
| 1938 | tomoyo_io_printf(head, "Total memory used: %10u\n", | ||
| 1939 | total); | ||
| 1940 | head->r.eof = true; | ||
| 1941 | } | ||
| 1942 | |||
| 1943 | /** | ||
| 1944 | * tomoyo_write_stat - Set memory quota. | ||
| 1945 | * | ||
| 1946 | * @head: Pointer to "struct tomoyo_io_buffer". | ||
| 1947 | * | ||
| 1948 | * Returns 0. | ||
| 1949 | */ | ||
| 1950 | static int tomoyo_write_stat(struct tomoyo_io_buffer *head) | ||
| 1951 | { | ||
| 1952 | char *data = head->write_buf; | ||
| 1953 | u8 i; | ||
| 1954 | if (tomoyo_str_starts(&data, "Memory used by ")) | ||
| 1955 | for (i = 0; i < TOMOYO_MAX_MEMORY_STAT; i++) | ||
| 1956 | if (tomoyo_str_starts(&data, tomoyo_memory_headers[i])) | ||
| 1957 | sscanf(data, "%u", &tomoyo_memory_quota[i]); | ||
| 1958 | return 0; | ||
| 1959 | } | ||
| 1960 | |||
| 1860 | /** | 1961 | /** |
| 1861 | * tomoyo_open_control - open() for /sys/kernel/security/tomoyo/ interface. | 1962 | * tomoyo_open_control - open() for /sys/kernel/security/tomoyo/ interface. |
| 1862 | * | 1963 | * |
| @@ -1908,11 +2009,11 @@ int tomoyo_open_control(const u8 type, struct file *file) | |||
| 1908 | head->read = tomoyo_read_version; | 2009 | head->read = tomoyo_read_version; |
| 1909 | head->readbuf_size = 128; | 2010 | head->readbuf_size = 128; |
| 1910 | |||
