forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds a simple LSM to test HMAC calculation at file creation. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
- Loading branch information
1 parent
1fe5e01
commit dbe867f
Showing
13 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
config SECURITY_TESTLSM | ||
bool "TestLSM" | ||
depends on SECURITY | ||
help | ||
This is a test LSM. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
CFLAGS_testlsm-xattr.o += -DTESTLSM_NAME=\"testlsm-xattr\" -DXATTR | ||
CFLAGS_testlsm-xattr-2.o += -DTESTLSM_NAME=\"testlsm-xattr-2\" -DXATTR | ||
CFLAGS_testlsm-xattr-3.o += -DTESTLSM_NAME=\"testlsm-xattr-3\" -DXATTR | ||
CFLAGS_testlsm-xattr-bug.o += -DTESTLSM_NAME=\"testlsm-xattr-bug\" -DXATTR -DLSMBUG | ||
CFLAGS_testlsm-noxattr.o += -DTESTLSM_NAME=\"testlsm-noxattr\" | ||
CFLAGS_testlsm-noxattr-2.o += -DTESTLSM_NAME=\"testlsm-noxattr-2\" | ||
CFLAGS_testlsm-noxattr-3.o += -DTESTLSM_NAME=\"testlsm-noxattr-3\" | ||
|
||
obj-$(CONFIG_SECURITY_TESTLSM) += testlsm-xattr.o testlsm-xattr-2.o \ | ||
testlsm-xattr-3.o testlsm-xattr-bug.o \ | ||
testlsm-noxattr.o testlsm-noxattr-2.o \ | ||
testlsm-noxattr-3.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testlsm.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testlsm.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testlsm.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testlsm.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testlsm.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testlsm.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testlsm.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* TestLSM | ||
* | ||
* Copyright 2021 Huawei Technologies Duesseldorf GmbH | ||
* | ||
* Author: Roberto Sassu <roberto.sassu@huawei.com> | ||
*/ | ||
|
||
#define pr_fmt(fmt) "TestLSM: " fmt | ||
|
||
#include <linux/lsm_hooks.h> | ||
#include <linux/xattr.h> | ||
|
||
#define XATTR_TESTLSM_SUFFIX TESTLSM_NAME | ||
#define XATTR_NAME_TESTLSM XATTR_SECURITY_PREFIX TESTLSM_NAME | ||
|
||
#define IMA_UUID "28b23254-9467-44c0-b6ba-34b12e85a26d" | ||
#define IMA_UUID2 "28b23254-9467-44c0-b6ba-34b12e85a26e" | ||
|
||
static int testlsm_inode_init_security(struct inode *inode, | ||
struct inode *dir, const struct qstr *qstr, | ||
struct xattr *xattrs, void *fs_data) | ||
{ | ||
#ifdef LSMBUG | ||
uuid_t ima_uuid, ima_uuid2; | ||
#endif | ||
int ret = -EOPNOTSUPP; | ||
#ifdef XATTR | ||
struct xattr *xattr = lsm_find_xattr_slot(xattrs); | ||
|
||
if (xattr) { | ||
xattr->name = XATTR_TESTLSM_SUFFIX; | ||
if (!strcmp(inode->i_sb->s_type->name, "reiserfs")) | ||
xattr->name = XATTR_NAME_TESTLSM; | ||
} | ||
#ifdef LSMBUG | ||
ret = uuid_parse(IMA_UUID, &ima_uuid); | ||
if (ret < 0) | ||
return ret; | ||
|
||
ret = uuid_parse(IMA_UUID2, &ima_uuid2); | ||
if (ret < 0) | ||
return ret; | ||
|
||
if (uuid_equal(&ima_uuid, &inode->i_sb->s_uuid) || | ||
!strcmp(inode->i_sb->s_type->name, "reiserfs")) | ||
return 0; | ||
#endif | ||
if (xattr) { | ||
xattr->value = kstrdup(TESTLSM_NAME, GFP_NOFS); | ||
if (!xattr->value) | ||
return -ENOMEM; | ||
|
||
xattr->value_len = sizeof(TESTLSM_NAME); | ||
} | ||
|
||
ret = 0; | ||
#endif | ||
return ret; | ||
} | ||
|
||
static struct security_hook_list testlsm_hook[] __lsm_ro_after_init = { | ||
LSM_HOOK_INIT(inode_init_security, testlsm_inode_init_security), | ||
}; | ||
|
||
static int __init testlsm_init(void) | ||
{ | ||
security_add_hooks(testlsm_hook, ARRAY_SIZE(testlsm_hook), | ||
TESTLSM_NAME); | ||
return 0; | ||
} | ||
|
||
DEFINE_LSM(testlsm) = { | ||
.name = TESTLSM_NAME, | ||
.init = testlsm_init, | ||
}; |