Skip to content

"copy source size is too small" after LLVM commit 3589cacfa8da89b9b5051e4dba659caa575e6b3f #2007

Closed
@nathanchance

Description

@nathanchance

After llvm/llvm-project@3589cac, I see the following error when building ARCH=x86_64 allmodconfig, which enables CONFIG_KCSAN (i.e, -fsanitize=thread):

$ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 clean allmodconfig net/bluetooth/sco.o
In file included from net/bluetooth/sco.c:27:
In file included from include/linux/module.h:13:
In file included from include/linux/stat.h:19:
In file included from include/linux/time.h:60:
In file included from include/linux/time32.h:13:
In file included from include/linux/timex.h:67:
In file included from arch/x86/include/asm/timex.h:6:
In file included from arch/x86/include/asm/tsc.h:10:
In file included from arch/x86/include/asm/msr.h:15:
In file included from include/linux/percpu.h:7:
In file included from include/linux/smp.h:118:
include/linux/thread_info.h:244:4: error: call to '__bad_copy_from' declared with 'error' attribute: copy source size is too small
  244 |                         __bad_copy_from();
      |                         ^
1 error generated.

which comes from check_copy_size() in copy_to_user(). I also see the same error emitted in net/bluetooth/l2cap_sock.c. If I disable CONFIG_KCSAN, there is no error. The parent of 3589cacfa8da89b9b5051e4dba659caa575e6b3f does not show this error and GCC does not show an error either, so I am not sure the kernel code is at fault here but I could be missing something obvious.

I tried adding 0 && to the if statements with copy_to_user() in net/bluetooth/sco.c to see if it was one particular statement causing an issue but applying it to either if (copy_to_user(optval, (char *)&opts, len)) or if (copy_to_user(optval, (char *)&cinfo, len)) prevents the error from appearing, which seems rather strange to me.

I am still working on teasing out a small reproducer. If this seems like an non-Linux kernel specific issue, I am happy to file a report upstream.

cc @dtcxzyw @nikic

Metadata

Metadata

Assignees

No one assigned

    Labels

    Reported upstreamThis bug was filed on LLVM’s issue tracker, Phabricator, or the kernel mailing list.[ARCH] x86_64This bug impacts ARCH=x86_64[BUG] llvm (main)A bug in an unreleased version of LLVM (this label is appropriate for regressions)[FIXED][LINUX] 6.9This bug was fixed in Linux 6.9

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions