SELinuxProject / selinux

This is the upstream repository for the Security Enhanced Linux (SELinux) userland libraries and tools. The software provided by this project complements the SELinux features integrated into the Linux kernel and is used by Linux distributions. All bugs and patches should be submitted to selinux@vger.kernel.org
Other
1.35k stars 360 forks source link

newrole: free_hashtab_entry function does not use the return value an… #355

Closed likunyur closed 2 years ago

likunyur commented 2 years ago

Omit the eax register step

fishilico commented 2 years ago

Hello, Even though your patch works on your machine, it is actually introducing a bug which could be triggered on other systems/CPU. free_hashtab_entry is used in a call to function hashtab_map, which actually checks the return value of the function: https://github.com/SELinuxProject/selinux/blob/0a8c177dacdc1df96ea11bb8aa75e16c4fa82285/libsepol/src/hashtab.c#L234-L236

Your patch makes this return value undefined, which is an issue.

cgzones commented 2 years ago
cc -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -Wunused -Wwrite-strings -fno-common -I/home/christian/destdir/usr/include -DVERSION=\"3.4\" -DUSE_NLS -DLOCALEDIR="\"/home/christian/destdir/usr/share/locale\"" -DPACKAGE="\"policycoreutils\"" -DUSE_PAM -DUSE_AUDIT   -c -o newrole.o newrole.c
newrole.c: In function ‘main’:
newrole.c:1248:48: error: passing argument 2 of ‘hashtab_map’ from incompatible pointer type [-Werror=incompatible-pointer-types]
 1248 |                 hashtab_map(app_service_names, free_hashtab_entry, NULL);
      |                                                ^~~~~~~~~~~~~~~~~~
      |                                                |
      |                                                void (*)(char *, void *, void *)
In file included from newrole.c:220:
hashtab.h:109:30: note: expected ‘int (*)(char *, void *, void *)’ but argument is of type ‘void (*)(char *, void *, void *)’
  109 |                        int (*apply) (hashtab_key_t k,
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
  110 |                                      hashtab_datum_t d,
      |                                      ~~~~~~~~~~~~~~~~~~
  111 |                                      void *args), void *args);
      |                                      ~~~~~~~~~~~
newrole.c:1376:48: error: passing argument 2 of ‘hashtab_map’ from incompatible pointer type [-Werror=incompatible-pointer-types]
 1376 |                 hashtab_map(app_service_names, free_hashtab_entry, NULL);
      |                                                ^~~~~~~~~~~~~~~~~~
      |                                                |
      |                                                void (*)(char *, void *, void *)
In file included from newrole.c:220:
hashtab.h:109:30: note: expected ‘int (*)(char *, void *, void *)’ but argument is of type ‘void (*)(char *, void *, void *)’
  109 |                        int (*apply) (hashtab_key_t k,
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
  110 |                                      hashtab_datum_t d,
      |                                      ~~~~~~~~~~~~~~~~~~
  111 |                                      void *args), void *args);
      |                                      ~~~~~~~~~~~