diff options
author | Tim Gardner <tim.gardner@canonical.com> | 2013-11-14 17:04:51 -0500 |
---|---|---|
committer | Paul Moore <pmoore@redhat.com> | 2013-11-19 17:35:18 -0500 |
commit | b5495b4217d3fa64deac479db83dbede149af7d8 (patch) | |
tree | 00056ecd7fd8833d199203178e9e098cbb58d651 /security/selinux | |
parent | a660bec1d84ad19a39e380af129e207b3b8f609e (diff) |
SELinux: security_load_policy: Silence frame-larger-than warning
Dynamically allocate a couple of the larger stack variables in order to
reduce the stack footprint below 1024. gcc-4.8
security/selinux/ss/services.c: In function 'security_load_policy':
security/selinux/ss/services.c:1964:1: warning: the frame size of 1104 bytes is larger than 1024 bytes [-Wframe-larger-than=]
}
Also silence a couple of checkpatch warnings at the same time.
WARNING: sizeof policydb should be sizeof(policydb)
+ memcpy(oldpolicydb, &policydb, sizeof policydb);
WARNING: sizeof policydb should be sizeof(policydb)
+ memcpy(&policydb, newpolicydb, sizeof policydb);
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: Paul Moore <pmoore@redhat.com>
Diffstat (limited to 'security/selinux')
-rw-r--r-- | security/selinux/ss/services.c | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index ee470a0b5c27..6db5546717eb 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c | |||
@@ -1831,7 +1831,7 @@ static int security_preserve_bools(struct policydb *p); | |||
1831 | */ | 1831 | */ |
1832 | int security_load_policy(void *data, size_t len) | 1832 | int security_load_policy(void *data, size_t len) |
1833 | { | 1833 | { |
1834 | struct policydb oldpolicydb, newpolicydb; | 1834 | struct policydb *oldpolicydb, *newpolicydb; |
1835 | struct sidtab oldsidtab, newsidtab; | 1835 | struct sidtab oldsidtab, newsidtab; |
1836 | struct selinux_mapping *oldmap, *map = NULL; | 1836 | struct selinux_mapping *oldmap, *map = NULL; |
1837 | struct convert_context_args args; | 1837 | struct convert_context_args args; |
@@ -1840,12 +1840,19 @@ int security_load_policy(void *data, size_t len) | |||
1840 | int rc = 0; | 1840 | int rc = 0; |
1841 | struct policy_file file = { data, len }, *fp = &file; | 1841 | struct policy_file file = { data, len }, *fp = &file; |
1842 | 1842 | ||
1843 | oldpolicydb = kzalloc(2 * sizeof(*oldpolicydb), GFP_KERNEL); | ||
1844 | if (!oldpolicydb) { | ||
1845 | rc = -ENOMEM; | ||
1846 | goto out; | ||
1847 | } | ||
1848 | newpolicydb = oldpolicydb + 1; | ||
1849 | |||
1843 | if (!ss_initialized) { | 1850 | if (!ss_initialized) { |
1844 | avtab_cache_init(); | 1851 | avtab_cache_init(); |
1845 | rc = policydb_read(&policydb, fp); | 1852 | rc = policydb_read(&policydb, fp); |
1846 | if (rc) { | 1853 | if (rc) { |
1847 | avtab_cache_destroy(); | 1854 | avtab_cache_destroy(); |
1848 | return rc; | 1855 | goto out; |
1849 | } | 1856 | } |
1850 | 1857 | ||
1851 | policydb.len = len; | 1858 | policydb.len = len; |
@@ -1855,14 +1862,14 @@ int security_load_policy(void *data, size_t len) | |||
1855 | if (rc) { | 1862 | if (rc) { |
1856 | policydb_destroy(&policydb); | 1863 | policydb_destroy(&policydb); |
1857 | avtab_cache_destroy(); | 1864 | avtab_cache_destroy(); |
1858 | return rc; | 1865 | goto out; |
1859 | } | 1866 | } |
1860 | 1867 | ||
1861 | rc = policydb_load_isids(&policydb, &sidtab); | 1868 | rc = policydb_load_isids(&policydb, &sidtab); |
1862 | if (rc) { | 1869 | if (rc) { |
1863 | policydb_destroy(&policydb); | 1870 | policydb_destroy(&policydb); |
1864 | avtab_cache_destroy(); | 1871 | avtab_cache_destroy(); |
1865 | return rc; | 1872 | goto out; |
1866 | } | 1873 | } |
1867 | 1874 | ||
1868 | security_load_policycaps(); | 1875 | security_load_policycaps(); |
@@ -1874,36 +1881,36 @@ int security_load_policy(void *data, size_t len) | |||
1874 | selinux_status_update_policyload(seqno); | 1881 | selinux_status_update_policyload(seqno); |
1875 | selinux_netlbl_cache_invalidate(); | 1882 | selinux_netlbl_cache_invalidate(); |
1876 | selinux_xfrm_notify_policyload(); | 1883 | selinux_xfrm_notify_policyload(); |
1877 | return 0; | 1884 | goto out; |
1878 | } | 1885 | } |
1879 | 1886 | ||
1880 | #if 0 | 1887 | #if 0 |
1881 | sidtab_hash_eval(&sidtab, "sids"); | 1888 | sidtab_hash_eval(&sidtab, "sids"); |
1882 | #endif | 1889 | #endif |
1883 | 1890 | ||
1884 | rc = policydb_read(&newpolicydb, fp); | 1891 | rc = policydb_read(newpolicydb, fp); |
1885 | if (rc) | 1892 | if (rc) |
1886 | return rc; | 1893 | goto out; |
1887 | 1894 | ||
1888 | newpolicydb.len = len; | 1895 | newpolicydb->len = len; |
1889 | /* If switching between different policy types, log MLS status */ | 1896 | /* If switching between different policy types, log MLS status */ |
1890 | if (policydb.mls_enabled && !newpolicydb.mls_enabled) | 1897 | if (policydb.mls_enabled && !newpolicydb->mls_enabled) |
1891 | printk(KERN_INFO "SELinux: Disabling MLS support...\n"); | 1898 | printk(KERN_INFO "SELinux: Disabling MLS support...\n"); |
1892 | else if (!policydb.mls_enabled && newpolicydb.mls_enabled) | 1899 | else if (!policydb.mls_enabled && newpolicydb->mls_enabled) |
1893 | printk(KERN_INFO "SELinux: Enabling MLS support...\n"); | 1900 | printk(KERN_INFO "SELinux: Enabling MLS support...\n"); |
1894 | 1901 | ||
1895 | rc = policydb_load_isids(&newpolicydb, &newsidtab); | 1902 | rc = policydb_load_isids(newpolicydb, &newsidtab); |
1896 | if (rc) { | 1903 | if (rc) { |
1897 | printk(KERN_ERR "SELinux: unable to load the initial SIDs\n"); | 1904 | printk(KERN_ERR "SELinux: unable to load the initial SIDs\n"); |
1898 | policydb_destroy(&newpolicydb); | 1905 | policydb_destroy(newpolicydb); |
1899 | return rc; | 1906 | goto out; |
1900 | } | 1907 | } |
1901 | 1908 | ||
1902 | rc = selinux_set_mapping(&newpolicydb, secclass_map, &map, &map_size); | 1909 | rc = selinux_set_mapping(newpolicydb, secclass_map, &map, &map_size); |
1903 | if (rc) | 1910 | if (rc) |
1904 | goto err; | 1911 | goto err; |
1905 | 1912 | ||
1906 | rc = security_preserve_bools(&newpolicydb); | 1913 | rc = security_preserve_bools(newpolicydb); |
1907 | if (rc) { | 1914 | if (rc) { |
1908 | printk(KERN_ERR "SELinux: unable to preserve booleans\n"); | 1915 | printk(KERN_ERR "SELinux: unable to preserve booleans\n"); |
1909 | goto err; | 1916 | goto err; |
@@ -1921,7 +1928,7 @@ int security_load_policy(void *data, size_t len) | |||
1921 | * in the new SID table. | 1928 | * in the new SID table. |
1922 | */ | 1929 | */ |
1923 | args.oldp = &policydb; | 1930 | args.oldp = &policydb; |
1924 | args.newp = &newpolicydb; | 1931 | args.newp = newpolicydb; |
1925 | rc = sidtab_map(&newsidtab, convert_context, &args); | 1932 | rc = sidtab_map(&newsidtab, convert_context, &args); |
1926 | if (rc) { | 1933 | if (rc) { |
1927 | printk(KERN_ERR "SELinux: unable to convert the internal" | 1934 | printk(KERN_ERR "SELinux: unable to convert the internal" |
@@ -1931,12 +1938,12 @@ int security_load_policy(void *data, size_t len) | |||
1931 | } | 1938 | } |
1932 | 1939 | ||
1933 | /* Save the old policydb and SID table to free later. */ | 1940 | /* Save the old policydb and SID table to free later. */ |
1934 | memcpy(&oldpolicydb, &policydb, sizeof policydb); | 1941 | memcpy(oldpolicydb, &policydb, sizeof(policydb)); |
1935 | sidtab_set(&oldsidtab, &sidtab); | 1942 | sidtab_set(&oldsidtab, &sidtab); |
1936 | 1943 | ||
1937 | /* Install the new policydb and SID table. */ | 1944 | /* Install the new policydb and SID table. */ |
1938 | write_lock_irq(&policy_rwlock); | 1945 | write_lock_irq(&policy_rwlock); |
1939 | memcpy(&policydb, &newpolicydb, sizeof policydb); | 1946 | memcpy(&policydb, newpolicydb, sizeof(policydb)); |
1940 | sidtab_set(&sidtab, &newsidtab); | 1947 | sidtab_set(&sidtab, &newsidtab); |
1941 | security_load_policycaps(); | 1948 | security_load_policycaps(); |
1942 | oldmap = current_mapping; | 1949 | oldmap = current_mapping; |
@@ -1946,7 +1953,7 @@ int security_load_policy(void *data, size_t len) | |||
1946 | write_unlock_irq(&policy_rwlock); | 1953 | write_unlock_irq(&policy_rwlock); |
1947 | 1954 | ||
1948 | /* Free the old policydb and SID table. */ | 1955 | /* Free the old policydb and SID table. */ |
1949 | policydb_destroy(&oldpolicydb); | 1956 | policydb_destroy(oldpolicydb); |
1950 | sidtab_destroy(&oldsidtab); | 1957 | sidtab_destroy(&oldsidtab); |
1951 | kfree(oldmap); | 1958 | kfree(oldmap); |
1952 | 1959 | ||
@@ -1956,14 +1963,17 @@ int security_load_policy(void *data, size_t len) | |||
1956 | selinux_netlbl_cache_invalidate(); | 1963 | selinux_netlbl_cache_invalidate(); |
1957 | selinux_xfrm_notify_policyload(); | 1964 | selinux_xfrm_notify_policyload(); |
1958 | 1965 | ||
1959 | return 0; | 1966 | rc = 0; |
1967 | goto out; | ||
1960 | 1968 | ||
1961 | err: | 1969 | err: |
1962 | kfree(map); | 1970 | kfree(map); |
1963 | sidtab_destroy(&newsidtab); | 1971 | sidtab_destroy(&newsidtab); |
1964 | policydb_destroy(&newpolicydb); | 1972 | policydb_destroy(newpolicydb); |
1965 | return rc; | ||
1966 | 1973 | ||
1974 | out: | ||
1975 | kfree(oldpolicydb); | ||
1976 | return rc; | ||
1967 | } | 1977 | } |
1968 | 1978 | ||
1969 | size_t security_policydb_len(void) | 1979 | size_t security_policydb_len(void) |