Skip to content

Commit 541b57e

Browse files
masahir0ypcmoore
authored andcommitted
selinux: do not include <linux/*.h> headers from host programs
The header, security/selinux/include/classmap.h, is included not only from kernel space but also from host programs. It includes <linux/capability.h> and <linux/socket.h>, which pull in more <linux/*.h> headers. This makes the host programs less portable, specifically causing build errors on macOS. Those headers are included for the following purposes: - <linux/capability.h> for checking CAP_LAST_CAP - <linux/socket.h> for checking PF_MAX These checks can be guarded by __KERNEL__ so they are skipped when building host programs. Testing them when building the kernel should be sufficient. The header, security/selinux/include/initial_sid_to_string.h, includes <linux/stddef.h> for the NULL definition, but this is not portable either. Instead, <stddef.h> should be included for host programs. Reported-by: Daniel Gomez <[email protected]> Closes: https://lore.kernel.org/lkml/[email protected]/ Closes: https://lore.kernel.org/lkml/[email protected]/ Signed-off-by: Masahiro Yamada <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 9852d85 commit 541b57e

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

scripts/selinux/genheaders/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0
22
hostprogs-always-y += genheaders
3-
HOST_EXTRACFLAGS += \
4-
-I$(srctree)/include/uapi -I$(srctree)/include \
5-
-I$(srctree)/security/selinux/include
3+
HOST_EXTRACFLAGS += -I$(srctree)/security/selinux/include

scripts/selinux/genheaders/genheaders.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
/* NOTE: we really do want to use the kernel headers here */
4-
#define __EXPORTED_HEADERS__
5-
63
#include <stdio.h>
74
#include <stdlib.h>
85
#include <unistd.h>

scripts/selinux/mdp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
hostprogs-always-y += mdp
33
HOST_EXTRACFLAGS += \
4-
-I$(srctree)/include/uapi -I$(srctree)/include \
4+
-I$(srctree)/include \
55
-I$(srctree)/security/selinux/include -I$(objtree)/include
66

77
clean-files := policy.* file_contexts

scripts/selinux/mdp/mdp.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
* Authors: Serge E. Hallyn <[email protected]>
1212
*/
1313

14-
15-
/* NOTE: we really do want to use the kernel headers here */
16-
#define __EXPORTED_HEADERS__
17-
1814
#include <stdio.h>
1915
#include <stdlib.h>
2016
#include <unistd.h>

security/selinux/include/classmap.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22

3-
#include <linux/capability.h>
4-
#include <linux/socket.h>
5-
63
#define COMMON_FILE_SOCK_PERMS \
74
"ioctl", "read", "write", "create", "getattr", "setattr", "lock", \
85
"relabelfrom", "relabelto", "append", "map"
@@ -36,9 +33,13 @@
3633
"mac_override", "mac_admin", "syslog", "wake_alarm", "block_suspend", \
3734
"audit_read", "perfmon", "bpf", "checkpoint_restore"
3835

36+
#ifdef __KERNEL__ /* avoid this check when building host programs */
37+
#include <linux/capability.h>
38+
3939
#if CAP_LAST_CAP > CAP_CHECKPOINT_RESTORE
4040
#error New capability defined, please update COMMON_CAP2_PERMS.
4141
#endif
42+
#endif
4243

4344
/*
4445
* Note: The name for any socket class should be suffixed by "socket",
@@ -181,6 +182,10 @@ const struct security_class_mapping secclass_map[] = {
181182
{ NULL }
182183
};
183184

185+
#ifdef __KERNEL__ /* avoid this check when building host programs */
186+
#include <linux/socket.h>
187+
184188
#if PF_MAX > 46
185189
#error New address family defined, please update secclass_map.
186190
#endif
191+
#endif

security/selinux/include/initial_sid_to_string.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22

3+
#ifdef __KERNEL__
34
#include <linux/stddef.h>
5+
#else
6+
#include <stddef.h>
7+
#endif
48

59
static const char *const initial_sid_to_string[] = {
610
NULL, /* zero placeholder, not used */

0 commit comments

Comments
 (0)