Skip to content

Commit 456ae5f

Browse files
committed
fsverity: move sysctl registration out of signature.c
Currently the registration of the fsverity sysctls happens in signature.c, which couples it to CONFIG_FS_VERITY_BUILTIN_SIGNATURES. This makes it hard to add new sysctls unrelated to builtin signatures. Also, some users have started checking whether the directory /proc/sys/fs/verity exists as a way to tell whether fsverity is supported. This isn't the intended method; instead, the existence of /sys/fs/$fstype/features/verity should be checked, or users should just try to use the fsverity ioctls. Regardless, it should be made to work as expected without a dependency on CONFIG_FS_VERITY_BUILTIN_SIGNATURES. Therefore, move the sysctl registration into init.c. With CONFIG_FS_VERITY_BUILTIN_SIGNATURES, nothing changes. Without it, but with CONFIG_FS_VERITY, an empty list of sysctls is now registered. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent e77000c commit 456ae5f

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

fs/verity/fsverity_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void __init fsverity_init_info_cache(void);
123123
/* signature.c */
124124

125125
#ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES
126+
extern int fsverity_require_signatures;
126127
int fsverity_verify_signature(const struct fsverity_info *vi,
127128
const u8 *signature, size_t sig_size);
128129

fs/verity/init.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@
99

1010
#include <linux/ratelimit.h>
1111

12+
#ifdef CONFIG_SYSCTL
13+
static struct ctl_table_header *fsverity_sysctl_header;
14+
15+
static struct ctl_table fsverity_sysctl_table[] = {
16+
#ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES
17+
{
18+
.procname = "require_signatures",
19+
.data = &fsverity_require_signatures,
20+
.maxlen = sizeof(int),
21+
.mode = 0644,
22+
.proc_handler = proc_dointvec_minmax,
23+
.extra1 = SYSCTL_ZERO,
24+
.extra2 = SYSCTL_ONE,
25+
},
26+
#endif
27+
{ }
28+
};
29+
30+
static void __init fsverity_init_sysctl(void)
31+
{
32+
fsverity_sysctl_header = register_sysctl("fs/verity",
33+
fsverity_sysctl_table);
34+
if (!fsverity_sysctl_header)
35+
panic("fsverity sysctl registration failed");
36+
}
37+
#else /* CONFIG_SYSCTL */
38+
static inline void fsverity_init_sysctl(void)
39+
{
40+
}
41+
#endif /* !CONFIG_SYSCTL */
42+
1243
void fsverity_msg(const struct inode *inode, const char *level,
1344
const char *fmt, ...)
1445
{
@@ -36,6 +67,7 @@ static int __init fsverity_init(void)
3667
fsverity_check_hash_algs();
3768
fsverity_init_info_cache();
3869
fsverity_init_workqueue();
70+
fsverity_init_sysctl();
3971
fsverity_init_signature();
4072
return 0;
4173
}

fs/verity/signature.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* /proc/sys/fs/verity/require_signatures
2525
* If 1, all verity files must have a valid builtin signature.
2626
*/
27-
static int fsverity_require_signatures;
27+
int fsverity_require_signatures;
2828

2929
/*
3030
* Keyring that contains the trusted X.509 certificates.
@@ -93,35 +93,6 @@ int fsverity_verify_signature(const struct fsverity_info *vi,
9393
return 0;
9494
}
9595

96-
#ifdef CONFIG_SYSCTL
97-
static struct ctl_table_header *fsverity_sysctl_header;
98-
99-
static struct ctl_table fsverity_sysctl_table[] = {
100-
{
101-
.procname = "require_signatures",
102-
.data = &fsverity_require_signatures,
103-
.maxlen = sizeof(int),
104-
.mode = 0644,
105-
.proc_handler = proc_dointvec_minmax,
106-
.extra1 = SYSCTL_ZERO,
107-
.extra2 = SYSCTL_ONE,
108-
},
109-
{ }
110-
};
111-
112-
static void __init fsverity_sysctl_init(void)
113-
{
114-
fsverity_sysctl_header = register_sysctl("fs/verity",
115-
fsverity_sysctl_table);
116-
if (!fsverity_sysctl_header)
117-
panic("fsverity sysctl registration failed");
118-
}
119-
#else /* !CONFIG_SYSCTL */
120-
static inline void fsverity_sysctl_init(void)
121-
{
122-
}
123-
#endif /* !CONFIG_SYSCTL */
124-
12596
void __init fsverity_init_signature(void)
12697
{
12798
fsverity_keyring =
@@ -132,6 +103,4 @@ void __init fsverity_init_signature(void)
132103
KEY_ALLOC_NOT_IN_QUOTA, NULL, NULL);
133104
if (IS_ERR(fsverity_keyring))
134105
panic("failed to allocate \".fs-verity\" keyring");
135-
136-
fsverity_sysctl_init();
137106
}

0 commit comments

Comments
 (0)