Skip to content

"stack smashing detected" since recent 23.05 upstream change when entering nix-shell with buildFHSUserEnv #262080

Closed

Description

@phip1611

Describe the bug

I'm on a flake-based system with NixOS 23.05 on a x86_64 machine.

I have a reproducible bug that came in very lately in NixOS 23.05 stable. When opening a nix-shell in a specific project, the nix-shell itself creates a pkgs.buildFHSUserEnv with many inputs and end's up with the following error:

image

It's hard to create a minimal example and I can't provide you the original nix-shell as it relies on some company-internal Nix files.

I know that rev 5a237ae (nixos-23.05 branch) from October 7th works and the NixOS 23.05 branch head from October 18th doesn't work. I verified that the issue is not caused by the Linux kernel update from 6.5.5 to 6.5.7. I think it's glibc or another very basic component.

I tried to do some kind of "manual bisecting" by going commit by commit through the log and build my NixOS system based on that nixpkgs version, but this failed as my system tried to build like everything from nixpkgs, i.e., all the derivations aren't cached (anymore).

Steps To Reproduce

I'm sorry that I can't provide a real reproducer now due to the limitations mentioned above.

Expected behavior

A normal nix-shell should open.

Screenshots

image

Additional context

None.

Notify maintainers

Not sure who is in charge as it is not clear what the problem is.

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.58, NixOS, 23.05 (Stoat), 23.05.20231017.b5f8ec6`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.5`
 - channels(pschuster): `""`
 - channels(root): `""`
 - nixpkgs: `/nix/store/37yxpbic78zskxf2di9nbkf0673gjh1p-source`

Activity

  1. added
    0.kind: bug
    on Oct 19, 2023
  2. phip1611 commented on Oct 19, 2023

    @phip1611
    MemberAuthor

    The message comes from the stack protector compiled into the binary by gcc, if I'm not mistaken. Maybe this is the root cause as something has changed their?

  3. Hermitter commented on Oct 19, 2023

    @Hermitter

    image
    I'm encountering the same issue when I use vscode-fhs

  4. NateWright commented on Oct 20, 2023

    @NateWright
    Contributor

    I am having a similar problem when using vscode-fhs or unstable vscode-fhs. Plugins are crashing and terminal isn't working saying stack smashing detected.

  5. phip1611 commented on Oct 20, 2023

    @phip1611
    MemberAuthor

    @NateWright @Hermitter Do you both mean that the bug on your side also just occurs very recently?

  6. NateWright commented on Oct 20, 2023

    @NateWright
    Contributor

    @phip1611 Yes as of a few days ago.

  7. Hermitter commented on Oct 20, 2023

    @Hermitter

    @phip1611 For me it started 2 days ago

  8. dverlan commented on Oct 23, 2023

    @dverlan

    Same here - getting this error when trying to open terminal / github / etc. in intellij-idea (both community and ultimate) via flake.nix that defines fhs

    flake.nix file:

    {
      # Flake.nix with FHSEnv to run idea-community so that github copilot plugin works
      # Made for SD class in IST, feel free to improve it
      # You can run idea-community by typing "nix run .#fhs_env" in the dev shell
      inputs = {
        nixpkgs.url = "github:NixOS/nixpkgs";
        flake-utils.url = "github:numtide/flake-utils";
      };
    
      
    outputs = { nixpkgs, flake-utils, ... }:
        flake-utils.lib.eachDefaultSystem (system:
          let
            pkgs = import nixpkgs { inherit system; };
          in
          {
            devShell = pkgs.mkShell {
              buildInputs = with pkgs; [
              ];
            };
            apps.fhs_env = {
              type = "app";
              program = let drv = pkgs.buildFHSUserEnv {
                name = "idea-ultimate";
                targetPkgs = pkgs: ( with pkgs; [
                  jetbrains.idea-ultimate
                ]);
                runScript = "idea-ultimate";
              }; in "${drv}/bin/idea-ultimate";
            };
          }
        );
    }
    

    Running this as:

    cdc <folder with flake.nix>
    nix develop
    export NIXPKGS_ALLOW_UNFREE=1 && nix run .#fhs_env --impure &> /tmp/idea-run-log &
    

    Not getting the "stack smashing detected" error when running idea without fhs - however this doesn't work for me for another reason, github copilot login is not working, so I am using a variation of this workaround.

    Example of stack trace:

    2023-10-23 11:21:02,445 [   6323]   WARN - #git4idea.repo.GitUntrackedFilesHolder - *** stack smashing detected ***: terminated
    com.intellij.openapi.vcs.VcsException: *** stack smashing detected ***: terminated
            at git4idea.commands.GitCommandResult.throwOnError(GitCommandResult.java:156)
            at git4idea.commands.GitCommandResult.getOutputOrThrow(GitCommandResult.java:145)
            at git4idea.index.GitIndexStatusUtilKt.getFileStatus(GitIndexStatusUtil.kt:84)
            at git4idea.repo.GitUntrackedFilesHolder.refreshFiles(GitUntrackedFilesHolder.java:351)
            at git4idea.repo.GitUntrackedFilesHolder.update(GitUntrackedFilesHolder.java:249)
            at com.intellij.util.ui.update.DisposableUpdate$1.doRun(DisposableUpdate.java:31)
            at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:186)
            at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
            at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
            at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
            at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
            at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
            at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:173)
            at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:361)
            at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:339)
            at com.intellij.util.ui.update.DisposableUpdate.run(DisposableUpdate.java:19)
            at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:350)
            at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:340)
            at com.intellij.util.ui.update.MergingUpdateQueue.doExecute(MergingUpdateQueue.java:297)
            at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:280)
            at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:245)
            at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:249)
            at com.intellij.util.Alarm$Request.runSafely(Alarm.java:365)
            at com.intellij.util.Alarm$Request.run(Alarm.java:354)
            at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
            at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
            at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:272)
            at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:248)
            at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:28)
            at com.intellij.util.concurrency.BoundedTaskExecutor$1.executeFirstTaskAndHelpQueue(BoundedTaskExecutor.java:221)
            at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:227)
            at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:210)
            at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
            at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
            at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
            at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
            at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
            at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
            at java.base/java.lang.Thread.run(Thread.java:833)
    
  9. danc86 commented on Oct 23, 2023

    @danc86
    Contributor

    I started seeing this today in my buildFHSUserEnv shells also. Just an empty environment is enough to see the "stack smashing detected". Here is a minimal shell.nix to reproduce (I use a version of this shell.nix with extra packages and hacks, to compile buildroot packages):

    let
      pkgs = import <nixpkgs> { };
    in (pkgs.buildFHSUserEnv {
      name = "issue-262080-repro";
    }).env
    

    Previous behaviour (good):

    $ nix-shell shell-test.nix
    
    [dan@host:~/src/buildroot]$
    

    New behaviour (bad):

    $ nix-shell shell-test.nix
    *** stack smashing detected ***: terminated
    
    [dan@host:~/src/buildroot]$ 
    

    I'm not sure what exactly is crashing with the stack smashing error, I assume it's just some program being executed inside the various shell startup scripts for buildFHSUserEnv.

    The regression range is 32dcb45..5550a85 on nixos-23.05. I'm bisecting now but it's taking some time to build everything from source on some commits.

  10. danc86 commented on Oct 23, 2023

    @danc86
    Contributor

    I realised I can do git bisect --first-parent to first find the PR merge commit which introduced the problem. That pointed to #260159 which included a glibc update 894988b which is the most likely culprit. I'm just checking it now.

  11. danc86 commented on Oct 24, 2023

    @danc86
    Contributor

    After quite a bit of rebuilding the world, I confirmed that the glibc: 2.37-8 -> 2.37-39 update 894988b is the commit which introduced this problem.

    The crash when entering the buildFHSUserEnv shell, shown in my previous comments, comes from dircolors which is executed by /etc/bashrc. But many other programs die in the same way when they're executed in the FHS shell.

    Issue #262775 points out that LD_LIBRARY_PATH is being set by buildFHSUserEnv and I found that if I unset LD_LIBRARY_PATH then the crashes go away. But I'm not sure how the glibc update from 2.37-8 to 2.37-39 is related.

  12. phip1611 commented on Oct 24, 2023

    @phip1611
    MemberAuthor

    @danc86 thanks for the investigation! @blitz and I try to debug the issue further in a session today - let's see if we trace down the root cause and possibly find solution

  13. blitz commented on Oct 24, 2023

    @blitz
    Contributor

    I can reproduce the crash. I get the following LD_LIBRARY_PATH:

    /run/opengl-driver/lib:/run/opengl-driver-32/lib:/usr/lib:/usr/lib32:/nix/store/jv2zvh0h6ippks9ib0ii6gwxmnypfi5r-pipewire-0.3.71-jack/lib
    

    If I remove /usr/lib, the crash disappears.

    The crashdump I get says this:

                    #0  0x00007f9878dfdadc __pthread_kill_implementation (/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 + 0x87adc)
                    #1  0x00007f9878daecb6 raise (/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 + 0x38cb6)
                    #2  0x00007f9878d988ba abort (/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 + 0x228ba)
                    #3  0x00007f9878d995f5 __libc_message.cold (/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 + 0x235f5)
                    #4  0x00007f9878e8d629 __fortify_fail (/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 + 0x117629)
                    #5  0x00007f9878e8d604 __stack_chk_fail (/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 + 0x117604)
                    #6  0x00007f9878df86c1 __lll_elision_init (/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6 + 0x826c1)
                    #7  0x00007f987915bfa3 dl_main (ld-linux-x86-64.so.2 + 0x1dfa3)
                    #8  0x00007f9879158703 _dl_sysdep_start (ld-linux-x86-64.so.2 + 0x1a703)
                    #9  0x00007f9879159e1e _dl_start (ld-linux-x86-64.so.2 + 0x1be1e)
                    #10 0x00007f9879158cd8 _start (ld-linux-x86-64.so.2 + 0x1acd8)
    
  14. Atemu commented on Oct 25, 2023

    @Atemu
    Member

    Could someone do a first-parent bisect to figure out what triggered this?

  15. blitz commented on Oct 25, 2023

    @blitz
    Contributor

    @Atemu See #262080 (comment).

    But depending on the reproducer this either introduces or fixes the issue. My current hypothesis is that the real issue is #262775 and the glibc update just shuffles things around a bit to make it work/fail depending on the circumstance.

  16. Atemu commented on Oct 25, 2023

    @Atemu
    Member

    Ah, missed that, thanks. Yeah, I suspect the latter too.

  17. nixos-discourse commented on Oct 27, 2023

    @nixos-discourse
  18. added
    0.kind: regression
    on Nov 5, 2023
  19. nixos-discourse commented on Nov 12, 2023

    @nixos-discourse
  20. Atemu commented on Nov 12, 2023

    @Atemu
    Member

    The above is not related to buildFHSEnv.

    Does anyone still experience this?

  21. danc86 commented on Nov 12, 2023

    @danc86
    Contributor

    I had been doing this as a workaround:

      profile = ''
        unset LD_LIBRARY_PATH
      '';
    

    With latest nixos-23.05 branch my workaround isn't needed. Looks like #263378 has fixed this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug0.kind: regression

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions