Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
linux
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martyn Welch
linux
Commits
f9652e10
Commit
f9652e10
authored
12 years ago
by
Al Viro
Browse files
Options
Downloads
Patches
Plain Diff
allow build_open_flags() to return an error
Signed-off-by:
Al Viro
<
viro@zeniv.linux.org.uk
>
parent
50cd2c57
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
fs/exec.c
+6
-4
6 additions, 4 deletions
fs/exec.c
fs/internal.h
+3
-2
3 additions, 2 deletions
fs/internal.h
fs/namei.c
+4
-4
4 additions, 4 deletions
fs/namei.c
fs/open.c
+28
-21
28 additions, 21 deletions
fs/open.c
with
41 additions
and
31 deletions
fs/exec.c
+
6
−
4
View file @
f9652e10
...
@@ -110,13 +110,14 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
...
@@ -110,13 +110,14 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
static
const
struct
open_flags
uselib_flags
=
{
static
const
struct
open_flags
uselib_flags
=
{
.
open_flag
=
O_LARGEFILE
|
O_RDONLY
|
__FMODE_EXEC
,
.
open_flag
=
O_LARGEFILE
|
O_RDONLY
|
__FMODE_EXEC
,
.
acc_mode
=
MAY_READ
|
MAY_EXEC
|
MAY_OPEN
,
.
acc_mode
=
MAY_READ
|
MAY_EXEC
|
MAY_OPEN
,
.
intent
=
LOOKUP_OPEN
.
intent
=
LOOKUP_OPEN
,
.
lookup_flags
=
LOOKUP_FOLLOW
,
};
};
if
(
IS_ERR
(
tmp
))
if
(
IS_ERR
(
tmp
))
goto
out
;
goto
out
;
file
=
do_filp_open
(
AT_FDCWD
,
tmp
,
&
uselib_flags
,
LOOKUP_FOLLOW
);
file
=
do_filp_open
(
AT_FDCWD
,
tmp
,
&
uselib_flags
);
putname
(
tmp
);
putname
(
tmp
);
error
=
PTR_ERR
(
file
);
error
=
PTR_ERR
(
file
);
if
(
IS_ERR
(
file
))
if
(
IS_ERR
(
file
))
...
@@ -756,10 +757,11 @@ struct file *open_exec(const char *name)
...
@@ -756,10 +757,11 @@ struct file *open_exec(const char *name)
static
const
struct
open_flags
open_exec_flags
=
{
static
const
struct
open_flags
open_exec_flags
=
{
.
open_flag
=
O_LARGEFILE
|
O_RDONLY
|
__FMODE_EXEC
,
.
open_flag
=
O_LARGEFILE
|
O_RDONLY
|
__FMODE_EXEC
,
.
acc_mode
=
MAY_EXEC
|
MAY_OPEN
,
.
acc_mode
=
MAY_EXEC
|
MAY_OPEN
,
.
intent
=
LOOKUP_OPEN
.
intent
=
LOOKUP_OPEN
,
.
lookup_flags
=
LOOKUP_FOLLOW
,
};
};
file
=
do_filp_open
(
AT_FDCWD
,
&
tmp
,
&
open_exec_flags
,
LOOKUP_FOLLOW
);
file
=
do_filp_open
(
AT_FDCWD
,
&
tmp
,
&
open_exec_flags
);
if
(
IS_ERR
(
file
))
if
(
IS_ERR
(
file
))
goto
out
;
goto
out
;
...
...
This diff is collapsed.
Click to expand it.
fs/internal.h
+
3
−
2
View file @
f9652e10
...
@@ -96,11 +96,12 @@ struct open_flags {
...
@@ -96,11 +96,12 @@ struct open_flags {
umode_t
mode
;
umode_t
mode
;
int
acc_mode
;
int
acc_mode
;
int
intent
;
int
intent
;
int
lookup_flags
;
};
};
extern
struct
file
*
do_filp_open
(
int
dfd
,
struct
filename
*
pathname
,
extern
struct
file
*
do_filp_open
(
int
dfd
,
struct
filename
*
pathname
,
const
struct
open_flags
*
op
,
int
flags
);
const
struct
open_flags
*
op
);
extern
struct
file
*
do_file_open_root
(
struct
dentry
*
,
struct
vfsmount
*
,
extern
struct
file
*
do_file_open_root
(
struct
dentry
*
,
struct
vfsmount
*
,
const
char
*
,
const
struct
open_flags
*
,
int
lookup_flags
);
const
char
*
,
const
struct
open_flags
*
);
extern
long
do_handle_open
(
int
mountdirfd
,
extern
long
do_handle_open
(
int
mountdirfd
,
struct
file_handle
__user
*
ufh
,
int
open_flag
);
struct
file_handle
__user
*
ufh
,
int
open_flag
);
...
...
This diff is collapsed.
Click to expand it.
fs/namei.c
+
4
−
4
View file @
f9652e10
...
@@ -2969,9 +2969,10 @@ static struct file *path_openat(int dfd, struct filename *pathname,
...
@@ -2969,9 +2969,10 @@ static struct file *path_openat(int dfd, struct filename *pathname,
}
}
struct
file
*
do_filp_open
(
int
dfd
,
struct
filename
*
pathname
,
struct
file
*
do_filp_open
(
int
dfd
,
struct
filename
*
pathname
,
const
struct
open_flags
*
op
,
int
flags
)
const
struct
open_flags
*
op
)
{
{
struct
nameidata
nd
;
struct
nameidata
nd
;
int
flags
=
op
->
lookup_flags
;
struct
file
*
filp
;
struct
file
*
filp
;
filp
=
path_openat
(
dfd
,
pathname
,
&
nd
,
op
,
flags
|
LOOKUP_RCU
);
filp
=
path_openat
(
dfd
,
pathname
,
&
nd
,
op
,
flags
|
LOOKUP_RCU
);
...
@@ -2983,17 +2984,16 @@ struct file *do_filp_open(int dfd, struct filename *pathname,
...
@@ -2983,17 +2984,16 @@ struct file *do_filp_open(int dfd, struct filename *pathname,
}
}
struct
file
*
do_file_open_root
(
struct
dentry
*
dentry
,
struct
vfsmount
*
mnt
,
struct
file
*
do_file_open_root
(
struct
dentry
*
dentry
,
struct
vfsmount
*
mnt
,
const
char
*
name
,
const
struct
open_flags
*
op
,
int
flags
)
const
char
*
name
,
const
struct
open_flags
*
op
)
{
{
struct
nameidata
nd
;
struct
nameidata
nd
;
struct
file
*
file
;
struct
file
*
file
;
struct
filename
filename
=
{
.
name
=
name
};
struct
filename
filename
=
{
.
name
=
name
};
int
flags
=
op
->
lookup_flags
|
LOOKUP_ROOT
;
nd
.
root
.
mnt
=
mnt
;
nd
.
root
.
mnt
=
mnt
;
nd
.
root
.
dentry
=
dentry
;
nd
.
root
.
dentry
=
dentry
;
flags
|=
LOOKUP_ROOT
;
if
(
dentry
->
d_inode
->
i_op
->
follow_link
&&
op
->
intent
&
LOOKUP_OPEN
)
if
(
dentry
->
d_inode
->
i_op
->
follow_link
&&
op
->
intent
&
LOOKUP_OPEN
)
return
ERR_PTR
(
-
ELOOP
);
return
ERR_PTR
(
-
ELOOP
);
...
...
This diff is collapsed.
Click to expand it.
fs/open.c
+
28
−
21
View file @
f9652e10
...
@@ -876,7 +876,8 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o
...
@@ -876,7 +876,8 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o
lookup_flags
|=
LOOKUP_DIRECTORY
;
lookup_flags
|=
LOOKUP_DIRECTORY
;
if
(
!
(
flags
&
O_NOFOLLOW
))
if
(
!
(
flags
&
O_NOFOLLOW
))
lookup_flags
|=
LOOKUP_FOLLOW
;
lookup_flags
|=
LOOKUP_FOLLOW
;
return
lookup_flags
;
op
->
lookup_flags
=
lookup_flags
;
return
0
;
}
}
/**
/**
...
@@ -893,8 +894,8 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o
...
@@ -893,8 +894,8 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o
struct
file
*
file_open_name
(
struct
filename
*
name
,
int
flags
,
umode_t
mode
)
struct
file
*
file_open_name
(
struct
filename
*
name
,
int
flags
,
umode_t
mode
)
{
{
struct
open_flags
op
;
struct
open_flags
op
;
int
lookup
=
build_open_flags
(
flags
,
mode
,
&
op
);
int
err
=
build_open_flags
(
flags
,
mode
,
&
op
);
return
do_filp_open
(
AT_FDCWD
,
name
,
&
op
,
lookup
);
return
err
?
ERR_PTR
(
err
)
:
do_filp_open
(
AT_FDCWD
,
name
,
&
op
);
}
}
/**
/**
...
@@ -919,27 +920,34 @@ struct file *file_open_root(struct dentry *dentry, struct vfsmount *mnt,
...
@@ -919,27 +920,34 @@ struct file *file_open_root(struct dentry *dentry, struct vfsmount *mnt,
const
char
*
filename
,
int
flags
)
const
char
*
filename
,
int
flags
)
{
{
struct
open_flags
op
;
struct
open_flags
op
;
int
lookup
=
build_open_flags
(
flags
,
0
,
&
op
);
int
err
=
build_open_flags
(
flags
,
0
,
&
op
);
if
(
err
)
return
ERR_PTR
(
err
);
if
(
flags
&
O_CREAT
)
if
(
flags
&
O_CREAT
)
return
ERR_PTR
(
-
EINVAL
);
return
ERR_PTR
(
-
EINVAL
);
if
(
!
filename
&&
(
flags
&
O_DIRECTORY
))
if
(
!
filename
&&
(
flags
&
O_DIRECTORY
))
if
(
!
dentry
->
d_inode
->
i_op
->
lookup
)
if
(
!
dentry
->
d_inode
->
i_op
->
lookup
)
return
ERR_PTR
(
-
ENOTDIR
);
return
ERR_PTR
(
-
ENOTDIR
);
return
do_file_open_root
(
dentry
,
mnt
,
filename
,
&
op
,
lookup
);
return
do_file_open_root
(
dentry
,
mnt
,
filename
,
&
op
);
}
}
EXPORT_SYMBOL
(
file_open_root
);
EXPORT_SYMBOL
(
file_open_root
);
long
do_sys_open
(
int
dfd
,
const
char
__user
*
filename
,
int
flags
,
umode_t
mode
)
long
do_sys_open
(
int
dfd
,
const
char
__user
*
filename
,
int
flags
,
umode_t
mode
)
{
{
struct
open_flags
op
;
struct
open_flags
op
;
int
lookup
=
build_open_flags
(
flags
,
mode
,
&
op
);
int
fd
=
build_open_flags
(
flags
,
mode
,
&
op
);
struct
filename
*
tmp
=
getname
(
filename
);
struct
filename
*
tmp
;
int
fd
=
PTR_ERR
(
tmp
);
if
(
fd
)
return
fd
;
tmp
=
getname
(
filename
);
if
(
IS_ERR
(
tmp
))
return
PTR_ERR
(
tmp
);
if
(
!
IS_ERR
(
tmp
))
{
fd
=
get_unused_fd_flags
(
flags
);
fd
=
get_unused_fd_flags
(
flags
);
if
(
fd
>=
0
)
{
if
(
fd
>=
0
)
{
struct
file
*
f
=
do_filp_open
(
dfd
,
tmp
,
&
op
,
lookup
);
struct
file
*
f
=
do_filp_open
(
dfd
,
tmp
,
&
op
);
if
(
IS_ERR
(
f
))
{
if
(
IS_ERR
(
f
))
{
put_unused_fd
(
fd
);
put_unused_fd
(
fd
);
fd
=
PTR_ERR
(
f
);
fd
=
PTR_ERR
(
f
);
...
@@ -949,7 +957,6 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
...
@@ -949,7 +957,6 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
}
}
}
}
putname
(
tmp
);
putname
(
tmp
);
}
return
fd
;
return
fd
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment