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

__mulodi4 from u32_u32__int_overflow_test in lib/overflow_kunit.c #1711

Closed
nathanchance opened this issue Sep 16, 2022 · 11 comments
Closed

__mulodi4 from u32_u32__int_overflow_test in lib/overflow_kunit.c #1711

nathanchance opened this issue Sep 16, 2022 · 11 comments
Assignees
Labels
[BUG] linux A bug that should be fixed in the mainline kernel. [FIXED][LINUX] development cycle This bug was only present and fixed in a -next or -rc cycle

Comments

@nathanchance
Copy link
Member

Reported by CI with LLVM 11 (newer versions do not show this):

https://builds.tuxbuild.com/2EqpS04tCKn154FmyeYYpl7WJJ2/build.log

$ make -skj"$(nproc)" ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- KCONFIG_ALLCONFIG=<(echo CONFIG_WERROR=n) LLVM=1 LLVM_IAS=0 allmodconfig all
...
ERROR: modpost: "__mulodi4" [lib/overflow_kunit.ko] undefined!
...

"Caused" by commit d219d2a9a92e ("overflow: Allow mixed type arguments") (cc @kees). A simplified reproducer on top of allnoconfig:

$ make -skj"$(nproc)" ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- LLVM=1 LLVM_IAS=0 allnoconfig

$ scripts/config -e KUNIT -e RUNTIME_TESTING_MENU -e OVERFLOW_KUNIT_TEST

$ make -skj"$(nproc)" ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- LLVM=1 LLVM_IAS=0 olddefconfig all
ld.lld: error: undefined symbol: __mulodi4
>>> referenced by overflow_kunit.c
>>>               lib/overflow_kunit.o:(u32_u32__int_overflow_test) in archive vmlinux.a
>>> referenced by overflow_kunit.c
>>>               lib/overflow_kunit.o:(u32_u32__int_overflow_test) in archive vmlinux.a

My reverse bisect of LLVM shows commit 3203143f1356 ("CodeGen: Improve generated IR for __builtin_mul_overflow(uint, uint, int)") resolved this, which appears to be this exact case. I wonder if it is worth bumping the minimum version of LLVM to 12.0.0 over this?

@nathanchance nathanchance added the [BUG] linux-next This is an issue only seen in linux-next label Sep 16, 2022
@nickdesaulniers
Copy link
Member

Can we simply omit the test for clang < 12?

@nathanchance
Copy link
Member Author

Sure, that would fix this immediate issue. However, it is still going to be possible for someone to call these overflow macros in a driver or core kernel code with the same types as the test (that was the original motivation for the change), which would cause this error at that point.

@nickdesaulniers
Copy link
Member

nickdesaulniers commented Sep 19, 2022

Maybe something like:

diff --git a/lib/overflow_kunit.c b/lib/overflow_kunit.c
index f385ca652b74..9240533e0283 100644
--- a/lib/overflow_kunit.c
+++ b/lib/overflow_kunit.c
@@ -716,12 +716,22 @@ static struct kunit_case overflow_test_cases[] = {
        KUNIT_CASE(u32_u32__u32_overflow_test),
        KUNIT_CASE(s32_s32__s32_overflow_test),
 /* Clang 13 and earlier generate unwanted libcalls on 32-bit. */
-#if BITS_PER_LONG == 64
+#if defined(CONFIG_CC_IS_GCC) || \
+  (defined(CONFIG_CC_IS_CLANG) && \
+    (__clang_major__ > 13 || BITS_PER_LONG == 64))
        KUNIT_CASE(u64_u64__u64_overflow_test),
        KUNIT_CASE(s64_s64__s64_overflow_test),
 #endif
-       KUNIT_CASE(u32_u32__u8_overflow_test),
+/* Clang 11 and earlier generate unwanted libcalls for signed output, unsigned
+ * input.
+ * https://github.com/llvm/llvm-project/commit/3203143f1356a4e4e3ada231156fc6da6e1a9f9d
+ * */
+#if defined(CONFIG_CC_IS_GCC) || \
+  (defined(CONFIG_CC_IS_CLANG) && \
+    (__clang_major__ > 11 || BITS_PER_LONG == 64))
        KUNIT_CASE(u32_u32__int_overflow_test),
+#endif
+       KUNIT_CASE(u32_u32__u8_overflow_test),
        KUNIT_CASE(u8_u8__int_overflow_test),
        KUNIT_CASE(int_int__u8_overflow_test),
        KUNIT_CASE(shift_sane_test),

@nathanchance
Copy link
Member Author

This is now in mainline:

https://github.com/ClangBuiltLinux/continuous-integration2/actions/runs/3179910972

I will try to test the above diff.

@nathanchance nathanchance added [BUG] linux A bug that should be fixed in the mainline kernel. and removed [BUG] linux-next This is an issue only seen in linux-next labels Oct 4, 2022
@kees
Copy link

kees commented Oct 5, 2022

Ah! Shall I take the above patch for it?

@nickdesaulniers
Copy link
Member

I'll send a formal patch today.

intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Oct 5, 2022
Building the overflow kunit tests with clang-11 fails with:

$ ./tools/testing/kunit/kunit.py run --arch=arm --make_options LLVM=1 \
overflow
...
ld.lld: error: undefined symbol: __mulodi4
...

Clang 11 and earlier generate unwanted libcalls for signed output,
unsigned input.

Disable these tests for now, but should these become used in the kernel
we might consider that as justification for dropping clang-11 support.
Keep the clang-11 build alive a little bit longer.

Avoid -Wunused-function warnings via __maybe_unused.

Link: ClangBuiltLinux#1711
Link: llvm/llvm-project@3203143
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
@nickdesaulniers
Copy link
Member

@nickdesaulniers nickdesaulniers self-assigned this Oct 6, 2022
@nickdesaulniers nickdesaulniers added the [PATCH] Submitted A patch has been submitted for review label Oct 6, 2022
@nickdesaulniers nickdesaulniers added [PATCH] Accepted A submitted patch has been accepted upstream and removed [PATCH] Submitted A patch has been submitted for review labels Oct 7, 2022
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Oct 17, 2022
Building the overflow kunit tests with clang-11 fails with:

$ ./tools/testing/kunit/kunit.py run --arch=arm --make_options LLVM=1 \
overflow
...
ld.lld: error: undefined symbol: __mulodi4
...

Clang 11 and earlier generate unwanted libcalls for signed output,
unsigned input.

Disable these tests for now, but should these become used in the kernel
we might consider that as justification for dropping clang-11 support.
Keep the clang-11 build alive a little bit longer.

Avoid -Wunused-function warnings via __maybe_unused. To test W=1:

$ make LLVM=1 -j128 defconfig
$ ./scripts/config -e KUNIT -e KUNIT_ALL
$ make LLVM=1 -j128 olddefconfig lib/overflow_kunit.o W=1

Link: ClangBuiltLinux#1711
Link: llvm/llvm-project@3203143
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221006171751.3444575-1-ndesaulniers@google.com
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Oct 19, 2022
Building the overflow kunit tests with clang-11 fails with:

$ ./tools/testing/kunit/kunit.py run --arch=arm --make_options LLVM=1 \
overflow
...
ld.lld: error: undefined symbol: __mulodi4
...

Clang 11 and earlier generate unwanted libcalls for signed output,
unsigned input.

Disable these tests for now, but should these become used in the kernel
we might consider that as justification for dropping clang-11 support.
Keep the clang-11 build alive a little bit longer.

Avoid -Wunused-function warnings via __maybe_unused. To test W=1:

$ make LLVM=1 -j128 defconfig
$ ./scripts/config -e KUNIT -e KUNIT_ALL
$ make LLVM=1 -j128 olddefconfig lib/overflow_kunit.o W=1

Link: ClangBuiltLinux#1711
Link: llvm/llvm-project@3203143
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221006171751.3444575-1-ndesaulniers@google.com
@nathanchance
Copy link
Member Author

Are those changes scheduled for 6.1 or 6.2? CI is still failing with this on mainline so it is needed there. I can just apply it to the relevant branches in CI for the time being if necessary.

@kees
Copy link

kees commented Oct 25, 2022

Hi! I originally wanted to get them out of the door for -next, and if they were happy, get them sent to Linus for 6.1 shortly.

intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Oct 25, 2022
Building the overflow kunit tests with clang-11 fails with:

$ ./tools/testing/kunit/kunit.py run --arch=arm --make_options LLVM=1 \
overflow
...
ld.lld: error: undefined symbol: __mulodi4
...

Clang 11 and earlier generate unwanted libcalls for signed output,
unsigned input.

Disable these tests for now, but should these become used in the kernel
we might consider that as justification for dropping clang-11 support.
Keep the clang-11 build alive a little bit longer.

Avoid -Wunused-function warnings via __maybe_unused. To test W=1:

$ make LLVM=1 -j128 defconfig
$ ./scripts/config -e KUNIT -e KUNIT_ALL
$ make LLVM=1 -j128 olddefconfig lib/overflow_kunit.o W=1

Link: ClangBuiltLinux#1711
Link: llvm/llvm-project@3203143
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221006171751.3444575-1-ndesaulniers@google.com
@nathanchance
Copy link
Member Author

Thanks Kees!

https://git.kernel.org/linus/0e5b9f25b27a7a92880f88f5dba3edf726ec5f61

@nathanchance nathanchance added [FIXED][LINUX] development cycle This bug was only present and fixed in a -next or -rc cycle and removed [PATCH] Accepted A submitted patch has been accepted upstream labels Oct 27, 2022
ashok-raj pushed a commit to ashok-raj/linux-ucode that referenced this issue Nov 20, 2022
Building the overflow kunit tests with clang-11 fails with:

$ ./tools/testing/kunit/kunit.py run --arch=arm --make_options LLVM=1 \
overflow
...
ld.lld: error: undefined symbol: __mulodi4
...

Clang 11 and earlier generate unwanted libcalls for signed output,
unsigned input.

Disable these tests for now, but should these become used in the kernel
we might consider that as justification for dropping clang-11 support.
Keep the clang-11 build alive a little bit longer.

Avoid -Wunused-function warnings via __maybe_unused. To test W=1:

$ make LLVM=1 -j128 defconfig
$ ./scripts/config -e KUNIT -e KUNIT_ALL
$ make LLVM=1 -j128 olddefconfig lib/overflow_kunit.o W=1

Link: ClangBuiltLinux/linux#1711
Link: llvm/llvm-project@3203143
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221006171751.3444575-1-ndesaulniers@google.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[BUG] linux A bug that should be fixed in the mainline kernel. [FIXED][LINUX] development cycle This bug was only present and fixed in a -next or -rc cycle
Projects
None yet
Development

No branches or pull requests

3 participants