Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
0460b2a2
Commit
0460b2a2
authored
Apr 08, 2017
by
Al Viro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
readdir: move compat syscalls from compat.c
Signed-off-by:
Al Viro
<
viro@zeniv.linux.org.uk
>
parent
4ada54ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
165 additions
and
162 deletions
+165
-162
fs/compat.c
fs/compat.c
+0
-162
fs/readdir.c
fs/readdir.c
+165
-0
No files found.
fs/compat.c
View file @
0460b2a2
...
...
@@ -548,168 +548,6 @@ COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
return
retval
;
}
struct
compat_old_linux_dirent
{
compat_ulong_t
d_ino
;
compat_ulong_t
d_offset
;
unsigned
short
d_namlen
;
char
d_name
[
1
];
};
struct
compat_readdir_callback
{
struct
dir_context
ctx
;
struct
compat_old_linux_dirent
__user
*
dirent
;
int
result
;
};
static
int
compat_fillonedir
(
struct
dir_context
*
ctx
,
const
char
*
name
,
int
namlen
,
loff_t
offset
,
u64
ino
,
unsigned
int
d_type
)
{
struct
compat_readdir_callback
*
buf
=
container_of
(
ctx
,
struct
compat_readdir_callback
,
ctx
);
struct
compat_old_linux_dirent
__user
*
dirent
;
compat_ulong_t
d_ino
;
if
(
buf
->
result
)
return
-
EINVAL
;
d_ino
=
ino
;
if
(
sizeof
(
d_ino
)
<
sizeof
(
ino
)
&&
d_ino
!=
ino
)
{
buf
->
result
=
-
EOVERFLOW
;
return
-
EOVERFLOW
;
}
buf
->
result
++
;
dirent
=
buf
->
dirent
;
if
(
!
access_ok
(
VERIFY_WRITE
,
dirent
,
(
unsigned
long
)(
dirent
->
d_name
+
namlen
+
1
)
-
(
unsigned
long
)
dirent
))
goto
efault
;
if
(
__put_user
(
d_ino
,
&
dirent
->
d_ino
)
||
__put_user
(
offset
,
&
dirent
->
d_offset
)
||
__put_user
(
namlen
,
&
dirent
->
d_namlen
)
||
__copy_to_user
(
dirent
->
d_name
,
name
,
namlen
)
||
__put_user
(
0
,
dirent
->
d_name
+
namlen
))
goto
efault
;
return
0
;
efault:
buf
->
result
=
-
EFAULT
;
return
-
EFAULT
;
}
COMPAT_SYSCALL_DEFINE3
(
old_readdir
,
unsigned
int
,
fd
,
struct
compat_old_linux_dirent
__user
*
,
dirent
,
unsigned
int
,
count
)
{
int
error
;
struct
fd
f
=
fdget_pos
(
fd
);
struct
compat_readdir_callback
buf
=
{
.
ctx
.
actor
=
compat_fillonedir
,
.
dirent
=
dirent
};
if
(
!
f
.
file
)
return
-
EBADF
;
error
=
iterate_dir
(
f
.
file
,
&
buf
.
ctx
);
if
(
buf
.
result
)
error
=
buf
.
result
;
fdput_pos
(
f
);
return
error
;
}
struct
compat_linux_dirent
{
compat_ulong_t
d_ino
;
compat_ulong_t
d_off
;
unsigned
short
d_reclen
;
char
d_name
[
1
];
};
struct
compat_getdents_callback
{
struct
dir_context
ctx
;
struct
compat_linux_dirent
__user
*
current_dir
;
struct
compat_linux_dirent
__user
*
previous
;
int
count
;
int
error
;
};
static
int
compat_filldir
(
struct
dir_context
*
ctx
,
const
char
*
name
,
int
namlen
,
loff_t
offset
,
u64
ino
,
unsigned
int
d_type
)
{
struct
compat_linux_dirent
__user
*
dirent
;
struct
compat_getdents_callback
*
buf
=
container_of
(
ctx
,
struct
compat_getdents_callback
,
ctx
);
compat_ulong_t
d_ino
;
int
reclen
=
ALIGN
(
offsetof
(
struct
compat_linux_dirent
,
d_name
)
+
namlen
+
2
,
sizeof
(
compat_long_t
));
buf
->
error
=
-
EINVAL
;
/* only used if we fail.. */
if
(
reclen
>
buf
->
count
)
return
-
EINVAL
;
d_ino
=
ino
;
if
(
sizeof
(
d_ino
)
<
sizeof
(
ino
)
&&
d_ino
!=
ino
)
{
buf
->
error
=
-
EOVERFLOW
;
return
-
EOVERFLOW
;
}
dirent
=
buf
->
previous
;
if
(
dirent
)
{
if
(
signal_pending
(
current
))
return
-
EINTR
;
if
(
__put_user
(
offset
,
&
dirent
->
d_off
))
goto
efault
;
}
dirent
=
buf
->
current_dir
;
if
(
__put_user
(
d_ino
,
&
dirent
->
d_ino
))
goto
efault
;
if
(
__put_user
(
reclen
,
&
dirent
->
d_reclen
))
goto
efault
;
if
(
copy_to_user
(
dirent
->
d_name
,
name
,
namlen
))
goto
efault
;
if
(
__put_user
(
0
,
dirent
->
d_name
+
namlen
))
goto
efault
;
if
(
__put_user
(
d_type
,
(
char
__user
*
)
dirent
+
reclen
-
1
))
goto
efault
;
buf
->
previous
=
dirent
;
dirent
=
(
void
__user
*
)
dirent
+
reclen
;
buf
->
current_dir
=
dirent
;
buf
->
count
-=
reclen
;
return
0
;
efault:
buf
->
error
=
-
EFAULT
;
return
-
EFAULT
;
}
COMPAT_SYSCALL_DEFINE3
(
getdents
,
unsigned
int
,
fd
,
struct
compat_linux_dirent
__user
*
,
dirent
,
unsigned
int
,
count
)
{
struct
fd
f
;
struct
compat_linux_dirent
__user
*
lastdirent
;
struct
compat_getdents_callback
buf
=
{
.
ctx
.
actor
=
compat_filldir
,
.
current_dir
=
dirent
,
.
count
=
count
};
int
error
;
if
(
!
access_ok
(
VERIFY_WRITE
,
dirent
,
count
))
return
-
EFAULT
;
f
=
fdget_pos
(
fd
);
if
(
!
f
.
file
)
return
-
EBADF
;
error
=
iterate_dir
(
f
.
file
,
&
buf
.
ctx
);
if
(
error
>=
0
)
error
=
buf
.
error
;
lastdirent
=
buf
.
previous
;
if
(
lastdirent
)
{
if
(
put_user
(
buf
.
ctx
.
pos
,
&
lastdirent
->
d_off
))
error
=
-
EFAULT
;
else
error
=
count
-
buf
.
count
;
}
fdput_pos
(
f
);
return
error
;
}
/*
* Exactly like fs/open.c:sys_open(), except that it doesn't set the
* O_LARGEFILE flag.
...
...
fs/readdir.c
View file @
0460b2a2
...
...
@@ -18,6 +18,7 @@
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/unistd.h>
#include <linux/compat.h>
#include <linux/uaccess.h>
...
...
@@ -324,3 +325,167 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
fdput_pos
(
f
);
return
error
;
}
#ifdef CONFIG_COMPAT
struct
compat_old_linux_dirent
{
compat_ulong_t
d_ino
;
compat_ulong_t
d_offset
;
unsigned
short
d_namlen
;
char
d_name
[
1
];
};
struct
compat_readdir_callback
{
struct
dir_context
ctx
;
struct
compat_old_linux_dirent
__user
*
dirent
;
int
result
;
};
static
int
compat_fillonedir
(
struct
dir_context
*
ctx
,
const
char
*
name
,
int
namlen
,
loff_t
offset
,
u64
ino
,
unsigned
int
d_type
)
{
struct
compat_readdir_callback
*
buf
=
container_of
(
ctx
,
struct
compat_readdir_callback
,
ctx
);
struct
compat_old_linux_dirent
__user
*
dirent
;
compat_ulong_t
d_ino
;
if
(
buf
->
result
)
return
-
EINVAL
;
d_ino
=
ino
;
if
(
sizeof
(
d_ino
)
<
sizeof
(
ino
)
&&
d_ino
!=
ino
)
{
buf
->
result
=
-
EOVERFLOW
;
return
-
EOVERFLOW
;
}
buf
->
result
++
;
dirent
=
buf
->
dirent
;
if
(
!
access_ok
(
VERIFY_WRITE
,
dirent
,
(
unsigned
long
)(
dirent
->
d_name
+
namlen
+
1
)
-
(
unsigned
long
)
dirent
))
goto
efault
;
if
(
__put_user
(
d_ino
,
&
dirent
->
d_ino
)
||
__put_user
(
offset
,
&
dirent
->
d_offset
)
||
__put_user
(
namlen
,
&
dirent
->
d_namlen
)
||
__copy_to_user
(
dirent
->
d_name
,
name
,
namlen
)
||
__put_user
(
0
,
dirent
->
d_name
+
namlen
))
goto
efault
;
return
0
;
efault:
buf
->
result
=
-
EFAULT
;
return
-
EFAULT
;
}
COMPAT_SYSCALL_DEFINE3
(
old_readdir
,
unsigned
int
,
fd
,
struct
compat_old_linux_dirent
__user
*
,
dirent
,
unsigned
int
,
count
)
{
int
error
;
struct
fd
f
=
fdget_pos
(
fd
);
struct
compat_readdir_callback
buf
=
{
.
ctx
.
actor
=
compat_fillonedir
,
.
dirent
=
dirent
};
if
(
!
f
.
file
)
return
-
EBADF
;
error
=
iterate_dir
(
f
.
file
,
&
buf
.
ctx
);
if
(
buf
.
result
)
error
=
buf
.
result
;
fdput_pos
(
f
);
return
error
;
}
struct
compat_linux_dirent
{
compat_ulong_t
d_ino
;
compat_ulong_t
d_off
;
unsigned
short
d_reclen
;
char
d_name
[
1
];
};
struct
compat_getdents_callback
{
struct
dir_context
ctx
;
struct
compat_linux_dirent
__user
*
current_dir
;
struct
compat_linux_dirent
__user
*
previous
;
int
count
;
int
error
;
};
static
int
compat_filldir
(
struct
dir_context
*
ctx
,
const
char
*
name
,
int
namlen
,
loff_t
offset
,
u64
ino
,
unsigned
int
d_type
)
{
struct
compat_linux_dirent
__user
*
dirent
;
struct
compat_getdents_callback
*
buf
=
container_of
(
ctx
,
struct
compat_getdents_callback
,
ctx
);
compat_ulong_t
d_ino
;
int
reclen
=
ALIGN
(
offsetof
(
struct
compat_linux_dirent
,
d_name
)
+
namlen
+
2
,
sizeof
(
compat_long_t
));
buf
->
error
=
-
EINVAL
;
/* only used if we fail.. */
if
(
reclen
>
buf
->
count
)
return
-
EINVAL
;
d_ino
=
ino
;
if
(
sizeof
(
d_ino
)
<
sizeof
(
ino
)
&&
d_ino
!=
ino
)
{
buf
->
error
=
-
EOVERFLOW
;
return
-
EOVERFLOW
;
}
dirent
=
buf
->
previous
;
if
(
dirent
)
{
if
(
signal_pending
(
current
))
return
-
EINTR
;
if
(
__put_user
(
offset
,
&
dirent
->
d_off
))
goto
efault
;
}
dirent
=
buf
->
current_dir
;
if
(
__put_user
(
d_ino
,
&
dirent
->
d_ino
))
goto
efault
;
if
(
__put_user
(
reclen
,
&
dirent
->
d_reclen
))
goto
efault
;
if
(
copy_to_user
(
dirent
->
d_name
,
name
,
namlen
))
goto
efault
;
if
(
__put_user
(
0
,
dirent
->
d_name
+
namlen
))
goto
efault
;
if
(
__put_user
(
d_type
,
(
char
__user
*
)
dirent
+
reclen
-
1
))
goto
efault
;
buf
->
previous
=
dirent
;
dirent
=
(
void
__user
*
)
dirent
+
reclen
;
buf
->
current_dir
=
dirent
;
buf
->
count
-=
reclen
;
return
0
;
efault:
buf
->
error
=
-
EFAULT
;
return
-
EFAULT
;
}
COMPAT_SYSCALL_DEFINE3
(
getdents
,
unsigned
int
,
fd
,
struct
compat_linux_dirent
__user
*
,
dirent
,
unsigned
int
,
count
)
{
struct
fd
f
;
struct
compat_linux_dirent
__user
*
lastdirent
;
struct
compat_getdents_callback
buf
=
{
.
ctx
.
actor
=
compat_filldir
,
.
current_dir
=
dirent
,
.
count
=
count
};
int
error
;
if
(
!
access_ok
(
VERIFY_WRITE
,
dirent
,
count
))
return
-
EFAULT
;
f
=
fdget_pos
(
fd
);
if
(
!
f
.
file
)
return
-
EBADF
;
error
=
iterate_dir
(
f
.
file
,
&
buf
.
ctx
);
if
(
error
>=
0
)
error
=
buf
.
error
;
lastdirent
=
buf
.
previous
;
if
(
lastdirent
)
{
if
(
put_user
(
buf
.
ctx
.
pos
,
&
lastdirent
->
d_off
))
error
=
-
EFAULT
;
else
error
=
count
-
buf
.
count
;
}
fdput_pos
(
f
);
return
error
;
}
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment