Skip to content

Commit 7ccbe07

Browse files
l0kodpcmoore
authored andcommitted
lsm: Only build lsm_audit.c if CONFIG_SECURITY and CONFIG_AUDIT are set
When CONFIG_AUDIT is set, its CONFIG_NET dependency is also set, and the dev_get_by_index and init_net symbols (used by dump_common_audit_data) are found by the linker. dump_common_audit_data() should then failed to build when CONFIG_NET is not set. However, because the compiler is smart, it knows that audit_log_start() always return NULL when !CONFIG_AUDIT, and it doesn't build the body of common_lsm_audit(). As a side effect, dump_common_audit_data() is not built and the linker doesn't error out because of missing symbols. Let's only build lsm_audit.o when CONFIG_SECURITY and CONFIG_AUDIT are both set, which is checked with the new CONFIG_HAS_SECURITY_AUDIT. ipv4_skb_to_auditdata() and ipv6_skb_to_auditdata() are only used by Smack if CONFIG_AUDIT is set, so they don't need fake implementations. Because common_lsm_audit() is used in multiple places without CONFIG_AUDIT checks, add a fake implementation. Link: https://lore.kernel.org/r/[email protected] Cc: Casey Schaufler <[email protected]> Cc: James Morris <[email protected]> Cc: Paul Moore <[email protected]> Cc: Serge E. Hallyn <[email protected]> Signed-off-by: Mickaël Salaün <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 7a9b65a commit 7ccbe07

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

include/linux/lsm_audit.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,28 @@ struct common_audit_data {
116116
#define v4info fam.v4
117117
#define v6info fam.v6
118118

119+
#ifdef CONFIG_AUDIT
120+
119121
int ipv4_skb_to_auditdata(struct sk_buff *skb,
120122
struct common_audit_data *ad, u8 *proto);
121123

124+
#if IS_ENABLED(CONFIG_IPV6)
122125
int ipv6_skb_to_auditdata(struct sk_buff *skb,
123126
struct common_audit_data *ad, u8 *proto);
127+
#endif /* IS_ENABLED(CONFIG_IPV6) */
124128

125129
void common_lsm_audit(struct common_audit_data *a,
126130
void (*pre_audit)(struct audit_buffer *, void *),
127131
void (*post_audit)(struct audit_buffer *, void *));
128132

133+
#else /* CONFIG_AUDIT */
134+
135+
static inline void common_lsm_audit(struct common_audit_data *a,
136+
void (*pre_audit)(struct audit_buffer *, void *),
137+
void (*post_audit)(struct audit_buffer *, void *))
138+
{
139+
}
140+
141+
#endif /* CONFIG_AUDIT */
142+
129143
#endif

security/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ config SECURITY
6464

6565
If you are unsure how to answer this question, answer N.
6666

67+
config HAS_SECURITY_AUDIT
68+
def_bool y
69+
depends on AUDIT
70+
depends on SECURITY
71+
6772
config SECURITYFS
6873
bool "Enable the securityfs filesystem"
6974
help

security/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ obj-$(CONFIG_SECURITY) += security.o
1515
obj-$(CONFIG_SECURITYFS) += inode.o
1616
obj-$(CONFIG_SECURITY_SELINUX) += selinux/
1717
obj-$(CONFIG_SECURITY_SMACK) += smack/
18-
obj-$(CONFIG_SECURITY) += lsm_audit.o
18+
obj-$(CONFIG_HAS_SECURITY_AUDIT) += lsm_audit.o
1919
obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/
2020
obj-$(CONFIG_SECURITY_APPARMOR) += apparmor/
2121
obj-$(CONFIG_SECURITY_YAMA) += yama/

0 commit comments

Comments
 (0)