1. 28 Sep, 2022 1 commit
    • Masahiro Yamada's avatar
      kbuild: remove the target in signal traps when interrupted · a7f3257d
      Masahiro Yamada authored
      When receiving some signal, GNU Make automatically deletes the target if
      it has already been changed by the interrupted recipe.
      
      If the target is possibly incomplete due to interruption, it must be
      deleted so that it will be remade from scratch on the next run of make.
      Otherwise, the target would remain corrupted permanently because its
      timestamp had already been updated.
      
      Thanks to this behavior of Make, you can stop the build any time by
      pressing Ctrl-C, and just run 'make' to resume it.
      
      Kbuild also relies on this feature, but it is equivalently important
      for any build systems that make decisions based on timestamps (if you
      want to support Ctrl-C reliably).
      
      However, this does not always work as claimed; Make immediately dies
      with Ctrl-C if its stderr goes into a pipe.
      
        [Test Makefile]
      
          foo:
                  echo hello > $@
                  sleep 3
                  echo world >> $@
      
        [Test Result]
      
          $ make                         # hit Ctrl-C
          echo hello > foo
          sleep 3
          ^Cmake: *** Deleting file 'foo'
          make: *** [Makefile:3: foo] Interrupt
      
          $ make 2>&1 | cat              # hit Ctrl-C
          echo hello > foo
          sleep 3
          ^C$                            # 'foo' is often left-over
      
      The reason is because SIGINT is sent to the entire process group.
      In this example, SIGINT kills 'cat', and 'make' writes the message to
      the closed pipe, then dies with SIGPIPE before cleaning the target.
      
      A typical bad scenario (as reported by [1], [2]) is to save build log
      by using the 'tee' command:
      
          $ make 2>&1 | tee log
      
      This can be problematic for any build systems based on Make, so I hope
      it will be fixed in GNU Make. The maintainer of GNU Make stated this is
      a long-standing issue and difficult to fix [3]. It has not been fixed
      yet as of writing.
      
      So, we cannot rely on Make cleaning the target. We can do it by
      ourselves, in signal traps.
      
      As far as I understand, Make takes care of SIGHUP, SIGINT, SIGQUIT, and
      SITERM for the target removal. I added the traps for them, and also for
      SIGPIPE just in case cmd_* rule prints something to stdout or stderr
      (but I did not observe an actual case where SIGPIPE was triggered).
      
      [Note 1]
      
      The trap handler might be worth explaining.
      
          rm -f $@; trap - $(sig); kill -s $(sig) $$
      
      This lets the shell kill itself by the signal it caught, so the parent
      process can tell the child has exited on the signal. Generally, this is
      a proper manner for handling signals, in case the calling program (like
      Bash) may monitor WIFSIGNALED() and WTERMSIG() for WCE although this may
      not be a big deal here because GNU Make handles SIGHUP, SIGINT, SIGQUIT
      in WUE and SIGTERM in IUE.
      
        IUE - Immediate Unconditional Exit
        WUE - Wait and Unconditional Exit
        WCE - Wait and Cooperative Exit
      
      For details, see "Proper handling of SIGINT/SIGQUIT" [4].
      
      [Note 2]
      
      Reverting 392885ee ("kbuild: let fixdep directly write to .*.cmd
      files") would directly address [1], but it only saves if_changed_dep.
      As reported in [2], all commands that use redirection can potentially
      leave an empty (i.e. broken) target.
      
      [Note 3]
      
      Another (even safer) approach might be to always write to a temporary
      file, and rename it to $@ at the end of the recipe.
      
         <command>  > $(tmp-target)
         mv $(tmp-target) $@
      
      It would require a lot of Makefile changes, and result in ugly code,
      so I did not take it.
      
      [Note 4]
      
      A little more thoughts about a pattern rule with multiple targets (or
      a grouped target).
      
          %.x %.y: %.z
                  <recipe>
      
      When interrupted, GNU Make deletes both %.x and %.y, while this solution
      only deletes $@. Probably, this is not a big deal. The next run of make
      will execute the rule again to create $@ along with the other files.
      
      [1]: https://lore.kernel.org/all/YLeot94yAaM4xbMY@gmail.com/
      [2]: https://lore.kernel.org/all/20220510221333.2770571-1-robh@kernel.org/
      [3]: https://lists.gnu.org/archive/html/help-make/2021-06/msg00001.html
      [4]: https://www.cons.org/cracauer/sigint.html
      
      Fixes: 392885ee ("kbuild: let fixdep directly write to .*.cmd files")
      Reported-by: default avatarIngo Molnar <mingo@kernel.org>
      Reported-by: default avatarRob Herring <robh@kernel.org>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: default avatarIngo Molnar <mingo@kernel.org>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      a7f3257d
  2. 25 Sep, 2022 8 commits
  3. 24 Sep, 2022 10 commits
  4. 23 Sep, 2022 18 commits
  5. 22 Sep, 2022 3 commits
    • Linus Torvalds's avatar
      Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi · bf682942
      Linus Torvalds authored
      Pull SCSI fixes from James Bottomley:
       "Three small and pretty obvious fixes, all in drivers"
      
      * tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi:
        scsi: mpt3sas: Fix return value check of dma_get_required_mask()
        scsi: qla2xxx: Fix memory leak in __qlt_24xx_handle_abts()
        scsi: qedf: Fix a UAF bug in __qedf_probe()
      bf682942
    • Linus Torvalds's avatar
      Merge tag 'slab-for-6.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab · 3c0f396a
      Linus Torvalds authored
      Pull slab fixes from Vlastimil Babka:
      
       - Fix a possible use-after-free in SLUB's kmem_cache removal,
         introduced in this cycle, by Feng Tang.
      
       - WQ_MEM_RECLAIM dependency fix for the workqueue-based cpu slab
         flushing introduced in 5.15, by Maurizio Lombardi.
      
       - Add missing KASAN hooks in two kmalloc entry paths, by Peter
         Collingbourne.
      
       - A BUG_ON() removal in SLUB's kmem_cache creation when allocation
         fails (too small to possibly happen in practice, syzbot used fault
         injection), by Chao Yu.
      
      * tag 'slab-for-6.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab:
        mm: slub: fix flush_cpu_slab()/__free_slab() invocations in task context.
        mm/slab_common: fix possible double free of kmem_cache
        kasan: call kasan_malloc() from __kmalloc_*track_caller()
        mm/slub: fix to return errno if kmalloc() fails
      3c0f396a
    • Sean Christopherson's avatar
      KVM: x86: Inject #UD on emulated XSETBV if XSAVES isn't enabled · 50b2d49b
      Sean Christopherson authored
      Inject #UD when emulating XSETBV if CR4.OSXSAVE is not set.  This also
      covers the "XSAVE not supported" check, as setting CR4.OSXSAVE=1 #GPs if
      XSAVE is not supported (and userspace gets to keep the pieces if it
      forces incoherent vCPU state).
      
      Add a comment to kvm_emulate_xsetbv() to call out that the CPU checks
      CR4.OSXSAVE before checking for intercepts.  AMD'S APM implies that #UD
      has priority (says that intercepts are checked before #GP exceptions),
      while Intel's SDM says nothing about interception priority.  However,
      testing on hardware shows that both AMD and Intel CPUs prioritize the #UD
      over interception.
      
      Fixes: 02d4160f ("x86: KVM: add xsetbv to the emulator")
      Cc: stable@vger.kernel.org
      Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20220824033057.3576315-4-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      50b2d49b