* [PATCH 1/2] new helper: user_path_locked_at()
@ 2023-11-16 5:08 Al Viro
2023-11-16 5:09 ` [PATCH 2/2] bch2_ioctl_subvolume_destroy(): fix locking Al Viro
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Al Viro @ 2023-11-16 5:08 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Kent Overstreet
(in #work.namei; used for bcachefs locking fix)
From 74d016ecc1a7974664e98d1afbf649cd4e0e0423 Mon Sep 17 00:00:00 2001
From: Al Viro <viro@zeniv.linux.org.uk>
Date: Wed, 15 Nov 2023 22:41:27 -0500
Subject: [PATCH 1/2] new helper: user_path_locked_at()
Equivalent of kern_path_locked() taking dfd/userland name.
User introduced in the next commit.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/namei.c | 16 +++++++++++++---
include/linux/namei.h | 1 +
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 71c13b2990b4..3ffbe268d52c 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2573,13 +2573,13 @@ static int filename_parentat(int dfd, struct filename *name,
}
/* does lookup, returns the object with parent locked */
-static struct dentry *__kern_path_locked(struct filename *name, struct path *path)
+static struct dentry *__kern_path_locked(int dfd, struct filename *name, struct path *path)
{
struct dentry *d;
struct qstr last;
int type, error;
- error = filename_parentat(AT_FDCWD, name, 0, path, &last, &type);
+ error = filename_parentat(dfd, name, 0, path, &last, &type);
if (error)
return ERR_PTR(error);
if (unlikely(type != LAST_NORM)) {
@@ -2598,12 +2598,22 @@ static struct dentry *__kern_path_locked(struct filename *name, struct path *pat
struct dentry *kern_path_locked(const char *name, struct path *path)
{
struct filename *filename = getname_kernel(name);
- struct dentry *res = __kern_path_locked(filename, path);
+ struct dentry *res = __kern_path_locked(AT_FDCWD, filename, path);
putname(filename);
return res;
}
+struct dentry *user_path_locked_at(int dfd, const char __user *name, struct path *path)
+{
+ struct filename *filename = getname(name);
+ struct dentry *res = __kern_path_locked(dfd, filename, path);
+
+ putname(filename);
+ return res;
+}
+EXPORT_SYMBOL(user_path_locked_at);
+
int kern_path(const char *name, unsigned int flags, struct path *path)
{
struct filename *filename = getname_kernel(name);
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 3100371b5e32..74e0cc14ebf8 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -66,6 +66,7 @@ extern struct dentry *kern_path_create(int, const char *, struct path *, unsigne
extern struct dentry *user_path_create(int, const char __user *, struct path *, unsigned int);
extern void done_path_create(struct path *, struct dentry *);
extern struct dentry *kern_path_locked(const char *, struct path *);
+extern struct dentry *user_path_locked_at(int , const char __user *, struct path *);
int vfs_path_parent_lookup(struct filename *filename, unsigned int flags,
struct path *parent, struct qstr *last, int *type,
const struct path *root);
--
2.39.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] bch2_ioctl_subvolume_destroy(): fix locking
2023-11-16 5:08 [PATCH 1/2] new helper: user_path_locked_at() Al Viro
@ 2023-11-16 5:09 ` Al Viro
2023-11-16 5:10 ` [PATCH 1/2] new helper: user_path_locked_at() Al Viro
2023-11-16 21:18 ` [PATCH] fs: export getname() Kent Overstreet
2 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2023-11-16 5:09 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Kent Overstreet
(#for-bcachefs, on top of #work.namei)
From bbe6a7c899e7f265c5a6d01a178336a405e98ed6 Mon Sep 17 00:00:00 2001
From: Al Viro <viro@zeniv.linux.org.uk>
Date: Tue, 14 Nov 2023 18:52:42 -0500
Subject: [PATCH 2/2] bch2_ioctl_subvolume_destroy(): fix locking
make it use user_path_locked_at() to get the normal directory protection
for modifications, as well as stable ->d_parent and ->d_name in victim
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/bcachefs/fs-ioctl.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/fs/bcachefs/fs-ioctl.c b/fs/bcachefs/fs-ioctl.c
index 5a39bcb597a3..c5ab5a2dc9be 100644
--- a/fs/bcachefs/fs-ioctl.c
+++ b/fs/bcachefs/fs-ioctl.c
@@ -453,33 +453,36 @@ static long bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp,
static long bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp,
struct bch_ioctl_subvolume arg)
{
+ const char __user *name = (void __user *)(unsigned long)arg.dst_ptr;
struct path path;
struct inode *dir;
+ struct dentry *victim;
int ret = 0;
if (arg.flags)
return -EINVAL;
- ret = user_path_at(arg.dirfd,
- (const char __user *)(unsigned long)arg.dst_ptr,
- LOOKUP_FOLLOW, &path);
- if (ret)
- return ret;
+ victim = user_path_locked_at(arg.dirfd, name, &path);
+ if (IS_ERR(victim))
+ return PTR_ERR(victim);
- if (path.dentry->d_sb->s_fs_info != c) {
+ if (victim->d_sb->s_fs_info != c) {
ret = -EXDEV;
goto err;
}
-
- dir = path.dentry->d_parent->d_inode;
-
- ret = __bch2_unlink(dir, path.dentry, true);
- if (ret)
+ if (!d_is_positive(victim)) {
+ ret = -ENOENT;
goto err;
-
- fsnotify_rmdir(dir, path.dentry);
- d_delete(path.dentry);
+ }
+ dir = d_inode(path.dentry);
+ ret = __bch2_unlink(dir, victim, true);
+ if (!ret) {
+ fsnotify_rmdir(dir, victim);
+ d_delete(victim);
+ }
+ inode_unlock(dir);
err:
+ dput(victim);
path_put(&path);
return ret;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 1/2] new helper: user_path_locked_at()
2023-11-16 5:08 [PATCH 1/2] new helper: user_path_locked_at() Al Viro
2023-11-16 5:09 ` [PATCH 2/2] bch2_ioctl_subvolume_destroy(): fix locking Al Viro
@ 2023-11-16 5:10 ` Al Viro
2023-11-16 21:18 ` [PATCH] fs: export getname() Kent Overstreet
2 siblings, 0 replies; 6+ messages in thread
From: Al Viro @ 2023-11-16 5:10 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Kent Overstreet
On Thu, Nov 16, 2023 at 05:08:32AM +0000, Al Viro wrote:
> (in #work.namei; used for bcachefs locking fix)
> >From 74d016ecc1a7974664e98d1afbf649cd4e0e0423 Mon Sep 17 00:00:00 2001
> From: Al Viro <viro@zeniv.linux.org.uk>
> Date: Wed, 15 Nov 2023 22:41:27 -0500
> Subject: [PATCH 1/2] new helper: user_path_locked_at()
>
> Equivalent of kern_path_locked() taking dfd/userland name.
> User introduced in the next commit.
... and unless anybody objects, into #for-next it goes...
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] fs: export getname()
2023-11-16 5:08 [PATCH 1/2] new helper: user_path_locked_at() Al Viro
2023-11-16 5:09 ` [PATCH 2/2] bch2_ioctl_subvolume_destroy(): fix locking Al Viro
2023-11-16 5:10 ` [PATCH 1/2] new helper: user_path_locked_at() Al Viro
@ 2023-11-16 21:18 ` Kent Overstreet
2023-11-16 21:53 ` Al Viro
2 siblings, 1 reply; 6+ messages in thread
From: Kent Overstreet @ 2023-11-16 21:18 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, Kent Overstreet
On Thu, Nov 16, 2023 at 05:08:32AM +0000, Al Viro wrote:
> (in #work.namei; used for bcachefs locking fix)
> From 74d016ecc1a7974664e98d1afbf649cd4e0e0423 Mon Sep 17 00:00:00 2001
> From: Al Viro <viro@zeniv.linux.org.uk>
> Date: Wed, 15 Nov 2023 22:41:27 -0500
> Subject: [PATCH 1/2] new helper: user_path_locked_at()
>
> Equivalent of kern_path_locked() taking dfd/userland name.
> User introduced in the next commit.
also applying this:
-- >8 --
The locking fix in bch2_ioctl_subvolume_destroy() also needs getname()
exported; previous patch provided filename_path_locked()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
diff --git a/fs/namei.c b/fs/namei.c
index eab372e04767..83dd8b51995a 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -218,6 +218,7 @@ getname(const char __user * filename)
{
return getname_flags(filename, 0, NULL);
}
+EXPORT_SYMBOL(getname);
struct filename *
getname_kernel(const char * filename)
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] fs: export getname()
2023-11-16 21:18 ` [PATCH] fs: export getname() Kent Overstreet
@ 2023-11-16 21:53 ` Al Viro
2023-11-16 21:56 ` Kent Overstreet
0 siblings, 1 reply; 6+ messages in thread
From: Al Viro @ 2023-11-16 21:53 UTC (permalink / raw)
To: Kent Overstreet; +Cc: linux-fsdevel, Kent Overstreet
On Thu, Nov 16, 2023 at 04:18:22PM -0500, Kent Overstreet wrote:
> On Thu, Nov 16, 2023 at 05:08:32AM +0000, Al Viro wrote:
> > (in #work.namei; used for bcachefs locking fix)
> > From 74d016ecc1a7974664e98d1afbf649cd4e0e0423 Mon Sep 17 00:00:00 2001
> > From: Al Viro <viro@zeniv.linux.org.uk>
> > Date: Wed, 15 Nov 2023 22:41:27 -0500
> > Subject: [PATCH 1/2] new helper: user_path_locked_at()
> >
> > Equivalent of kern_path_locked() taking dfd/userland name.
> > User introduced in the next commit.
>
> also applying this:
> -- >8 --
>
> The locking fix in bch2_ioctl_subvolume_destroy() also needs getname()
> exported; previous patch provided filename_path_locked()
Not needed anymore...
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs: export getname()
2023-11-16 21:53 ` Al Viro
@ 2023-11-16 21:56 ` Kent Overstreet
0 siblings, 0 replies; 6+ messages in thread
From: Kent Overstreet @ 2023-11-16 21:56 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, Kent Overstreet
On Thu, Nov 16, 2023 at 09:53:56PM +0000, Al Viro wrote:
> On Thu, Nov 16, 2023 at 04:18:22PM -0500, Kent Overstreet wrote:
> > On Thu, Nov 16, 2023 at 05:08:32AM +0000, Al Viro wrote:
> > > (in #work.namei; used for bcachefs locking fix)
> > > From 74d016ecc1a7974664e98d1afbf649cd4e0e0423 Mon Sep 17 00:00:00 2001
> > > From: Al Viro <viro@zeniv.linux.org.uk>
> > > Date: Wed, 15 Nov 2023 22:41:27 -0500
> > > Subject: [PATCH 1/2] new helper: user_path_locked_at()
> > >
> > > Equivalent of kern_path_locked() taking dfd/userland name.
> > > User introduced in the next commit.
> >
> > also applying this:
> > -- >8 --
> >
> > The locking fix in bch2_ioctl_subvolume_destroy() also needs getname()
> > exported; previous patch provided filename_path_locked()
>
> Not needed anymore...
Saw your message about user_path_locked(); dropping these
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-11-16 21:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-16 5:08 [PATCH 1/2] new helper: user_path_locked_at() Al Viro
2023-11-16 5:09 ` [PATCH 2/2] bch2_ioctl_subvolume_destroy(): fix locking Al Viro
2023-11-16 5:10 ` [PATCH 1/2] new helper: user_path_locked_at() Al Viro
2023-11-16 21:18 ` [PATCH] fs: export getname() Kent Overstreet
2023-11-16 21:53 ` Al Viro
2023-11-16 21:56 ` Kent Overstreet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).