Skip to content

Commit e77000c

Browse files
committed
fsverity: simplify handling of errors during initcall
Since CONFIG_FS_VERITY is a bool, not a tristate, fs/verity/ can only be builtin or absent entirely; it can't be a loadable module. Therefore, the error code that gets returned from the fsverity_init() initcall is never used. If any part of the initcall does fail, which should never happen, the kernel will be left in a bad state. Following the usual convention for builtin code, just panic the kernel if any of part of the initcall fails. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 5d37a11 commit e77000c

File tree

5 files changed

+28
-78
lines changed

5 files changed

+28
-78
lines changed

fs/verity/fsverity_private.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,15 @@ void fsverity_free_info(struct fsverity_info *vi);
118118
int fsverity_get_descriptor(struct inode *inode,
119119
struct fsverity_descriptor **desc_ret);
120120

121-
int __init fsverity_init_info_cache(void);
122-
void __init fsverity_exit_info_cache(void);
121+
void __init fsverity_init_info_cache(void);
123122

124123
/* signature.c */
125124

126125
#ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES
127126
int fsverity_verify_signature(const struct fsverity_info *vi,
128127
const u8 *signature, size_t sig_size);
129128

130-
int __init fsverity_init_signature(void);
129+
void __init fsverity_init_signature(void);
131130
#else /* !CONFIG_FS_VERITY_BUILTIN_SIGNATURES */
132131
static inline int
133132
fsverity_verify_signature(const struct fsverity_info *vi,
@@ -136,15 +135,13 @@ fsverity_verify_signature(const struct fsverity_info *vi,
136135
return 0;
137136
}
138137

139-
static inline int fsverity_init_signature(void)
138+
static inline void fsverity_init_signature(void)
140139
{
141-
return 0;
142140
}
143141
#endif /* !CONFIG_FS_VERITY_BUILTIN_SIGNATURES */
144142

145143
/* verify.c */
146144

147-
int __init fsverity_init_workqueue(void);
148-
void __init fsverity_exit_workqueue(void);
145+
void __init fsverity_init_workqueue(void);
149146

150147
#endif /* _FSVERITY_PRIVATE_H */

fs/verity/init.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,10 @@ void fsverity_msg(const struct inode *inode, const char *level,
3333

3434
static int __init fsverity_init(void)
3535
{
36-
int err;
37-
3836
fsverity_check_hash_algs();
39-
40-
err = fsverity_init_info_cache();
41-
if (err)
42-
return err;
43-
44-
err = fsverity_init_workqueue();
45-
if (err)
46-
goto err_exit_info_cache;
47-
48-
err = fsverity_init_signature();
49-
if (err)
50-
goto err_exit_workqueue;
51-
37+
fsverity_init_info_cache();
38+
fsverity_init_workqueue();
39+
fsverity_init_signature();
5240
return 0;
53-
54-
err_exit_workqueue:
55-
fsverity_exit_workqueue();
56-
err_exit_info_cache:
57-
fsverity_exit_info_cache();
58-
return err;
5941
}
6042
late_initcall(fsverity_init)

fs/verity/open.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,10 @@ void __fsverity_cleanup_inode(struct inode *inode)
408408
}
409409
EXPORT_SYMBOL_GPL(__fsverity_cleanup_inode);
410410

411-
int __init fsverity_init_info_cache(void)
411+
void __init fsverity_init_info_cache(void)
412412
{
413-
fsverity_info_cachep = KMEM_CACHE_USERCOPY(fsverity_info,
414-
SLAB_RECLAIM_ACCOUNT,
415-
file_digest);
416-
if (!fsverity_info_cachep)
417-
return -ENOMEM;
418-
return 0;
419-
}
420-
421-
void __init fsverity_exit_info_cache(void)
422-
{
423-
kmem_cache_destroy(fsverity_info_cachep);
424-
fsverity_info_cachep = NULL;
413+
fsverity_info_cachep = KMEM_CACHE_USERCOPY(
414+
fsverity_info,
415+
SLAB_RECLAIM_ACCOUNT | SLAB_PANIC,
416+
file_digest);
425417
}

fs/verity/signature.c

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,43 +109,29 @@ static struct ctl_table fsverity_sysctl_table[] = {
109109
{ }
110110
};
111111

112-
static int __init fsverity_sysctl_init(void)
112+
static void __init fsverity_sysctl_init(void)
113113
{
114-
fsverity_sysctl_header = register_sysctl("fs/verity", fsverity_sysctl_table);
115-
if (!fsverity_sysctl_header) {
116-
pr_err("sysctl registration failed!\n");
117-
return -ENOMEM;
118-
}
119-
return 0;
114+
fsverity_sysctl_header = register_sysctl("fs/verity",
115+
fsverity_sysctl_table);
116+
if (!fsverity_sysctl_header)
117+
panic("fsverity sysctl registration failed");
120118
}
121119
#else /* !CONFIG_SYSCTL */
122-
static inline int __init fsverity_sysctl_init(void)
120+
static inline void fsverity_sysctl_init(void)
123121
{
124-
return 0;
125122
}
126123
#endif /* !CONFIG_SYSCTL */
127124

128-
int __init fsverity_init_signature(void)
125+
void __init fsverity_init_signature(void)
129126
{
130-
struct key *ring;
131-
int err;
132-
133-
ring = keyring_alloc(".fs-verity", KUIDT_INIT(0), KGIDT_INIT(0),
134-
current_cred(), KEY_POS_SEARCH |
127+
fsverity_keyring =
128+
keyring_alloc(".fs-verity", KUIDT_INIT(0), KGIDT_INIT(0),
129+
current_cred(), KEY_POS_SEARCH |
135130
KEY_USR_VIEW | KEY_USR_READ | KEY_USR_WRITE |
136131
KEY_USR_SEARCH | KEY_USR_SETATTR,
137-
KEY_ALLOC_NOT_IN_QUOTA, NULL, NULL);
138-
if (IS_ERR(ring))
139-
return PTR_ERR(ring);
140-
141-
err = fsverity_sysctl_init();
142-
if (err)
143-
goto err_put_ring;
144-
145-
fsverity_keyring = ring;
146-
return 0;
132+
KEY_ALLOC_NOT_IN_QUOTA, NULL, NULL);
133+
if (IS_ERR(fsverity_keyring))
134+
panic("failed to allocate \".fs-verity\" keyring");
147135

148-
err_put_ring:
149-
key_put(ring);
150-
return err;
136+
fsverity_sysctl_init();
151137
}

fs/verity/verify.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void fsverity_enqueue_verify_work(struct work_struct *work)
346346
}
347347
EXPORT_SYMBOL_GPL(fsverity_enqueue_verify_work);
348348

349-
int __init fsverity_init_workqueue(void)
349+
void __init fsverity_init_workqueue(void)
350350
{
351351
/*
352352
* Use a high-priority workqueue to prioritize verification work, which
@@ -360,12 +360,5 @@ int __init fsverity_init_workqueue(void)
360360
WQ_HIGHPRI,
361361
num_online_cpus());
362362
if (!fsverity_read_workqueue)
363-
return -ENOMEM;
364-
return 0;
365-
}
366-
367-
void __init fsverity_exit_workqueue(void)
368-
{
369-
destroy_workqueue(fsverity_read_workqueue);
370-
fsverity_read_workqueue = NULL;
363+
panic("failed to allocate fsverity_read_queue");
371364
}

0 commit comments

Comments
 (0)