NFSD: Don't hold unrefcounted creds over call to nfsd_setuser()
Subsystems (2)
PATCH 1/1 NFSD: Don't hold unrefcounted creds over call to nfsd_setuser()
nfsd_open() gets an unrefcounted pointer to the current process's effective credentials at the top of the function, then calls nfsd_setuser() via fh_verify() - which may replace and destroy the current process's effective credentials - and then passes the unrefcounted pointer to dentry_open() - but the credentials may have been destroyed by this point.
Instead, the value from current_cred() should be passed directly to dentry_open() as one of its arguments, rather than being cached in a variable.
Possibly fh_verify() should return the creds to use.
---
fs/nfsd/vfs.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
fs/nfsd/vfs.c +1 -2
@@ -678,7 +678,6 @@ __be32 nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access, struct file **filp) { - const struct cred *cred = current_cred(); struct dentry *dentry;struct inode *inode;int flags =O_RDONLY |O_LARGEFILE ;
@@ -733,7 +732,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,vfs_dq_init (inode); } *filp =dentry_open (dget (dentry),mntget (fhp->fh_export->ex_path.mnt), - flags, cred); + flags,current_cred ());if (IS_ERR (*filp)) host_err =PTR_ERR (*filp);else
Quoted 6 lines · David Howells
nfsd_open()gets an unrefcounted pointer to the current process's effective credentials at the top of the function, then callsnfsd_setuser()viafh_verify()- which may replace and destroy the current process's effective credentials - and then passes the unrefcounted pointer todentry_open()- but the credentials may have been destroyed by this point.
Quoted 6 lines
Instead, the value from
current_cred()should be passed directly todentry_open()as one of its arguments, rather than being cached in a variable.Possibly
fh_verify()should return the creds to use.Signed-off-by David Howells <[email protected]>
Quoted 8 lines · David Howells
nfsd_open()gets an unrefcounted pointer to the current process's effective credentials at the top of the function, then callsnfsd_setuser()viafh_verify()- which may replace and destroy the current process's effective credentials - and then passes the unrefcounted pointer todentry_open()- but the credentials may have been destroyed by this point.Instead, the value from
current_cred()should be passed directly todentry_open()as one of its arguments, rather than being cached in a variable.
Got it, thanks. How easy is it to hit this case? (Just wondering whether to submit for stable.)
--b.
Quoted 32 lines
Possibly
fh_verify()should return the creds to use.Signed-off-by David Howells <[email protected]>---
fs/nfsd/vfs.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)fs/nfsd/vfs.c +1
-2@@ -678,7 +678,6 @@ __be32 nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access, struct file **filp) { - const struct cred *cred = current_cred(); struct dentry *dentry;struct inode *inode;int flags =O_RDONLY |O_LARGEFILE ;@@ -733,7 +732,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,vfs_dq_init (inode); } *filp =dentry_open (dget (dentry),mntget (fhp->fh_export->ex_path.mnt), - flags, cred); + flags,current_cred ());if (IS_ERR (*filp)) host_err =PTR_ERR (*filp);else
Quoted 2 lines · J. Bruce Fields
Got it, thanks. How easy is it to hit this case? (Just wondering whether to submit for stable.)
Actually, one of the problems with it is that the file is opened using the old creds, cached across the call to nfsd_setuser().
David
Quoted 7 lines · David Howells
Quoted 2 lines · J. Bruce Fields
Got it, thanks. How easy is it to hit this case? (Just wondering whether to submit for stable.)
Actually, one of the problems with it is that the file is opened using the old creds, cached across the call to
nfsd_setuser().
Oops, got it. That answers that question....
--b.
Quoted 10 lines · bfields
Quoted 7 lines · David Howells
Quoted 2 lines · J. Bruce Fields
Got it, thanks. How easy is it to hit this case? (Just wondering whether to submit for stable.)
Actually, one of the problems with it is that the file is opened using the old creds, cached across the call to
nfsd_setuser().Oops, got it. That answers that question....
Also: the problem was introduced by 745ca2475a6ac596e3d8d37c2759c0fbe2586227, right? Or does it not actually manifest till a little later?
--b.
Quoted 2 lines · J. Bruce Fields
Also: the problem was introduced by
745ca2475a6ac596e3d8d37c2759c0fbe2586227, right?
Yes.
David
The following patch is appropriate for 2.6.31 (and stable), and is also available from
git://linux-nfs.org/~bfields/linux.git for-2.6.31
--b.
commit 033a666ccb842ab4134fcd0c861d5ba9f5d6bf3a
Author: David Howells <[email protected]> Date: Thu Jul 2 14:35:32 2009 +0100
NFSD: Don't hold unrefcounted creds over call to nfsd_setuser()
nfsd_open() gets an unrefcounted pointer to the current process's effective credentials at the top of the function, then calls nfsd_setuser() via fh_verify() - which may replace and destroy the current process's effective credentials - and then passes the unrefcounted pointer to dentry_open() - but the credentials may have been destroyed by this point.
Instead, the value from current_cred() should be passed directly to dentry_open() as one of its arguments, rather than being cached in a variable.
Possibly fh_verify() should return the creds to use.
This is a regression introduced by 745ca2475a6ac596e3d8d37c2759c0fbe2586227 "CRED: Pass credentials through dentry_open()".
fs/nfsd/vfs.c +1 -2
@@ -678,7 +678,6 @@ __be32 nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access, struct file **filp) { - const struct cred *cred = current_cred(); struct dentry *dentry;struct inode *inode;int flags =O_RDONLY |O_LARGEFILE ;
@@ -733,7 +732,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,vfs_dq_init (inode); } *filp =dentry_open (dget (dentry),mntget (fhp->fh_export->ex_path.mnt), - flags, cred); + flags,current_cred ());if (IS_ERR (*filp)) host_err =PTR_ERR (*filp);else