Skip to contentSkip to conversation

Fix build with -fno-common

PATCH Superseded Ondrej Mosnacek 2 participants 8 messages Jan 22, 2020 – Jan 23, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix build with -fno-common

GCC 10 is going to enable -fno-common by default [1], so fix all build errors uncovered by it and add it to global CFLAGS to avoid introducing new bugs.

Travis build: [2]

[1] https://gcc.gnu.org/gcc-10/porting_to.html#common
[2] https://travis-ci.org/WOnder93/selinux/builds/640506702

Ondrej Mosnacek (4):
libsepol: fix CIL_KEY_* build errors with -fno-common
libsepol: remove unused cil_mem_error_handler
checkpolicy: remove unused te_assertions
Makefile: always build with -fno-common

 Makefile                        |   3 +-
 checkpolicy/checkpolicy.h       |   2 -
 libsepol/cil/src/cil.c          | 162 ++++++++++++++++
 libsepol/cil/src/cil_internal.h | 322 ++++++++++++++++----------------
 libsepol/cil/src/cil_mem.h      |   1 -
 libsepol/cil/src/cil_strpool.c  |   2 -
 6 files changed, 325 insertions(+), 167 deletions(-)
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/4 libsepol: fix CIL_KEY_* build errors with -fno-common

GCC 10 comes with -fno-common enabled by default - fix the CIL_KEY_* global variables to be defined only once in cil.c and declared in the header file correctly with the 'extern' keyword, so that other units including the file don't generate duplicate definitions.

---
 libsepol/cil/src/cil.c          | 162 ++++++++++++++++
 libsepol/cil/src/cil_internal.h | 322 ++++++++++++++++----------------
 2 files changed, 323 insertions(+), 161 deletions(-)
libsepol/cil/src/cil.c +162 -0
index de729cf8..d222ad3a 100644
@@ -77,6 +77,168 @@ int cil_sym_sizes[CIL_SYM_ARRAY_NUM][CIL_SYM_NUM] = {
 	{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
 };
 
+char *CIL_KEY_CONS_T1;
+char *CIL_KEY_CONS_T2;
+char *CIL_KEY_CONS_T3;
+char *CIL_KEY_CONS_R1;
+char *CIL_KEY_CONS_R2;
+char *CIL_KEY_CONS_R3;
+char *CIL_KEY_CONS_U1;
+char *CIL_KEY_CONS_U2;
+char *CIL_KEY_CONS_U3;
+char *CIL_KEY_CONS_L1;
+char *CIL_KEY_CONS_L2;
+char *CIL_KEY_CONS_H1;
+char *CIL_KEY_CONS_H2;
+char *CIL_KEY_AND;
+char *CIL_KEY_OR;
+char *CIL_KEY_NOT;
+char *CIL_KEY_EQ;
+char *CIL_KEY_NEQ;
+char *CIL_KEY_CONS_DOM;
+char *CIL_KEY_CONS_DOMBY;
+char *CIL_KEY_CONS_INCOMP;
+char *CIL_KEY_CONDTRUE;
+char *CIL_KEY_CONDFALSE;
+char *CIL_KEY_SELF;
+char *CIL_KEY_OBJECT_R;
+char *CIL_KEY_STAR;
+char *CIL_KEY_TCP;
+char *CIL_KEY_UDP;
+char *CIL_KEY_DCCP;
+char *CIL_KEY_SCTP;
+char *CIL_KEY_AUDITALLOW;
+char *CIL_KEY_TUNABLEIF;
+char *CIL_KEY_ALLOW;
+char *CIL_KEY_DONTAUDIT;
+char *CIL_KEY_TYPETRANSITION;
+char *CIL_KEY_TYPECHANGE;
+char *CIL_KEY_CALL;
+char *CIL_KEY_TUNABLE;
+char *CIL_KEY_XOR;
+char *CIL_KEY_ALL;
+char *CIL_KEY_RANGE;
+char *CIL_KEY_GLOB;
+char *CIL_KEY_FILE;
+char *CIL_KEY_DIR;
+char *CIL_KEY_CHAR;
+char *CIL_KEY_BLOCK;
+char *CIL_KEY_SOCKET;
+char *CIL_KEY_PIPE;
+char *CIL_KEY_SYMLINK;
+char *CIL_KEY_ANY;
+char *CIL_KEY_XATTR;
+char *CIL_KEY_TASK;
+char *CIL_KEY_TRANS;
+char *CIL_KEY_TYPE;
+char *CIL_KEY_ROLE;
+char *CIL_KEY_USER;
+char *CIL_KEY_USERATTRIBUTE;
+char *CIL_KEY_USERATTRIBUTESET;
+char *CIL_KEY_SENSITIVITY;
+char *CIL_KEY_CATEGORY;
+char *CIL_KEY_CATSET;
+char *CIL_KEY_LEVEL;
+char *CIL_KEY_LEVELRANGE;
+char *CIL_KEY_CLASS;
+char *CIL_KEY_IPADDR;
+char *CIL_KEY_MAP_CLASS;
+char *CIL_KEY_CLASSPERMISSION;
+char *CIL_KEY_BOOL;
+char *CIL_KEY_STRING;
+char *CIL_KEY_NAME;
+char *CIL_KEY_SOURCE;
+char *CIL_KEY_TARGET;
+char *CIL_KEY_LOW;
+char *CIL_KEY_HIGH;
+char *CIL_KEY_LOW_HIGH;
+char *CIL_KEY_GLBLUB;
+char *CIL_KEY_HANDLEUNKNOWN;
+char *CIL_KEY_HANDLEUNKNOWN_ALLOW;
+char *CIL_KEY_HANDLEUNKNOWN_DENY;
+char *CIL_KEY_HANDLEUNKNOWN_REJECT;
+char *CIL_KEY_MACRO;
+char *CIL_KEY_IN;
+char *CIL_KEY_MLS;
+char *CIL_KEY_DEFAULTRANGE;
+char *CIL_KEY_BLOCKINHERIT;
+char *CIL_KEY_BLOCKABSTRACT;
+char *CIL_KEY_CLASSORDER;
+char *CIL_KEY_CLASSMAPPING;
+char *CIL_KEY_CLASSPERMISSIONSET;
+char *CIL_KEY_COMMON;
+char *CIL_KEY_CLASSCOMMON;
+char *CIL_KEY_SID;
+char *CIL_KEY_SIDCONTEXT;
+char *CIL_KEY_SIDORDER;
+char *CIL_KEY_USERLEVEL;
+char *CIL_KEY_USERRANGE;
+char *CIL_KEY_USERBOUNDS;
+char *CIL_KEY_USERPREFIX;
+char *CIL_KEY_SELINUXUSER;
+char *CIL_KEY_SELINUXUSERDEFAULT;
+char *CIL_KEY_TYPEATTRIBUTE;
+char *CIL_KEY_TYPEATTRIBUTESET;
+char *CIL_KEY_EXPANDTYPEATTRIBUTE;
+char *CIL_KEY_TYPEALIAS;
+char *CIL_KEY_TYPEALIASACTUAL;
+char *CIL_KEY_TYPEBOUNDS;
+char *CIL_KEY_TYPEPERMISSIVE;
+char *CIL_KEY_RANGETRANSITION;
+char *CIL_KEY_USERROLE;
+char *CIL_KEY_ROLETYPE;
+char *CIL_KEY_ROLETRANSITION;
+char *CIL_KEY_ROLEALLOW;
+char *CIL_KEY_ROLEATTRIBUTE;
+char *CIL_KEY_ROLEATTRIBUTESET;
+char *CIL_KEY_ROLEBOUNDS;
+char *CIL_KEY_BOOLEANIF;
+char *CIL_KEY_NEVERALLOW;
+char *CIL_KEY_TYPEMEMBER;
+char *CIL_KEY_SENSALIAS;
+char *CIL_KEY_SENSALIASACTUAL;
+char *CIL_KEY_CATALIAS;
+char *CIL_KEY_CATALIASACTUAL;
+char *CIL_KEY_CATORDER;
+char *CIL_KEY_SENSITIVITYORDER;
+char *CIL_KEY_SENSCAT;
+char *CIL_KEY_CONSTRAIN;
+char *CIL_KEY_MLSCONSTRAIN;
+char *CIL_KEY_VALIDATETRANS;
+char *CIL_KEY_MLSVALIDATETRANS;
+char *CIL_KEY_CONTEXT;
+char *CIL_KEY_FILECON;
+char *CIL_KEY_IBPKEYCON;
+char *CIL_KEY_IBENDPORTCON;
+char *CIL_KEY_PORTCON;
+char *CIL_KEY_NODECON;
+char *CIL_KEY_GENFSCON;
+char *CIL_KEY_NETIFCON;
+char *CIL_KEY_PIRQCON;
+char *CIL_KEY_IOMEMCON;
+char *CIL_KEY_IOPORTCON;
+char *CIL_KEY_PCIDEVICECON;
+char *CIL_KEY_DEVICETREECON;
+char *CIL_KEY_FSUSE;
+char *CIL_KEY_POLICYCAP;
+char *CIL_KEY_OPTIONAL;
+char *CIL_KEY_DEFAULTUSER;
+char *CIL_KEY_DEFAULTROLE;
+char *CIL_KEY_DEFAULTTYPE;
+char *CIL_KEY_ROOT;
+char *CIL_KEY_NODE;
+char *CIL_KEY_PERM;
+char *CIL_KEY_ALLOWX;
+char *CIL_KEY_AUDITALLOWX;
+char *CIL_KEY_DONTAUDITX;
+char *CIL_KEY_NEVERALLOWX;
+char *CIL_KEY_PERMISSIONX;
+char *CIL_KEY_IOCTL;
+char *CIL_KEY_UNORDERED;
+char *CIL_KEY_SRC_INFO;
+char *CIL_KEY_SRC_CIL;
+char *CIL_KEY_SRC_HLL;
+
 static void cil_init_keys(void)
 {
 	/* Initialize CIL Keys into strpool */
libsepol/cil/src/cil_internal.h +161 -161

328 lines not on this page · raw message

Signature · 1 line
2.24.1
#2 lore raw

PATCH 2/4 libsepol: remove unused cil_mem_error_handler

In reply to Ondrej Mosnacek

It is declared in an internal header but never defined. Remove it.

---
 libsepol/cil/src/cil_mem.h     | 1 -
 libsepol/cil/src/cil_strpool.c | 2 --
 2 files changed, 3 deletions(-)
libsepol/cil/src/cil_mem.h +0 -1
index 902ce131..794f02a3 100644
@@ -36,7 +36,6 @@ void *cil_calloc(size_t num_elements, size_t element_size);
 void *cil_realloc(void *ptr, size_t size);
 char *cil_strdup(const char *str);
 int cil_asprintf(char **strp, const char *fmt, ...);
-void (*cil_mem_error_handler)(void);
 
 #endif /* CIL_MEM_H_ */
 
libsepol/cil/src/cil_strpool.c +0 -2
index 97d4c4b9..508541d6 100644
@@ -80,7 +80,6 @@ char *cil_strpool_add(const char *str)
 		int rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
 		if (rc != SEPOL_OK) {
 			pthread_mutex_unlock(&cil_strpool_mutex);
-			(*cil_mem_error_handler)();
 			pthread_mutex_lock(&cil_strpool_mutex);
 		}
 	}
@@ -104,7 +103,6 @@ void cil_strpool_init(void)
 		cil_strpool_tab = hashtab_create(cil_strpool_hash, cil_strpool_compare, CIL_STRPOOL_TABLE_SIZE);
 		if (cil_strpool_tab == NULL) {
 			pthread_mutex_unlock(&cil_strpool_mutex);
-			(*cil_mem_error_handler)();
 			return;
 		}
 	}
Signature · 1 line
2.24.1
#3 lore raw

Re: [Non-DoD Source] [PATCH userspace 2/4] libsepol: remove unused cil_mem_error_handler

Quoted 25 lines · Ondrej Mosnacek

It is declared in an internal header but never defined. Remove it.

---
  libsepol/cil/src/cil_mem.h     | 1 -
  libsepol/cil/src/cil_strpool.c | 2 --
  2 files changed, 3 deletions(-)
libsepol/cil/src/cil_mem.h +0 -1
index 902ce131..794f02a3 100644
@@ -36,7 +36,6 @@ void *cil_calloc(size_t num_elements, size_t element_size);
  void *cil_realloc(void *ptr, size_t size);
  char *cil_strdup(const char *str);
  int cil_asprintf(char **strp, const char *fmt, ...);
-void (*cil_mem_error_handler)(void);
 
  #endif /* CIL_MEM_H_ */
 
libsepol/cil/src/cil_strpool.c +0 -0
index 97d4c4b9..508541d6 100644

libsepol/cil/src/cil_strpool.c char *cil_strpool_add(const char *str) · line 85

Quoted 7 lines
libsepol/cil/src/cil_strpool.c +0 -1
@@ -80,7 +80,6 @@ char *cil_strpool_add(const char *str)
  		int rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
  		if (rc != SEPOL_OK) {
  			pthread_mutex_unlock(&cil_strpool_mutex);
-			(*cil_mem_error_handler)();
  			pthread_mutex_lock(&cil_strpool_mutex);
  		}
  	}

I removed the cil_mem_error_handler stuff last Fall (see commit 4459d635). I guess that I must have missed these somehow.

In the other places where I removed it, I replaced it with the inlined default hanlder which consisted of the following:

  cil_log(CIL_ERR, "Failed to allocate memory\n");
  exit(1);

Since we are existing, the pthread_mutex_lock() call can be removed.

libsepol/cil/src/cil_strpool.c void cil_strpool_init(void) · line 108

Quoted 9 lines
libsepol/cil/src/cil_strpool.c +0 -1
@@ -104,7 +103,6 @@ void cil_strpool_init(void)
  		cil_strpool_tab = hashtab_create(cil_strpool_hash, cil_strpool_compare, CIL_STRPOOL_TABLE_SIZE);
  		if (cil_strpool_tab == NULL) {
  			pthread_mutex_unlock(&cil_strpool_mutex);
-			(*cil_mem_error_handler)();
  			return;
  		}
  	}

Same thing here, but now the return won't be needed.

Thanks,
Jim

Signature · 2 lines
James Carter <[email protected]>
National Security Agency
#4 lore raw

Re: [Non-DoD Source] [PATCH userspace 2/4] libsepol: remove unused cil_mem_error_handler

Quoted 37 lines · On Wed, Jan 22, 2020 at 7:54 PM jwcart2 <[email protected]> wrote:
Quoted 25 lines · Ondrej Mosnacek

It is declared in an internal header but never defined. Remove it.

---
  libsepol/cil/src/cil_mem.h     | 1 -
  libsepol/cil/src/cil_strpool.c | 2 --
  2 files changed, 3 deletions(-)
libsepol/cil/src/cil_mem.h +0 -1
index 902ce131..794f02a3 100644
@@ -36,7 +36,6 @@ void *cil_calloc(size_t num_elements, size_t element_size);
  void *cil_realloc(void *ptr, size_t size);
  char *cil_strdup(const char *str);
  int cil_asprintf(char **strp, const char *fmt, ...);
-void (*cil_mem_error_handler)(void);
 
  #endif /* CIL_MEM_H_ */
 
libsepol/cil/src/cil_strpool.c +0 -0
index 97d4c4b9..508541d6 100644

libsepol/cil/src/cil_strpool.c char *cil_strpool_add(const char *str) · line 85

Quoted 7 lines
libsepol/cil/src/cil_strpool.c +0 -1
@@ -80,7 +80,6 @@ char *cil_strpool_add(const char *str)
              int rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
              if (rc != SEPOL_OK) {
                      pthread_mutex_unlock(&cil_strpool_mutex);
-                     (*cil_mem_error_handler)();
                      pthread_mutex_lock(&cil_strpool_mutex);
              }
      }

I removed the cil_mem_error_handler stuff last Fall (see commit 4459d635). I guess that I must have missed these somehow.

Quoted 7 lines

In the other places where I removed it, I replaced it with the inlined default hanlder which consisted of the following:

   cil_log(CIL_ERR, "Failed to allocate memory\n");
   exit(1);

Since we are existing, the pthread_mutex_lock() call can be removed.

I see, thanks for pointing it out! I'm now quite embarrassed for not noticing the needless lock-unlock sequence I left behind in this patch :)

I will rework this patch to match commit 4459d635 in v2.

Quoted 13 lines

libsepol/cil/src/cil_strpool.c void cil_strpool_init(void) · line 108

Quoted 10 lines
libsepol/cil/src/cil_strpool.c +0 -1
@@ -104,7 +103,6 @@ void cil_strpool_init(void)
              cil_strpool_tab = hashtab_create(cil_strpool_hash, cil_strpool_compare, CIL_STRPOOL_TABLE_SIZE);
              if (cil_strpool_tab == NULL) {
                      pthread_mutex_unlock(&cil_strpool_mutex);
-                     (*cil_mem_error_handler)();
                      return;
              }
      }

Same thing here, but now the return won't be needed.

Quoted 8 lines

Thanks,
Jim

--
James Carter <[email protected]>
National Security Agency

--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.

#5 lore raw

PATCH 3/4 checkpolicy: remove unused te_assertions

In reply to Ondrej Mosnacek

This variable is declared in a header file, but never defined or used. Remove it.

---
 checkpolicy/checkpolicy.h | 2 --
 1 file changed, 2 deletions(-)
checkpolicy/checkpolicy.h +0 -2
index 3868f1fa..8fbc1b7d 100644
@@ -13,8 +13,6 @@ typedef struct te_assert {
 	struct te_assert *next;
 } te_assert_t;
 
-te_assert_t *te_assertions;
-
 extern unsigned int policyvers;
 
 #endif
Signature · 1 line
2.24.1
#6 lore raw

Re: [PATCH userspace 3/4] checkpolicy: remove unused te_assertions

Quoted 13 lines · Ondrej Mosnacek

This variable is declared in a header file, but never defined or used. Remove it.

---
 checkpolicy/checkpolicy.h | 2 --
 1 file changed, 2 deletions(-)
checkpolicy/checkpolicy.h +0 -0
index 3868f1fa..8fbc1b7d 100644

checkpolicy/checkpolicy.h typedef struct te_assert { · line 14

Quoted 2 lines
checkpolicy/checkpolicy.h +0 -0
@@ -13,8 +13,6 @@ typedef struct te_assert {
        struct te_assert *next;
 } te_assert_t;

Actually, it looks like this whole struct definition can go as well. I'll post a v2 later.

Quoted 9 lines
checkpolicy/checkpolicy.h +0 -3
-te_assert_t *te_assertions;
-
 extern unsigned int policyvers;
 
 #endif
--

2.24.1

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
#7 lore raw

PATCH 4/4 Makefile: always build with -fno-common

In reply to Ondrej Mosnacek

GCC 10 has it enabled by default and everything now builds OK with it, so add it to CFLAGS to avoid breaking the build in the future.

---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile +2 -1
index c238dbc8..298cd2b7 100644
@@ -16,7 +16,8 @@ else
 		-Wstrict-prototypes \
 		-Wundef \
 		-Wunused \
-		-Wwrite-strings
+		-Wwrite-strings \
+		-fno-common
 endif
 
 ifneq ($(DESTDIR),)
Signature · 1 line
2.24.1