[PATCH 00/10] Towards safer path_* API

Mateusz Guzik posted 10 patches 1 week, 4 days ago
drivers/block/loop.c               |  3 +-
fs/autofs/dev-ioctl.c              |  3 +-
fs/autofs/expire.c                 |  4 +--
fs/backing-file.c                  |  2 --
fs/devpts/inode.c                  |  6 ++--
fs/failfs.c                        |  3 +-
fs/fhandle.c                       |  3 +-
fs/file_attr.c                     |  6 ++--
fs/file_table.c                    |  3 +-
fs/fs_struct.c                     |  6 ++--
fs/namei.c                         | 44 ++++++++++++++++++++++++------
fs/namespace.c                     |  3 +-
fs/nfsd/export.c                   |  6 ++--
fs/nfsd/nfs4xdr.c                  |  8 +++---
fs/notify/fanotify/fanotify.c      |  6 ++--
fs/notify/fanotify/fanotify_user.c |  3 +-
fs/nsfs.c                          |  3 +-
fs/open.c                          | 10 ++-----
fs/overlayfs/params.c              |  3 +-
fs/pidfs.c                         |  3 +-
fs/proc/base.c                     |  6 ++--
fs/proc/fd.c                       |  3 +-
fs/smb/server/vfs.c                |  3 +-
fs/xfs/xfs_handle.c                |  3 +-
include/linux/path.h               | 14 ++++++++--
kernel/trace/bpf_trace.c           |  3 +-
security/apparmor/task.c           |  3 +-
security/keys/big_key.c            |  3 +-
security/landlock/fs.c             |  3 +-
security/landlock/syscalls.c       |  3 +-
30 files changed, 87 insertions(+), 85 deletions(-)
[PATCH 00/10] Towards safer path_* API
Posted by Mateusz Guzik 1 week, 4 days ago
Currently the handling is highly error-prone with consumers allowed to
arbitrarily manipulate references, notably with path_get().

In the past this resulted in preventable bugs.

The end goal, not yet achieved with this patchset, will provide an
invariant that a populated 'struct path' has precisely one set of
references on it.

While consumers can still cause leaks by neglecting to path_put(), the
footgun of path_get() can be eliminated.

With this patchset instead of hand-rolling a path copy and issuing
path_get() on it, callers can resort to path_clone() instead.

Almost all path_get() consumers get converted, most of which with
coccinelle.

Few instances are left until I figure out a nice way to sort them out.

Overall almost entirety of this patchset is a NOP.

Mateusz Guzik (10):
  fs: unexport backing_file_set_user_path() and make it take the ref on
    its own
  fs: add path_create(), path_move() and path_clone()
  fs: use path_clone() in path_init()
  fs: use path_clone() and path_move() in vfs_open*
  fs: use path_clone() in backing_file_set_user_path()
  Coccinelle-based conversion of path_* consumers to use the new
    primitives
  autofs: use path_create()
  fsnotify: use path_clone()
  proc: use path_clone()
  nfsd: use path_clone()

 drivers/block/loop.c               |  3 +-
 fs/autofs/dev-ioctl.c              |  3 +-
 fs/autofs/expire.c                 |  4 +--
 fs/backing-file.c                  |  2 --
 fs/devpts/inode.c                  |  6 ++--
 fs/failfs.c                        |  3 +-
 fs/fhandle.c                       |  3 +-
 fs/file_attr.c                     |  6 ++--
 fs/file_table.c                    |  3 +-
 fs/fs_struct.c                     |  6 ++--
 fs/namei.c                         | 44 ++++++++++++++++++++++++------
 fs/namespace.c                     |  3 +-
 fs/nfsd/export.c                   |  6 ++--
 fs/nfsd/nfs4xdr.c                  |  8 +++---
 fs/notify/fanotify/fanotify.c      |  6 ++--
 fs/notify/fanotify/fanotify_user.c |  3 +-
 fs/nsfs.c                          |  3 +-
 fs/open.c                          | 10 ++-----
 fs/overlayfs/params.c              |  3 +-
 fs/pidfs.c                         |  3 +-
 fs/proc/base.c                     |  6 ++--
 fs/proc/fd.c                       |  3 +-
 fs/smb/server/vfs.c                |  3 +-
 fs/xfs/xfs_handle.c                |  3 +-
 include/linux/path.h               | 14 ++++++++--
 kernel/trace/bpf_trace.c           |  3 +-
 security/apparmor/task.c           |  3 +-
 security/keys/big_key.c            |  3 +-
 security/landlock/fs.c             |  3 +-
 security/landlock/syscalls.c       |  3 +-
 30 files changed, 87 insertions(+), 85 deletions(-)

-- 
2.53.0
Re: [PATCH 00/10] Towards safer path_* API
Posted by Jan Kara 1 week, 4 days ago
On Sun 13-09-26 16:49:07, Mateusz Guzik wrote:
> Currently the handling is highly error-prone with consumers allowed to
> arbitrarily manipulate references, notably with path_get().
> 
> In the past this resulted in preventable bugs.
> 
> The end goal, not yet achieved with this patchset, will provide an
> invariant that a populated 'struct path' has precisely one set of
> references on it.
> 
> While consumers can still cause leaks by neglecting to path_put(), the
> footgun of path_get() can be eliminated.
> 
> With this patchset instead of hand-rolling a path copy and issuing
> path_get() on it, callers can resort to path_clone() instead.
> 
> Almost all path_get() consumers get converted, most of which with
> coccinelle.
> 
> Few instances are left until I figure out a nice way to sort them out.
> 
> Overall almost entirety of this patchset is a NOP.

I like most of the changes. Just the changes to path_init() kind of leave a
bad taste because they leave struct path assignment there for the RCU
lookup mode. But I don't see a nicer way of dealing with it.

								Honza

> 
> Mateusz Guzik (10):
>   fs: unexport backing_file_set_user_path() and make it take the ref on
>     its own
>   fs: add path_create(), path_move() and path_clone()
>   fs: use path_clone() in path_init()
>   fs: use path_clone() and path_move() in vfs_open*
>   fs: use path_clone() in backing_file_set_user_path()
>   Coccinelle-based conversion of path_* consumers to use the new
>     primitives
>   autofs: use path_create()
>   fsnotify: use path_clone()
>   proc: use path_clone()
>   nfsd: use path_clone()
> 
>  drivers/block/loop.c               |  3 +-
>  fs/autofs/dev-ioctl.c              |  3 +-
>  fs/autofs/expire.c                 |  4 +--
>  fs/backing-file.c                  |  2 --
>  fs/devpts/inode.c                  |  6 ++--
>  fs/failfs.c                        |  3 +-
>  fs/fhandle.c                       |  3 +-
>  fs/file_attr.c                     |  6 ++--
>  fs/file_table.c                    |  3 +-
>  fs/fs_struct.c                     |  6 ++--
>  fs/namei.c                         | 44 ++++++++++++++++++++++++------
>  fs/namespace.c                     |  3 +-
>  fs/nfsd/export.c                   |  6 ++--
>  fs/nfsd/nfs4xdr.c                  |  8 +++---
>  fs/notify/fanotify/fanotify.c      |  6 ++--
>  fs/notify/fanotify/fanotify_user.c |  3 +-
>  fs/nsfs.c                          |  3 +-
>  fs/open.c                          | 10 ++-----
>  fs/overlayfs/params.c              |  3 +-
>  fs/pidfs.c                         |  3 +-
>  fs/proc/base.c                     |  6 ++--
>  fs/proc/fd.c                       |  3 +-
>  fs/smb/server/vfs.c                |  3 +-
>  fs/xfs/xfs_handle.c                |  3 +-
>  include/linux/path.h               | 14 ++++++++--
>  kernel/trace/bpf_trace.c           |  3 +-
>  security/apparmor/task.c           |  3 +-
>  security/keys/big_key.c            |  3 +-
>  security/landlock/fs.c             |  3 +-
>  security/landlock/syscalls.c       |  3 +-
>  30 files changed, 87 insertions(+), 85 deletions(-)
> 
> -- 
> 2.53.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
Re: [PATCH 00/10] Towards safer path_* API
Posted by NeilBrown 1 week, 3 days ago
On Mon, 14 Sep 2026, Mateusz Guzik wrote:
> Currently the handling is highly error-prone with consumers allowed to
> arbitrarily manipulate references, notably with path_get().
> 
> In the past this resulted in preventable bugs.

Can you provide a reference to one or two of these bugs.  That would be
useful context.  Thanks.

NeilBrown


> 
> The end goal, not yet achieved with this patchset, will provide an
> invariant that a populated 'struct path' has precisely one set of
> references on it.
> 
> While consumers can still cause leaks by neglecting to path_put(), the
> footgun of path_get() can be eliminated.
> 
> With this patchset instead of hand-rolling a path copy and issuing
> path_get() on it, callers can resort to path_clone() instead.
> 
> Almost all path_get() consumers get converted, most of which with
> coccinelle.
> 
> Few instances are left until I figure out a nice way to sort them out.
> 
> Overall almost entirety of this patchset is a NOP.
> 
> Mateusz Guzik (10):
>   fs: unexport backing_file_set_user_path() and make it take the ref on
>     its own
>   fs: add path_create(), path_move() and path_clone()
>   fs: use path_clone() in path_init()
>   fs: use path_clone() and path_move() in vfs_open*
>   fs: use path_clone() in backing_file_set_user_path()
>   Coccinelle-based conversion of path_* consumers to use the new
>     primitives
>   autofs: use path_create()
>   fsnotify: use path_clone()
>   proc: use path_clone()
>   nfsd: use path_clone()
> 
>  drivers/block/loop.c               |  3 +-
>  fs/autofs/dev-ioctl.c              |  3 +-
>  fs/autofs/expire.c                 |  4 +--
>  fs/backing-file.c                  |  2 --
>  fs/devpts/inode.c                  |  6 ++--
>  fs/failfs.c                        |  3 +-
>  fs/fhandle.c                       |  3 +-
>  fs/file_attr.c                     |  6 ++--
>  fs/file_table.c                    |  3 +-
>  fs/fs_struct.c                     |  6 ++--
>  fs/namei.c                         | 44 ++++++++++++++++++++++++------
>  fs/namespace.c                     |  3 +-
>  fs/nfsd/export.c                   |  6 ++--
>  fs/nfsd/nfs4xdr.c                  |  8 +++---
>  fs/notify/fanotify/fanotify.c      |  6 ++--
>  fs/notify/fanotify/fanotify_user.c |  3 +-
>  fs/nsfs.c                          |  3 +-
>  fs/open.c                          | 10 ++-----
>  fs/overlayfs/params.c              |  3 +-
>  fs/pidfs.c                         |  3 +-
>  fs/proc/base.c                     |  6 ++--
>  fs/proc/fd.c                       |  3 +-
>  fs/smb/server/vfs.c                |  3 +-
>  fs/xfs/xfs_handle.c                |  3 +-
>  include/linux/path.h               | 14 ++++++++--
>  kernel/trace/bpf_trace.c           |  3 +-
>  security/apparmor/task.c           |  3 +-
>  security/keys/big_key.c            |  3 +-
>  security/landlock/fs.c             |  3 +-
>  security/landlock/syscalls.c       |  3 +-
>  30 files changed, 87 insertions(+), 85 deletions(-)
> 
> -- 
> 2.53.0
> 
> 
>