NFS: Fix access to suid/sgid executables
nfs_open_permission_mask() should only check MAY_EXEC for files that are opened with __FMODE_EXEC. Also fix NFSv4 access-in-open path in a similar way -- openflags must be used because fmode will not always have FMODE_EXEC set. This patch fixes https://bugzilla.kernel.org/show_bug.cgi?id=49101 Signed-off-by: Weston Andros Adamson <dros@netapp.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com> Cc: stable@vger.kernel.org
This commit is contained in:
parent
d1c3ed669a
commit
f8d9a897d4
|
@ -2153,12 +2153,16 @@ static int nfs_open_permission_mask(int openflags)
|
||||||
{
|
{
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
|
|
||||||
|
if (openflags & __FMODE_EXEC) {
|
||||||
|
/* ONLY check exec rights */
|
||||||
|
mask = MAY_EXEC;
|
||||||
|
} else {
|
||||||
if ((openflags & O_ACCMODE) != O_WRONLY)
|
if ((openflags & O_ACCMODE) != O_WRONLY)
|
||||||
mask |= MAY_READ;
|
mask |= MAY_READ;
|
||||||
if ((openflags & O_ACCMODE) != O_RDONLY)
|
if ((openflags & O_ACCMODE) != O_RDONLY)
|
||||||
mask |= MAY_WRITE;
|
mask |= MAY_WRITE;
|
||||||
if (openflags & __FMODE_EXEC)
|
}
|
||||||
mask |= MAY_EXEC;
|
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1626,7 +1626,8 @@ static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
|
||||||
|
|
||||||
static int nfs4_opendata_access(struct rpc_cred *cred,
|
static int nfs4_opendata_access(struct rpc_cred *cred,
|
||||||
struct nfs4_opendata *opendata,
|
struct nfs4_opendata *opendata,
|
||||||
struct nfs4_state *state, fmode_t fmode)
|
struct nfs4_state *state, fmode_t fmode,
|
||||||
|
int openflags)
|
||||||
{
|
{
|
||||||
struct nfs_access_entry cache;
|
struct nfs_access_entry cache;
|
||||||
u32 mask;
|
u32 mask;
|
||||||
|
@ -1638,11 +1639,14 @@ static int nfs4_opendata_access(struct rpc_cred *cred,
|
||||||
|
|
||||||
mask = 0;
|
mask = 0;
|
||||||
/* don't check MAY_WRITE - a newly created file may not have
|
/* don't check MAY_WRITE - a newly created file may not have
|
||||||
* write mode bits, but POSIX allows the creating process to write */
|
* write mode bits, but POSIX allows the creating process to write.
|
||||||
if (fmode & FMODE_READ)
|
* use openflags to check for exec, because fmode won't
|
||||||
mask |= MAY_READ;
|
* always have FMODE_EXEC set when file open for exec. */
|
||||||
if (fmode & FMODE_EXEC)
|
if (openflags & __FMODE_EXEC) {
|
||||||
mask |= MAY_EXEC;
|
/* ONLY check for exec rights */
|
||||||
|
mask = MAY_EXEC;
|
||||||
|
} else if (fmode & FMODE_READ)
|
||||||
|
mask = MAY_READ;
|
||||||
|
|
||||||
cache.cred = cred;
|
cache.cred = cred;
|
||||||
cache.jiffies = jiffies;
|
cache.jiffies = jiffies;
|
||||||
|
@ -1896,7 +1900,7 @@ static int _nfs4_do_open(struct inode *dir,
|
||||||
if (server->caps & NFS_CAP_POSIX_LOCK)
|
if (server->caps & NFS_CAP_POSIX_LOCK)
|
||||||
set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
|
set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
|
||||||
|
|
||||||
status = nfs4_opendata_access(cred, opendata, state, fmode);
|
status = nfs4_opendata_access(cred, opendata, state, fmode, flags);
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
goto err_opendata_put;
|
goto err_opendata_put;
|
||||||
|
|
||||||
|
|
Reference in New Issue