Skip to content
Snippets Groups Projects
  1. Feb 12, 2024
    • Johannes Berg's avatar
      debugfs: fix automount d_fsdata usage · 0929a355
      Johannes Berg authored and Frieder Schrempf's avatar Frieder Schrempf committed
      
      [ Upstream commit 0ed04a18 ]
      
      debugfs_create_automount() stores a function pointer in d_fsdata,
      but since commit 7c8d4698 ("debugfs: add support for more
      elaborate ->d_fsdata") debugfs_release_dentry() will free it, now
      conditionally on DEBUGFS_FSDATA_IS_REAL_FOPS_BIT, but that's not
      set for the function pointer in automount. As a result, removing
      an automount dentry would attempt to free the function pointer.
      Luckily, the only user of this (tracing) never removes it.
      
      Nevertheless, it's safer if we just handle the fsdata in one way,
      namely either DEBUGFS_FSDATA_IS_REAL_FOPS_BIT or allocated. Thus,
      change the automount to allocate it, and use the real_fops in the
      data to indicate whether or not automount is filled, rather than
      adding a type tag. At least for now this isn't actually needed,
      but the next changes will require it.
      
      Also check in debugfs_file_get() that it gets only called
      on regular files, just to make things clearer.
      
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      0929a355
  2. Dec 31, 2022
  3. Sep 24, 2022
  4. Sep 05, 2022
  5. Feb 25, 2022
  6. Jan 06, 2022
  7. Sep 21, 2021
  8. Aug 05, 2021
  9. Jun 04, 2021
  10. May 21, 2021
  11. May 18, 2021
  12. May 14, 2021
  13. Apr 16, 2021
  14. Apr 09, 2021
  15. Apr 05, 2021
  16. Feb 18, 2021
  17. Jan 24, 2021
    • Christian Brauner's avatar
      fs: make helpers idmap mount aware · 549c7297
      Christian Brauner authored
      Extend some inode methods with an additional user namespace argument. A
      filesystem that is aware of idmapped mounts will receive the user
      namespace the mount has been marked with. This can be used for
      additional permission checking and also to enable filesystems to
      translate between uids and gids if they need to. We have implemented all
      relevant helpers in earlier patches.
      
      As requested we simply extend the exisiting inode method instead of
      introducing new ones. This is a little more code churn but it's mostly
      mechanical and doesnt't leave us with additional inode methods.
      
      Link: https://lore.kernel.org/r/20210121131959.646623-25-christian.brauner@ubuntu.com
      
      
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: linux-fsdevel@vger.kernel.org
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      549c7297
  18. Oct 30, 2020
  19. Sep 04, 2020
  20. Jul 23, 2020
    • Peter Enderborg's avatar
      debugfs: Add access restriction option · a24c6f7b
      Peter Enderborg authored
      
      Since debugfs include sensitive information it need to be treated
      carefully. But it also has many very useful debug functions for userspace.
      With this option we can have same configuration for system with
      need of debugfs and a way to turn it off. This gives a extra protection
      for exposure on systems where user-space services with system
      access are attacked.
      
      It is controlled by a configurable default value that can be override
      with a kernel command line parameter. (debugfs=)
      
      It can be on or off, but also internally on but not seen from user-space.
      This no-mount mode do not register a debugfs as filesystem, but client can
      register their parts in the internal structures. This data can be readed
      with a debugger or saved with a crashkernel. When it is off clients
      get EPERM error when accessing the functions for registering their
      components.
      
      Signed-off-by: default avatarPeter Enderborg <peter.enderborg@sony.com>
      Link: https://lore.kernel.org/r/20200716071511.26864-3-peter.enderborg@sony.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a24c6f7b
  21. Jul 10, 2020
  22. Apr 23, 2020
  23. Apr 17, 2020
  24. Mar 18, 2020
    • Greg Kroah-Hartman's avatar
      debugfs: remove return value of debugfs_create_file_size() · 526ee72d
      Greg Kroah-Hartman authored
      
      No one checks the return value of debugfs_create_file_size, as it's not
      needed, so make the return value void, so that no one tries to do so in
      the future.
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Link: https://lore.kernel.org/r/20200309163640.237984-1-gregkh@linuxfoundation.org
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      526ee72d
    • Taehee Yoo's avatar
      debugfs: Check module state before warning in {full/open}_proxy_open() · 275678e7
      Taehee Yoo authored
      
      When the module is being removed, the module state is set to
      MODULE_STATE_GOING. At this point, try_module_get() fails.
      And when {full/open}_proxy_open() is being called,
      it calls try_module_get() to try to hold module reference count.
      If it fails, it warns about the possibility of debugfs file leak.
      
      If {full/open}_proxy_open() is called while the module is being removed,
      it fails to hold the module.
      So, It warns about debugfs file leak. But it is not the debugfs file
      leak case. So, this patch just adds module state checking routine
      in the {full/open}_proxy_open().
      
      Test commands:
          #SHELL1
          while :
          do
              modprobe netdevsim
              echo 1 > /sys/bus/netdevsim/new_device
              modprobe -rv netdevsim
          done
      
          #SHELL2
          while :
          do
              cat /sys/kernel/debug/netdevsim/netdevsim1/ports/0/ipsec
          done
      
      Splat looks like:
      [  298.766738][T14664] debugfs file owner did not clean up at exit: ipsec
      [  298.766766][T14664] WARNING: CPU: 2 PID: 14664 at fs/debugfs/file.c:312 full_proxy_open+0x10f/0x650
      [  298.768595][T14664] Modules linked in: netdevsim(-) openvswitch nsh nf_conncount nf_nat nf_conntrack nf_defrag_ipv6 n][  298.771343][T14664] CPU: 2 PID: 14664 Comm: cat Tainted: G        W         5.5.0+ #1
      [  298.772373][T14664] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
      [  298.773545][T14664] RIP: 0010:full_proxy_open+0x10f/0x650
      [  298.774247][T14664] Code: 48 c1 ea 03 80 3c 02 00 0f 85 c1 04 00 00 49 8b 3c 24 e8 e4 b5 78 ff 84 c0 75 2d 4c 89 ee 48
      [  298.776782][T14664] RSP: 0018:ffff88805b7df9b8 EFLAGS: 00010282[  298.777583][T14664] RAX: dffffc0000000008 RBX: ffff8880511725c0 RCX: 0000000000000000
      [  298.778610][T14664] RDX: 0000000000000000 RSI: 0000000000000006 RDI: ffff8880540c5c14
      [  298.779637][T14664] RBP: 0000000000000000 R08: fffffbfff15235ad R09: 0000000000000000
      [  298.780664][T14664] R10: 0000000000000001 R11: 0000000000000000 R12: ffffffffc06b5000
      [  298.781702][T14664] R13: ffff88804c234a88 R14: ffff88804c22dd00 R15: ffffffff8a1b5660
      [  298.782722][T14664] FS:  00007fafa13a8540(0000) GS:ffff88806c800000(0000) knlGS:0000000000000000
      [  298.783845][T14664] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [  298.784672][T14664] CR2: 00007fafa0e9cd10 CR3: 000000004b286005 CR4: 00000000000606e0
      [  298.785739][T14664] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [  298.786769][T14664] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      [  298.787785][T14664] Call Trace:
      [  298.788237][T14664]  do_dentry_open+0x63c/0xf50
      [  298.788872][T14664]  ? open_proxy_open+0x270/0x270
      [  298.789524][T14664]  ? __x64_sys_fchdir+0x180/0x180
      [  298.790169][T14664]  ? inode_permission+0x65/0x390
      [  298.790832][T14664]  path_openat+0xc45/0x2680
      [  298.791425][T14664]  ? save_stack+0x69/0x80
      [  298.791988][T14664]  ? save_stack+0x19/0x80
      [  298.792544][T14664]  ? path_mountpoint+0x2e0/0x2e0
      [  298.793233][T14664]  ? check_chain_key+0x236/0x5d0
      [  298.793910][T14664]  ? sched_clock_cpu+0x18/0x170
      [  298.794527][T14664]  ? find_held_lock+0x39/0x1d0
      [  298.795153][T14664]  do_filp_open+0x16a/0x260
      [ ... ]
      
      Fixes: 9fd4dcec ("debugfs: prevent access to possibly dead file_operations at file open")
      Reported-by: default avatarkbuild test robot <lkp@intel.com>
      Signed-off-by: default avatarTaehee Yoo <ap420073@gmail.com>
      Link: https://lore.kernel.org/r/20200218043150.29447-1-ap420073@gmail.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      275678e7
  25. Feb 22, 2020
  26. Feb 10, 2020
  27. Jan 14, 2020
    • Eric Snowberg's avatar
      debugfs: Return -EPERM when locked down · a37f4958
      Eric Snowberg authored
      
      When lockdown is enabled, debugfs_is_locked_down returns 1. It will then
      trigger the following:
      
      WARNING: CPU: 48 PID: 3747
      CPU: 48 PID: 3743 Comm: bash Not tainted 5.4.0-1946.x86_64 #1
      Hardware name: Oracle Corporation ORACLE SERVER X7-2/ASM, MB, X7-2, BIOS 41060400 05/20/2019
      RIP: 0010:do_dentry_open+0x343/0x3a0
      Code: 00 40 08 00 45 31 ff 48 c7 43 28 40 5b e7 89 e9 02 ff ff ff 48 8b 53 28 4c 8b 72 70 4d 85 f6 0f 84 10 fe ff ff e9 f5 fd ff ff <0f> 0b 41 bf ea ff ff ff e9 3b ff ff ff 41 bf e6 ff ff ff e9 b4 fe
      RSP: 0018:ffffb8740dde7ca0 EFLAGS: 00010202
      RAX: ffffffff89e88a40 RBX: ffff928c8e6b6f00 RCX: 0000000000000000
      RDX: 0000000000000000 RSI: ffff928dbfd97778 RDI: ffff9285cff685c0
      RBP: ffffb8740dde7cc8 R08: 0000000000000821 R09: 0000000000000030
      R10: 0000000000000057 R11: ffffb8740dde7a98 R12: ffff926ec781c900
      R13: ffff928c8e6b6f10 R14: ffffffff8936e190 R15: 0000000000000001
      FS:  00007f45f6777740(0000) GS:ffff928dbfd80000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007fff95e0d5d8 CR3: 0000001ece562006 CR4: 00000000007606e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      PKRU: 55555554
      Call Trace:
       vfs_open+0x2d/0x30
       path_openat+0x2d4/0x1680
       ? tty_mode_ioctl+0x298/0x4c0
       do_filp_open+0x93/0x100
       ? strncpy_from_user+0x57/0x1b0
       ? __alloc_fd+0x46/0x150
       do_sys_open+0x182/0x230
       __x64_sys_openat+0x20/0x30
       do_syscall_64+0x60/0x1b0
       entry_SYSCALL_64_after_hwframe+0x170/0x1d5
      RIP: 0033:0x7f45f5e5ce02
      Code: 25 00 00 41 00 3d 00 00 41 00 74 4c 48 8d 05 25 59 2d 00 8b 00 85 c0 75 6d 89 f2 b8 01 01 00 00 48 89 fe bf 9c ff ff ff 0f 05 <48> 3d 00 f0 ff ff 0f 87 a2 00 00 00 48 8b 4c 24 28 64 48 33 0c 25
      RSP: 002b:00007fff95e0d2e0 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
      RAX: ffffffffffffffda RBX: 0000561178c069b0 RCX: 00007f45f5e5ce02
      RDX: 0000000000000241 RSI: 0000561178c08800 RDI: 00000000ffffff9c
      RBP: 00007fff95e0d3e0 R08: 0000000000000020 R09: 0000000000000005
      R10: 00000000000001b6 R11: 0000000000000246 R12: 0000000000000000
      R13: 0000000000000003 R14: 0000000000000001 R15: 0000561178c08800
      
      Change the return type to int and return -EPERM when lockdown is enabled
      to remove the warning above. Also rename debugfs_is_locked_down to
      debugfs_locked_down to make it sound less like it returns a boolean.
      
      Fixes: 5496197f ("debugfs: Restrict debugfs when the kernel is locked down")
      Signed-off-by: default avatarEric Snowberg <eric.snowberg@oracle.com>
      Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
      Cc: stable <stable@vger.kernel.org>
      Acked-by: default avatarJames Morris <jamorris@linux.microsoft.com>
      Link: https://lore.kernel.org/r/20191207161603.35907-1-eric.snowberg@oracle.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a37f4958
  28. Jan 06, 2020
    • Daniel W. S. Almeida's avatar
      debugfs: Fix warnings when building documentation · adc92dd4
      Daniel W. S. Almeida authored
      
      Fix the following warnings:
      
      fs/debugfs/inode.c:423: WARNING: Inline literal start-string without end-string.
      fs/debugfs/inode.c:502: WARNING: Inline literal start-string without end-string.
      fs/debugfs/inode.c:534: WARNING: Inline literal start-string without end-string.
      fs/debugfs/inode.c:627: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:496: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:502: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:581: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:587: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:846: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:852: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:899: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:905: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:1091: WARNING: Inline literal start-string without end-string.
      fs/debugfs/file.c:1097: WARNING: Inline literal start-string without end-string
      
      By replacing %ERR_PTR with ERR_PTR.
      
      Signed-off-by: default avatarDaniel W. S. Almeida <dwlsalmeida@gmail.com>
      Link: https://lore.kernel.org/r/20191227010035.854913-1-dwlsalmeida@gmail.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      adc92dd4
  29. Dec 11, 2019
  30. Nov 15, 2019
    • Al Viro's avatar
      new helper: lookup_positive_unlocked() · 6c2d4798
      Al Viro authored
      
      Most of the callers of lookup_one_len_unlocked() treat negatives are
      ERR_PTR(-ENOENT).  Provide a helper that would do just that.  Note
      that a pinned positive dentry remains positive - it's ->d_inode is
      stable, etc.; a pinned _negative_ dentry can become positive at any
      point as long as you are not holding its parent at least shared.
      So using lookup_one_len_unlocked() needs to be careful;
      lookup_positive_unlocked() is safer and that's what the callers
      end up open-coding anyway.
      
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      6c2d4798
  31. Nov 03, 2019
  32. Nov 02, 2019
  33. Oct 16, 2019
Loading