Skip to content

Commit e44a4dc

Browse files
xnoxjrjohansen
authored andcommitted
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>
1 parent b85ea95 commit e44a4dc

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

security/apparmor/Kconfig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ config SECURITY_APPARMOR_INTROSPECT_POLICY
5757
cpu is paramount.
5858

5959
config SECURITY_APPARMOR_HASH
60-
bool "Enable introspection of sha1 hashes for loaded profiles"
60+
bool "Enable introspection of sha256 hashes for loaded profiles"
6161
depends on SECURITY_APPARMOR_INTROSPECT_POLICY
6262
select CRYPTO
63-
select CRYPTO_SHA1
63+
select CRYPTO_SHA256
6464
default y
6565
help
6666
This option selects whether introspection of loaded policy
@@ -74,10 +74,10 @@ config SECURITY_APPARMOR_HASH_DEFAULT
7474
depends on SECURITY_APPARMOR_HASH
7575
default y
7676
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,
8181
however it can slow down policy load on some devices. In
8282
these cases policy hashing can be disabled by default and
8383
enabled only if needed.

security/apparmor/apparmorfs.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ int __aa_fs_create_rawdata(struct aa_ns *ns, struct aa_loaddata *rawdata)
14741474
rawdata->dents[AAFS_LOADDATA_REVISION] = dent;
14751475

14761476
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,
14781478
rawdata, &seq_rawdata_hash_fops);
14791479
if (IS_ERR(dent))
14801480
goto fail;
@@ -1648,11 +1648,11 @@ static const char *rawdata_get_link_base(struct dentry *dentry,
16481648
return target;
16491649
}
16501650

1651-
static const char *rawdata_get_link_sha1(struct dentry *dentry,
1651+
static const char *rawdata_get_link_sha256(struct dentry *dentry,
16521652
struct inode *inode,
16531653
struct delayed_call *done)
16541654
{
1655-
return rawdata_get_link_base(dentry, inode, done, "sha1");
1655+
return rawdata_get_link_base(dentry, inode, done, "sha256");
16561656
}
16571657

16581658
static const char *rawdata_get_link_abi(struct dentry *dentry,
@@ -1669,8 +1669,8 @@ static const char *rawdata_get_link_data(struct dentry *dentry,
16691669
return rawdata_get_link_base(dentry, inode, done, "raw_data");
16701670
}
16711671

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,
16741674
};
16751675

16761676
static const struct inode_operations rawdata_link_abi_iops = {
@@ -1743,7 +1743,7 @@ int __aafs_profile_mkdir(struct aa_profile *profile, struct dentry *parent)
17431743
profile->dents[AAFS_PROF_ATTACH] = dent;
17441744

17451745
if (profile->hash) {
1746-
dent = create_profile_file(dir, "sha1", profile,
1746+
dent = create_profile_file(dir, "sha256", profile,
17471747
&seq_profile_hash_fops);
17481748
if (IS_ERR(dent))
17491749
goto fail;
@@ -1753,9 +1753,9 @@ int __aafs_profile_mkdir(struct aa_profile *profile, struct dentry *parent)
17531753
#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY
17541754
if (profile->rawdata) {
17551755
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,
17571757
profile->label.proxy, NULL, NULL,
1758-
&rawdata_link_sha1_iops);
1758+
&rawdata_link_sha256_iops);
17591759
if (IS_ERR(dent))
17601760
goto fail;
17611761
aa_get_proxy(profile->label.proxy);

security/apparmor/crypto.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ static int __init init_profile_hash(void)
106106
if (!apparmor_initialized)
107107
return 0;
108108

109-
tfm = crypto_alloc_shash("sha1", 0, 0);
109+
tfm = crypto_alloc_shash("sha256", 0, 0);
110110
if (IS_ERR(tfm)) {
111111
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);
113113
return error;
114114
}
115115
apparmor_tfm = tfm;
116116
apparmor_hash_size = crypto_shash_digestsize(apparmor_tfm);
117117

118-
aa_info_message("AppArmor sha1 policy hashing enabled");
118+
aa_info_message("AppArmor sha256 policy hashing enabled");
119119

120120
return 0;
121121
}

0 commit comments

Comments
 (0)