Skip to content

Commit 5b9d406

Browse files
author
Al Viro
committed
filename_...xattr(): don't consume filename reference
Callers switched to CLASS(filename_maybe_null) (in fs/xattr.c) and CLASS(filename_complete_delayed) (in io_uring/xattr.c). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent e50aae1 commit 5b9d406

2 files changed

Lines changed: 12 additions & 29 deletions

File tree

fs/xattr.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ int file_setxattr(struct file *f, struct kernel_xattr_ctx *ctx)
649649
return error;
650650
}
651651

652-
/* unconditionally consumes filename */
653652
int filename_setxattr(int dfd, struct filename *filename,
654653
unsigned int lookup_flags, struct kernel_xattr_ctx *ctx)
655654
{
@@ -659,7 +658,7 @@ int filename_setxattr(int dfd, struct filename *filename,
659658
retry:
660659
error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
661660
if (error)
662-
goto out;
661+
return error;
663662
error = mnt_want_write(path.mnt);
664663
if (!error) {
665664
error = do_setxattr(mnt_idmap(path.mnt), path.dentry, ctx);
@@ -670,9 +669,6 @@ int filename_setxattr(int dfd, struct filename *filename,
670669
lookup_flags |= LOOKUP_REVAL;
671670
goto retry;
672671
}
673-
674-
out:
675-
putname(filename);
676672
return error;
677673
}
678674

@@ -688,7 +684,6 @@ static int path_setxattrat(int dfd, const char __user *pathname,
688684
.kname = &kname,
689685
.flags = flags,
690686
};
691-
struct filename *filename;
692687
unsigned int lookup_flags = 0;
693688
int error;
694689

@@ -702,7 +697,7 @@ static int path_setxattrat(int dfd, const char __user *pathname,
702697
if (error)
703698
return error;
704699

705-
filename = getname_maybe_null(pathname, at_flags);
700+
CLASS(filename_maybe_null, filename)(pathname, at_flags);
706701
if (!filename && dfd >= 0) {
707702
CLASS(fd, f)(dfd);
708703
if (fd_empty(f))
@@ -804,7 +799,6 @@ ssize_t file_getxattr(struct file *f, struct kernel_xattr_ctx *ctx)
804799
return do_getxattr(file_mnt_idmap(f), f->f_path.dentry, ctx);
805800
}
806801

807-
/* unconditionally consumes filename */
808802
ssize_t filename_getxattr(int dfd, struct filename *filename,
809803
unsigned int lookup_flags, struct kernel_xattr_ctx *ctx)
810804
{
@@ -813,15 +807,13 @@ ssize_t filename_getxattr(int dfd, struct filename *filename,
813807
retry:
814808
error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
815809
if (error)
816-
goto out;
810+
return error;
817811
error = do_getxattr(mnt_idmap(path.mnt), path.dentry, ctx);
818812
path_put(&path);
819813
if (retry_estale(error, lookup_flags)) {
820814
lookup_flags |= LOOKUP_REVAL;
821815
goto retry;
822816
}
823-
out:
824-
putname(filename);
825817
return error;
826818
}
827819

@@ -836,7 +828,6 @@ static ssize_t path_getxattrat(int dfd, const char __user *pathname,
836828
.kname = &kname,
837829
.flags = 0,
838830
};
839-
struct filename *filename;
840831
ssize_t error;
841832

842833
if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
@@ -846,7 +837,7 @@ static ssize_t path_getxattrat(int dfd, const char __user *pathname,
846837
if (error)
847838
return error;
848839

849-
filename = getname_maybe_null(pathname, at_flags);
840+
CLASS(filename_maybe_null, filename)(pathname, at_flags);
850841
if (!filename && dfd >= 0) {
851842
CLASS(fd, f)(dfd);
852843
if (fd_empty(f))
@@ -943,7 +934,6 @@ ssize_t file_listxattr(struct file *f, char __user *list, size_t size)
943934
return listxattr(f->f_path.dentry, list, size);
944935
}
945936

946-
/* unconditionally consumes filename */
947937
static
948938
ssize_t filename_listxattr(int dfd, struct filename *filename,
949939
unsigned int lookup_flags,
@@ -954,29 +944,26 @@ ssize_t filename_listxattr(int dfd, struct filename *filename,
954944
retry:
955945
error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
956946
if (error)
957-
goto out;
947+
return error;
958948
error = listxattr(path.dentry, list, size);
959949
path_put(&path);
960950
if (retry_estale(error, lookup_flags)) {
961951
lookup_flags |= LOOKUP_REVAL;
962952
goto retry;
963953
}
964-
out:
965-
putname(filename);
966954
return error;
967955
}
968956

969957
static ssize_t path_listxattrat(int dfd, const char __user *pathname,
970958
unsigned int at_flags, char __user *list,
971959
size_t size)
972960
{
973-
struct filename *filename;
974961
int lookup_flags;
975962

976963
if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
977964
return -EINVAL;
978965

979-
filename = getname_maybe_null(pathname, at_flags);
966+
CLASS(filename_maybe_null, filename)(pathname, at_flags);
980967
if (!filename) {
981968
CLASS(fd, f)(dfd);
982969
if (fd_empty(f))
@@ -1036,7 +1023,6 @@ static int file_removexattr(struct file *f, struct xattr_name *kname)
10361023
return error;
10371024
}
10381025

1039-
/* unconditionally consumes filename */
10401026
static int filename_removexattr(int dfd, struct filename *filename,
10411027
unsigned int lookup_flags, struct xattr_name *kname)
10421028
{
@@ -1046,7 +1032,7 @@ static int filename_removexattr(int dfd, struct filename *filename,
10461032
retry:
10471033
error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
10481034
if (error)
1049-
goto out;
1035+
return error;
10501036
error = mnt_want_write(path.mnt);
10511037
if (!error) {
10521038
error = removexattr(mnt_idmap(path.mnt), path.dentry, kname->name);
@@ -1057,16 +1043,13 @@ static int filename_removexattr(int dfd, struct filename *filename,
10571043
lookup_flags |= LOOKUP_REVAL;
10581044
goto retry;
10591045
}
1060-
out:
1061-
putname(filename);
10621046
return error;
10631047
}
10641048

10651049
static int path_removexattrat(int dfd, const char __user *pathname,
10661050
unsigned int at_flags, const char __user *name)
10671051
{
10681052
struct xattr_name kname;
1069-
struct filename *filename;
10701053
unsigned int lookup_flags;
10711054
int error;
10721055

@@ -1077,7 +1060,7 @@ static int path_removexattrat(int dfd, const char __user *pathname,
10771060
if (error)
10781061
return error;
10791062

1080-
filename = getname_maybe_null(pathname, at_flags);
1063+
CLASS(filename_maybe_null, filename)(pathname, at_flags);
10811064
if (!filename) {
10821065
CLASS(fd, f)(dfd);
10831066
if (fd_empty(f))

io_uring/xattr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags)
109109
int io_getxattr(struct io_kiocb *req, unsigned int issue_flags)
110110
{
111111
struct io_xattr *ix = io_kiocb_to_cmd(req, struct io_xattr);
112+
CLASS(filename_complete_delayed, name)(&ix->filename);
112113
int ret;
113114

114115
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
115116

116-
ret = filename_getxattr(AT_FDCWD, complete_getname(&ix->filename),
117-
LOOKUP_FOLLOW, &ix->ctx);
117+
ret = filename_getxattr(AT_FDCWD, name, LOOKUP_FOLLOW, &ix->ctx);
118118
io_xattr_finish(req, ret);
119119
return IOU_COMPLETE;
120120
}
@@ -186,12 +186,12 @@ int io_fsetxattr(struct io_kiocb *req, unsigned int issue_flags)
186186
int io_setxattr(struct io_kiocb *req, unsigned int issue_flags)
187187
{
188188
struct io_xattr *ix = io_kiocb_to_cmd(req, struct io_xattr);
189+
CLASS(filename_complete_delayed, name)(&ix->filename);
189190
int ret;
190191

191192
WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
192193

193-
ret = filename_setxattr(AT_FDCWD, complete_getname(&ix->filename),
194-
LOOKUP_FOLLOW, &ix->ctx);
194+
ret = filename_setxattr(AT_FDCWD, name, LOOKUP_FOLLOW, &ix->ctx);
195195
io_xattr_finish(req, ret);
196196
return IOU_COMPLETE;
197197
}

0 commit comments

Comments
 (0)