Skip to content
Snippets Groups Projects
  1. Mar 03, 2025
    • Nam Cao's avatar
      fs/proc: do_task_stat: Fix ESP not readable during coredump · f52cebe9
      Nam Cao authored and Frieder Schrempf's avatar Frieder Schrempf committed
      
      commit ab251dacfbae28772c897f068a4184f478189ff2 upstream.
      
      The field "eip" (instruction pointer) and "esp" (stack pointer) of a task
      can be read from /proc/PID/stat. These fields can be interesting for
      coredump.
      
      However, these fields were disabled by commit 0a1eb2d4 ("fs/proc: Stop
      reporting eip and esp in /proc/PID/stat"), because it is generally unsafe
      to do so. But it is safe for a coredumping process, and therefore
      exceptions were made:
      
        - for a coredumping thread by commit fd7d5627 ("fs/proc: Report
          eip/esp in /prod/PID/stat for coredumping").
      
        - for all other threads in a coredumping process by commit cb8f381f
          ("fs/proc/array.c: allow reporting eip/esp for all coredumping
          threads").
      
      The above two commits check the PF_DUMPCORE flag to determine a coredump thread
      and the PF_EXITING flag for the other threads.
      
      Unfortunately, commit 92307383 ("coredump:  Don't perform any cleanups
      before dumping core") moved coredump to happen earlier and before PF_EXITING is
      set. Thus, checking PF_EXITING is no longer the correct way to determine
      threads in a coredumping process.
      
      Instead of PF_EXITING, use PF_POSTCOREDUMP to determine the other threads.
      
      Checking of PF_EXITING was added for coredumping, so it probably can now be
      removed. But it doesn't hurt to keep.
      
      Fixes: 92307383 ("coredump:  Don't perform any cleanups before dumping core")
      Cc: stable@vger.kernel.org
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Acked-by: default avatarOleg Nesterov <oleg@redhat.com>
      Acked-by: default avatarKees Cook <kees@kernel.org>
      Signed-off-by: default avatarNam Cao <namcao@linutronix.de>
      Link: https://lore.kernel.org/r/d89af63d478d6c64cc46a01420b46fd6eb147d6f.1735805772.git.namcao@linutronix.de
      
      
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f52cebe9
  2. Feb 03, 2025
  3. Jan 14, 2025
  4. Sep 17, 2024
  5. Aug 12, 2024
  6. Jul 11, 2024
  7. Apr 11, 2024
  8. Mar 11, 2024
  9. Dec 12, 2023
  10. Oct 12, 2023
    • Ben Wolsieffer's avatar
      proc: nommu: fix empty /proc/<pid>/maps · 0aa88576
      Ben Wolsieffer authored and Frieder Schrempf's avatar Frieder Schrempf committed
      [ Upstream commit fe441980 ]
      
      On no-MMU, /proc/<pid>/maps reads as an empty file.  This happens because
      find_vma(mm, 0) always returns NULL (assuming no vma actually contains the
      zero address, which is normally the case).
      
      To fix this bug and improve the maintainability in the future, this patch
      makes the no-MMU implementation as similar as possible to the MMU
      implementation.
      
      The only remaining differences are the lack of hold/release_task_mempolicy
      and the extra code to shoehorn the gate vma into the iterator.
      
      This has been tested on top of 6.5.3 on an STM32F746.
      
      Link: https://lkml.kernel.org/r/20230915160055.971059-2-ben.wolsieffer@hefring.com
      
      
      Fixes: 0c563f14 ("proc: remove VMA rbtree use from nommu")
      Signed-off-by: default avatarBen Wolsieffer <ben.wolsieffer@hefring.com>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Giulio Benetti <giulio.benetti@benettiengineering.com>
      Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0aa88576
    • Ben Wolsieffer's avatar
      proc: nommu: /proc/<pid>/maps: release mmap read lock · 7181b7df
      Ben Wolsieffer authored and Frieder Schrempf's avatar Frieder Schrempf committed
      [ Upstream commit 578d7699 ]
      
      The no-MMU implementation of /proc/<pid>/map doesn't normally release
      the mmap read lock, because it uses !IS_ERR_OR_NULL(_vml) to determine
      whether to release the lock.  Since _vml is NULL when the end of the
      mappings is reached, the lock is not released.
      
      Reading /proc/1/maps twice doesn't cause a hang because it only
      takes the read lock, which can be taken multiple times and therefore
      doesn't show any problem if the lock isn't released. Instead, you need
      to perform some operation that attempts to take the write lock after
      reading /proc/<pid>/maps. To actually reproduce the bug, compile the
      following code as 'proc_maps_bug':
      
      #include <stdio.h>
      #include <unistd.h>
      #include <sys/mman.h>
      
      int main(int argc, char *argv[]) {
              void *buf;
              sleep(1);
              buf = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
              puts("mmap returned");
              return 0;
      }
      
      Then, run:
      
        ./proc_maps_bug &; cat /proc/$!/maps; fg
      
      Without this patch, mmap() will hang and the command will never
      complete.
      
      This code was incorrectly adapted from the MMU implementation, which at
      the time released the lock in m_next() before returning the last entry.
      
      The MMU implementation has diverged further from the no-MMU version since
      then, so this patch brings their locking and error handling into sync,
      fixing the bug and hopefully avoiding similar issues in the future.
      
      Link: https://lkml.kernel.org/r/20230914163019.4050530-2-ben.wolsieffer@hefring.com
      
      
      Fixes: 47fecca1 ("fs/proc/task_nommu.c: don't use priv->task->mm")
      Signed-off-by: default avatarBen Wolsieffer <ben.wolsieffer@hefring.com>
      Acked-by: default avatarOleg Nesterov <oleg@redhat.com>
      Cc: Giulio Benetti <giulio.benetti@benettiengineering.com>
      Cc: Greg Ungerer <gerg@uclinux.org>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Stable-dep-of: fe441980 ("proc: nommu: fix empty /proc/<pid>/maps")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      7181b7df
    • Aleksa Sarai's avatar
      procfs: block chmod on /proc/thread-self/comm · 30cf3d32
      Aleksa Sarai authored and Frieder Schrempf's avatar Frieder Schrempf committed
      commit ccf61486 upstream.
      
      Due to an oversight in commit 1b3044e3 ("procfs: fix pthread
      cross-thread naming if !PR_DUMPABLE") in switching from REG to NOD,
      chmod operations on /proc/thread-self/comm were no longer blocked as
      they are on almost all other procfs files.
      
      A very similar situation with /proc/self/environ was used to as a root
      exploit a long time ago, but procfs has SB_I_NOEXEC so this is simply a
      correctness issue.
      
      Ref: https://lwn.net/Articles/191954/
      
      
      Ref: 6d76fa58 ("Don't allow chmod() on the /proc/<pid>/ files")
      Fixes: 1b3044e3 ("procfs: fix pthread cross-thread naming if !PR_DUMPABLE")
      Cc: stable@vger.kernel.org # v4.7+
      Signed-off-by: default avatarAleksa Sarai <cyphar@cyphar.com>
      Message-Id: <20230713141001.27046-1-cyphar@cyphar.com>
      Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      30cf3d32
  11. Aug 17, 2023
  12. May 17, 2023
  13. Feb 09, 2023
    • Mike Kravetz's avatar
      mm: hugetlb: proc: check for hugetlb shared PMD in /proc/PID/smaps · 139f866e
      Mike Kravetz authored
      commit 3489dbb6 upstream.
      
      Patch series "Fixes for hugetlb mapcount at most 1 for shared PMDs".
      
      This issue of mapcount in hugetlb pages referenced by shared PMDs was
      discussed in [1].  The following two patches address user visible behavior
      caused by this issue.
      
      [1] https://lore.kernel.org/linux-mm/Y9BF+OCdWnCSilEu@monkey/
      
      
      This patch (of 2):
      
      A hugetlb page will have a mapcount of 1 if mapped by multiple processes
      via a shared PMD.  This is because only the first process increases the
      map count, and subsequent processes just add the shared PMD page to their
      page table.
      
      page_mapcount is being used to decide if a hugetlb page is shared or
      private in /proc/PID/smaps.  Pages referenced via a shared PMD were
      incorrectly being counted as private.
      
      To fix, check for a shared PMD if mapcount is 1.  If a shared PMD is found
      count the hugetlb page as shared.  A new helper to check for a shared PMD
      is added.
      
      [akpm@linux-foundation.org: simplification, per David]
      [akpm@linux-foundation.org: hugetlb.h: include page_ref.h for page_count()]
      Link: https://lkml.kernel.org/r/20230126222721.222195-2-mike.kravetz@oracle.com
      
      
      Fixes: 25ee01a2 ("mm: hugetlb: proc: add hugetlb-related fields to /proc/PID/smaps")
      Signed-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Acked-by: default avatarPeter Xu <peterx@redhat.com>
      Cc: David Hildenbrand <david@redhat.com>
      Cc: James Houghton <jthoughton@google.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Muchun Song <songmuchun@bytedance.com>
      Cc: Naoya Horiguchi <naoya.horiguchi@linux.dev>
      Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
      Cc: Yang Shi <shy828301@gmail.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      139f866e
    • Al Viro's avatar
      use less confusing names for iov_iter direction initializers · 5a190951
      Al Viro authored
      
      [ Upstream commit de4eda9d ]
      
      READ/WRITE proved to be actively confusing - the meanings are
      "data destination, as used with read(2)" and "data source, as
      used with write(2)", but people keep interpreting those as
      "we read data from it" and "we write data to it", i.e. exactly
      the wrong way.
      
      Call them ITER_DEST and ITER_SOURCE - at least that is harder
      to misinterpret...
      
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Stable-dep-of: 6dd88fd5 ("vhost-scsi: unbreak any layout for response")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5a190951
  14. Nov 23, 2022
  15. Oct 21, 2022
  16. Oct 03, 2022
  17. Sep 29, 2022
  18. Sep 27, 2022
Loading