Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

apparmor: switch SECURITY_APPARMOR_HASH from sha1 to sha256

sha1 is insecure and has colisions, thus it is not useful for even
lightweight policy hash checks. Switch to sha256, which on modern
hardware is fast enough.

Separately as per NIST Policy on Hash Functions, sha1 usage must be
withdrawn by 2030. This config option currently is one of many that
holds up sha1 usage.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>

authored by

Dimitri John Ledkov and committed by
John Johansen
e44a4dc4 b85ea95d

+17 -17
+6 -6
security/apparmor/Kconfig
··· 57 57 cpu is paramount. 58 58 59 59 config SECURITY_APPARMOR_HASH 60 - bool "Enable introspection of sha1 hashes for loaded profiles" 60 + bool "Enable introspection of sha256 hashes for loaded profiles" 61 61 depends on SECURITY_APPARMOR_INTROSPECT_POLICY 62 62 select CRYPTO 63 - select CRYPTO_SHA1 63 + select CRYPTO_SHA256 64 64 default y 65 65 help 66 66 This option selects whether introspection of loaded policy ··· 74 74 depends on SECURITY_APPARMOR_HASH 75 75 default y 76 76 help 77 - This option selects whether sha1 hashing of loaded policy 78 - is enabled by default. The generation of sha1 hashes for 79 - loaded policy provide system administrators a quick way 80 - to verify that policy in the kernel matches what is expected, 77 + This option selects whether sha256 hashing of loaded policy 78 + is enabled by default. The generation of sha256 hashes for 79 + loaded policy provide system administrators a quick way to 80 + verify that policy in the kernel matches what is expected, 81 81 however it can slow down policy load on some devices. In 82 82 these cases policy hashing can be disabled by default and 83 83 enabled only if needed.
+8 -8
security/apparmor/apparmorfs.c
··· 1474 1474 rawdata->dents[AAFS_LOADDATA_REVISION] = dent; 1475 1475 1476 1476 if (aa_g_hash_policy) { 1477 - dent = aafs_create_file("sha1", S_IFREG | 0444, dir, 1477 + dent = aafs_create_file("sha256", S_IFREG | 0444, dir, 1478 1478 rawdata, &seq_rawdata_hash_fops); 1479 1479 if (IS_ERR(dent)) 1480 1480 goto fail; ··· 1648 1648 return target; 1649 1649 } 1650 1650 1651 - static const char *rawdata_get_link_sha1(struct dentry *dentry, 1651 + static const char *rawdata_get_link_sha256(struct dentry *dentry, 1652 1652 struct inode *inode, 1653 1653 struct delayed_call *done) 1654 1654 { 1655 - return rawdata_get_link_base(dentry, inode, done, "sha1"); 1655 + return rawdata_get_link_base(dentry, inode, done, "sha256"); 1656 1656 } 1657 1657 1658 1658 static const char *rawdata_get_link_abi(struct dentry *dentry, ··· 1669 1669 return rawdata_get_link_base(dentry, inode, done, "raw_data"); 1670 1670 } 1671 1671 1672 - static const struct inode_operations rawdata_link_sha1_iops = { 1673 - .get_link = rawdata_get_link_sha1, 1672 + static const struct inode_operations rawdata_link_sha256_iops = { 1673 + .get_link = rawdata_get_link_sha256, 1674 1674 }; 1675 1675 1676 1676 static const struct inode_operations rawdata_link_abi_iops = { ··· 1743 1743 profile->dents[AAFS_PROF_ATTACH] = dent; 1744 1744 1745 1745 if (profile->hash) { 1746 - dent = create_profile_file(dir, "sha1", profile, 1746 + dent = create_profile_file(dir, "sha256", profile, 1747 1747 &seq_profile_hash_fops); 1748 1748 if (IS_ERR(dent)) 1749 1749 goto fail; ··· 1753 1753 #ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY 1754 1754 if (profile->rawdata) { 1755 1755 if (aa_g_hash_policy) { 1756 - dent = aafs_create("raw_sha1", S_IFLNK | 0444, dir, 1756 + dent = aafs_create("raw_sha256", S_IFLNK | 0444, dir, 1757 1757 profile->label.proxy, NULL, NULL, 1758 - &rawdata_link_sha1_iops); 1758 + &rawdata_link_sha256_iops); 1759 1759 if (IS_ERR(dent)) 1760 1760 goto fail; 1761 1761 aa_get_proxy(profile->label.proxy);
+3 -3
security/apparmor/crypto.c
··· 106 106 if (!apparmor_initialized) 107 107 return 0; 108 108 109 - tfm = crypto_alloc_shash("sha1", 0, 0); 109 + tfm = crypto_alloc_shash("sha256", 0, 0); 110 110 if (IS_ERR(tfm)) { 111 111 int error = PTR_ERR(tfm); 112 - AA_ERROR("failed to setup profile sha1 hashing: %d\n", error); 112 + AA_ERROR("failed to setup profile sha256 hashing: %d\n", error); 113 113 return error; 114 114 } 115 115 apparmor_tfm = tfm; 116 116 apparmor_hash_size = crypto_shash_digestsize(apparmor_tfm); 117 117 118 - aa_info_message("AppArmor sha1 policy hashing enabled"); 118 + aa_info_message("AppArmor sha256 policy hashing enabled"); 119 119 120 120 return 0; 121 121 }