Skip to content
  1. Jan 04, 2024
  2. Jan 03, 2024
  3. Jan 01, 2024
  4. Dec 31, 2023
  5. Dec 30, 2023
    • Steven Rostedt (Google)'s avatar
      ftrace: Fix modification of direct_function hash while in use · d05cb470
      Steven Rostedt (Google) authored
      Masami Hiramatsu reported a memory leak in register_ftrace_direct() where
      if the number of new entries are added is large enough to cause two
      allocations in the loop:
      
              for (i = 0; i < size; i++) {
                      hlist_for_each_entry(entry, &hash->buckets[i], hlist) {
                              new = ftrace_add_rec_direct(entry->ip, addr, &free_hash);
                              if (!new)
                                      goto out_remove;
                              entry->direct = addr;
                      }
              }
      
      Where ftrace_add_rec_direct() has:
      
              if (ftrace_hash_empty(direct_functions) ||
                  direct_functions->count > 2 * (1 << direct_functions->size_bits)) {
                      struct ftrace_hash *new_hash;
                      int size = ftrace_hash_empty(direct_functions) ? 0 :
                              direct_functions->count + 1;
      
                      if (size < 32)
                              size = 32;
      
                      new_hash = dup_hash(direct_functions, size);
                      if (!new_hash)
                              return NULL;
      
                      *free_hash = direct_functions;
                      direct_functions = new_hash;
              }
      
      The "*free_hash = direct_functions;" can happen twice, losing the previous
      allocation of direct_functions.
      
      But this also exposed a more serious bug.
      
      The modification of direct_functions above is not safe. As
      direct_functions can be referenced at any time to find what direct caller
      it should call, the time between:
      
                      new_hash = dup_hash(direct_functions, size);
       and
                      direct_functions = new_hash;
      
      can have a race with another CPU (or even this one if it gets interrupted),
      and the entries being moved to the new hash are not referenced.
      
      That's because the "dup_hash()" is really misnamed and is really a
      "move_hash()". It moves the entries from the old hash to the new one.
      
      Now even if that was changed, this code is not proper as direct_functions
      should not be updated until the end. That is the best way to handle
      function reference changes, and is the way other parts of ftrace handles
      this.
      
      The following is done:
      
       1. Change add_hash_entry() to return the entry it created and inserted
          into the hash, and not just return success or not.
      
       2. Replace ftrace_add_rec_direct() with add_hash_entry(), and remove
          the former.
      
       3. Allocate a "new_hash" at the start that is made for holding both the
          new hash entries as well as the existing entries in direct_functions.
      
       4. Copy (not move) the direct_function entries over to the new_hash.
      
       5. Copy the entries of the added hash to the new_hash.
      
       6. If everything succeeds, then use rcu_pointer_assign() to update the
          direct_functions with the new_hash.
      
      This simplifies the code and fixes both the memory leak as well as the
      race condition mentioned above.
      
      Link: https://lore.kernel.org/all/170368070504.42064.8960569647118388081.stgit@devnote2/
      Link: https://lore.kernel.org/linux-trace-kernel/20231229115134.08dd5174@gandalf.local.home
      
      
      
      Cc: stable@vger.kernel.org
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Fixes: 763e34e7
      
       ("ftrace: Add register_ftrace_direct()")
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      d05cb470
    • Linus Torvalds's avatar
      Merge tag 'gpio-fixes-for-v6.7-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux · f016f754
      Linus Torvalds authored
      Pull gpio fixes from Bartosz Golaszewski:
      
       - Andy steps down as GPIO reviewer
      
       - Kent becomes a reviewer for GPIO uAPI
      
       - add missing intel file to the relevant MAINTAINERS section
      
      * tag 'gpio-fixes-for-v6.7-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux:
        MAINTAINERS: Add a missing file to the INTEL GPIO section
        MAINTAINERS: Remove Andy from GPIO maintainers
        MAINTAINERS: split out the uAPI into a new section
      f016f754
    • Linus Torvalds's avatar
      Merge tag 'platform-drivers-x86-v6.7-6' of... · e543d0b5
      Linus Torvalds authored
      Merge tag 'platform-drivers-x86-v6.7-6' of git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86
      
      Pull x86 platform driver fixes from Ilpo Järvinen:
      
       - Intel PMC GBE LTR regression
      
       - P2SB / PCI deadlock fix
      
      * tag 'platform-drivers-x86-v6.7-6' of git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86:
        platform/x86/intel/pmc: Move GBE LTR ignore to suspend callback
        platform/x86/intel/pmc: Allow reenabling LTRs
        platform/x86/intel/pmc: Add suspend callback
        platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe
      e543d0b5
    • Linus Torvalds's avatar
      Merge tag 'block-6.7-2023-12-29' of git://git.kernel.dk/linux · 09c57a76
      Linus Torvalds authored
      Pull block fixes from Jens Axboe:
       "Fix for a badly numbered flag, and a regression fix for the badblocks
        updates from this merge window"
      
      * tag 'block-6.7-2023-12-29' of git://git.kernel.dk/linux:
        block: renumber QUEUE_FLAG_HW_WC
        badblocks: avoid checking invalid range in badblocks_check()
      09c57a76
  6. Dec 29, 2023
  7. Dec 28, 2023
    • Namjae Jeon's avatar
      ksmbd: fix slab-out-of-bounds in smb_strndup_from_utf16() · d10c7787
      Namjae Jeon authored
      
      
      If ->NameOffset/Length is bigger than ->CreateContextsOffset/Length,
      ksmbd_check_message doesn't validate request buffer it correctly.
      So slab-out-of-bounds warning from calling smb_strndup_from_utf16()
      in smb2_open() could happen. If ->NameLength is non-zero, Set the larger
      of the two sums (Name and CreateContext size) as the offset and length of
      the data area.
      
      Reported-by: default avatarYang Chaoming <lometsj@live.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      d10c7787
    • Linus Torvalds's avatar
      Merge tag 'mm-hotfixes-stable-2023-12-27-15-00' of... · f5837722
      Linus Torvalds authored
      Merge tag 'mm-hotfixes-stable-2023-12-27-15-00' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
      
      Pull misc fixes from Andrew Morton:
       "11 hotfixes. 7 are cc:stable and the other 4 address post-6.6 issues
        or are not considered backporting material"
      
      * tag 'mm-hotfixes-stable-2023-12-27-15-00' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm:
        mailmap: add an old address for Naoya Horiguchi
        mm/memory-failure: cast index to loff_t before shifting it
        mm/memory-failure: check the mapcount of the precise page
        mm/memory-failure: pass the folio and the page to collect_procs()
        selftests: secretmem: floor the memory size to the multiple of page_size
        mm: migrate high-order folios in swap cache correctly
        maple_tree: do not preallocate nodes for slot stores
        mm/filemap: avoid buffered read/write race to read inconsistent data
        kunit: kasan_test: disable fortify string checker on kmalloc_oob_memset
        kexec: select CRYPTO from KEXEC_FILE instead of depending on it
        kexec: fix KEXEC_FILE dependencies
      f5837722
  8. Dec 27, 2023
  9. Dec 26, 2023
  10. Dec 24, 2023