Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc-12 seems to be unhappy about mfree() #22215

Closed
mrc0mmand opened this issue Jan 22, 2022 · 7 comments · Fixed by #22191
Closed

gcc-12 seems to be unhappy about mfree() #22215

mrc0mmand opened this issue Jan 22, 2022 · 7 comments · Fixed by #22191

Comments

@mrc0mmand
Copy link
Member

systemd version the issue has been seen with

latest master

Used distribution

Fedora Rawhide (gcc-12)

Recent Packit jobs fail with:

In file included from ../src/basic/macro.h:12,
                 from ../src/basic/time-util.h:19,
                 from ../src/shared/ask-password-api.h:6,
                 from ../src/shared/pkcs11-util.c:5:
In function ‘freep’,
    inlined from ‘pkcs11_token_login’ at ../src/shared/pkcs11-util.c:240:83:
../src/fundamental/macro-fundamental.h:284:17: error: pointer ‘id_384’ used after ‘free’ [-Werror=use-after-free]
  284 |                 free(memory);                   \
      |                 ^~~~~~~~~~~~
In function ‘freep’,
    inlined from ‘pkcs11_token_login’ at ../src/shared/pkcs11-util.c:240:95:
../src/fundamental/macro-fundamental.h:284:17: note: call to ‘free’ here
  284 |                 free(memory);                   \
      |                 ^~~~~~~~~~~~
In function ‘freep’,
    inlined from ‘pkcs11_token_login’ at ../src/shared/pkcs11-util.c:240:56:
../src/fundamental/macro-fundamental.h:284:17: error: pointer ‘token_uri_escaped_380’ used after ‘free’ [-Werror=use-after-free]
  284 |                 free(memory);                   \
      |                 ^~~~~~~~~~~~
In function ‘freep’,
    inlined from ‘pkcs11_token_login’ at ../src/shared/pkcs11-util.c:240:95:
../src/fundamental/macro-fundamental.h:284:17: note: call to ‘free’ here
  284 |                 free(memory);                   \
      |                 ^~~~~~~~~~~~
cc1: all warnings being treated as errors

regarding

#define mfree(memory) \
({ \
free(memory); \
(typeof(memory)) NULL; \
})

@mrc0mmand mrc0mmand added the bug 🐛 Programming errors, that need preferential fixing label Jan 22, 2022
@mrc0mmand
Copy link
Member Author

Given that clang-12 and clang-13 seem to be alright with this, I'd say it's an issue on gcc's side, but I tagged as "bug" just to be sure...

@yuwata
Copy link
Member

yuwata commented Jan 22, 2022

I'd like to tag this 'not-our-bug' :-)

@yuwata
Copy link
Member

yuwata commented Jan 22, 2022

C.f. #22191.

@mrc0mmand
Copy link
Member Author

C.f. #22191.

Ah, I had a feeling I've seen it before :-) I'll try to dig a bit deeper and report it to gcc folks, if possible.

@bluca
Copy link
Member

bluca commented Jan 22, 2022

Can we add a pragma to ignore it?

@mrc0mmand
Copy link
Member Author

Interesting, the culprit seems to be -ffat-lto-objects when used with gcc-12 (and this option is added to $CFLAGS by rpm's hardening macros.

# cc -Isrc/shared/libsystemd-shared-250.a.p -Isrc/shared -I../src/shared -Isrc/basic -I../src/basic -Isrc/fundamental -I../src/fundamental -Isrc/systemd -I../src/systemd -I. -I.. -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-journal -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -I../src/libsystemd/sd-resolve -I/usr/include/blkid -I/usr/include/libmount -I/usr/include/p11-kit-1 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=gnu99 -g -Wno-format-signedness -Wno-missing-field-initializers -Wno-unused-parameter -Wdate-time -Wendif-labels -Werror=format=2 -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=undef -Wfloat-equal -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -Wstrict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wno-unused-result -Werror=missing-declarations -Werror=missing-prototypes -fdiagnostics-show-option -fno-common -fno-strict-aliasing -fstack-protector -fstack-protector-strong -fvisibility=hidden --param=ssp-buffer-size=4 -Werror=shadow -include config.h -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC -pthread -fvisibility=default -MD -MQ src/shared/libsystemd-shared-250.a.p/pkcs11-util.c.o -MF src/shared/libsystemd-shared-250.a.p/pkcs11-util.c.o.d -o src/shared/libsystemd-shared-250.a.p/pkcs11-util.c.o -c ../src/shared/pkcs11-util.c 
In file included from ../src/basic/macro.h:12,
                 from ../src/basic/time-util.h:19,
                 from ../src/shared/ask-password-api.h:6,
                 from ../src/shared/pkcs11-util.c:5:
In function ‘freep’,
    inlined from ‘pkcs11_token_login’ at ../src/shared/pkcs11-util.c:240:83:
../src/fundamental/macro-fundamental.h:284:17: error: pointer ‘id_390’ used after ‘free’ [-Werror=use-after-free]
  284 |                 free(memory);                   \
      |                 ^~~~~~~~~~~~
In function ‘freep’,
    inlined from ‘pkcs11_token_login’ at ../src/shared/pkcs11-util.c:240:95:
../src/fundamental/macro-fundamental.h:284:17: note: call to ‘free’ here
  284 |                 free(memory);                   \
      |                 ^~~~~~~~~~~~
In function ‘freep’,
    inlined from ‘pkcs11_token_login’ at ../src/shared/pkcs11-util.c:240:56:
../src/fundamental/macro-fundamental.h:284:17: error: pointer ‘token_uri_escaped_386’ used after ‘free’ [-Werror=use-after-free]
  284 |                 free(memory);                   \
      |                 ^~~~~~~~~~~~
In function ‘freep’,
    inlined from ‘pkcs11_token_login’ at ../src/shared/pkcs11-util.c:240:95:
../src/fundamental/macro-fundamental.h:284:17: note: call to ‘free’ here
  284 |                 free(memory);                   \
      |                 ^~~~~~~~~~~~
cc1: all warnings being treated as errors

with -fno-fat-lto-objects appended:

# cc -Isrc/shared/libsystemd-shared-250.a.p -Isrc/shared -I../src/shared -Isrc/basic -I../src/basic -Isrc/fundamental -I../src/fundamental -Isrc/systemd -I../src/systemd -I. -I.. -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-journal -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -I../src/libsystemd/sd-resolve -I/usr/include/blkid -I/usr/include/libmount -I/usr/include/p11-kit-1 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=gnu99 -g -Wno-format-signedness -Wno-missing-field-initializers -Wno-unused-parameter -Wdate-time -Wendif-labels -Werror=format=2 -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=undef -Wfloat-equal -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -Wstrict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wno-unused-result -Werror=missing-declarations -Werror=missing-prototypes -fdiagnostics-show-option -fno-common -fno-strict-aliasing -fstack-protector -fstack-protector-strong -fvisibility=hidden --param=ssp-buffer-size=4 -Werror=shadow -include config.h -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC -pthread -fvisibility=default -MD -MQ src/shared/libsystemd-shared-250.a.p/pkcs11-util.c.o -MF src/shared/libsystemd-shared-250.a.p/pkcs11-util.c.o.d -o src/shared/libsystemd-shared-250.a.p/pkcs11-util.c.o -c ../src/shared/pkcs11-util.c -fno-fat-lto-objects
# echo $?
0

@mrc0mmand
Copy link
Member Author

@mrc0mmand mrc0mmand added not-our-bug and removed bug 🐛 Programming errors, that need preferential fixing labels Jan 22, 2022
mrc0mmand added a commit to mrc0mmand/systemd that referenced this issue Jan 22, 2022
gcc-12 seems to be very unstable right now, so to keep our CI builds
useful let's move them to stable F35 for a while.

Follow-up to 478c632.
See:
  * systemd#22215
  * https://bugzilla.redhat.com/show_bug.cgi?id=2043915
mrc0mmand added a commit that referenced this issue Jan 22, 2022
gcc-12 seems to be very unstable right now, so to keep our CI builds
useful let's move them to stable F35 for a while.

Follow-up to 478c632.
See:
  * #22215
  * https://bugzilla.redhat.com/show_bug.cgi?id=2043915
@mrc0mmand mrc0mmand linked a pull request Feb 7, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants