Check for NULL fid pointers in p9_client_clunk()
Subsystems (2)
PATCH 1/1 Check for NULL fid pointers in p9_client_clunk()
NULL fid should be handled in cases where we endup calling v9fs_dir_release() before even we instantiate the fid in filp. This patch handles pasing a NULL p9_fid* to p9_client_clunk.
--- fs/9p/vfs_dir.c | 3 ++- net/9p/client.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletions(-)
fs/9p/vfs_dir.c +2 -1
@@ -292,7 +292,8 @@ int v9fs_dir_release(struct inode *inode, struct file *filp) fid = filp->private_data;P9_DPRINTK (P9_DEBUG_VFS , -"inode: %p filp: %p fid: %d\n" , inode, filp, fid->fid); +"JV: inode: %p filp: %p fid: %d\n" , inode, filp, + fid ? fid->fid :-1 );filemap_write_and_wait (inode->i_mapping);p9_client_clunk (fid);return 0 ;
net/9p/client.c +3 -0
@@ -1201,6 +1201,9 @@ int p9_client_clunk(struct p9_fid *fid)struct p9_client *clnt;struct p9_req_t *req; +if (!fid) +return 0 ; +P9_DPRINTK (P9_DEBUG_9P ,">>> TCLUNK fid %d\n" , fid->fid); err =0 ; clnt = fid->clnt;
Signature · 1 line
1.6.5.2
Quoted 15 lines · Venkateswararao Jujjuri (JV)
NULL fid should be handled in cases where we endup calling
v9fs_dir_release()before even we instantiate the fid in filp. This patch handles pasing a NULL p9_fid* top9_client_clunk.Signed-off-by Venkateswararao Jujjuri <[email protected]>---
fs/9p/vfs_dir.c | 3 ++-
net/9p/client.c | 3 +++2 files changed, 5 insertions(+), 1 deletions(-)fs/9p/vfs_dir.c +0
-0
fs/9p/vfs_dir.c int v9fs_dir_release(struct inode *inode, struct file *filp) · line 296
Quoted 6 lines
fs/9p/vfs_dir.c +2
-1@@ -292,7 +292,8 @@ int v9fs_dir_release(struct inode *inode, struct file *filp) fid = filp->private_data; P9_DPRINTK(P9_DEBUG_VFS, - "inode: %p filp: %p fid: %d\n", inode, filp, fid->fid); + "JV: inode: %p filp: %p fid: %d\n", inode, filp, + fid ? fid->fid : -1);
Did you really mean to insert a JV: debug label in there?
Quoted 8 lines
fs/9p/vfs_dir.c +0
-0filemap_write_and_wait(inode->i_mapping); p9_client_clunk(fid); return 0;net/9p/client.c +0
-0
net/9p/client.c int p9_client_clunk(struct p9_fid *fid) · line 1207
Quoted 7 lines
net/9p/client.c +3
-0@@ -1201,6 +1201,9 @@ int p9_client_clunk(struct p9_fid *fid) struct p9_client *clnt; struct p9_req_t *req; + if (!fid) + return 0; +
While this will solve the NULL pointer dereference, it will do so silently which may lead to us leaking fids/memory/resources/etc. If we were to do such a thing, I'd want warning messages. However, I wouldn't want warning messages in the generic, because now we have places we are calling p9_client_clunk from where we expect null fids to be valid.
I'd suggest keeping the fid check in v9fs_dir_release to parameterize sending the clunk since we expect to sometimes not have a fid here, and then in a separate patch adding some code to p9_client_clunk which complains loudly any time it gets called with a NULL fid. Its unclear to me whether this should be a BUG() or just a warning, a warning would probably suffice as it'll help us track down such cases during testing without breaking users.
-eric
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 18 lines · Eric Van Hensbergen
Quoted 16 lines · Venkateswararao Jujjuri (JV)
NULL fid should be handled in cases where we endup calling
v9fs_dir_release()before even we instantiate the fid in filp. This patch handles pasing a NULL p9_fid* top9_client_clunk.Signed-off-by Venkateswararao Jujjuri <[email protected]>--- fs/9p/vfs_dir.c | 3 ++- net/9p/client.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletions(-)fs/9p/vfs_dir.c +0
-0@@ -292,7 +292,8 @@ int v9fs_dir_release(struct inode *inode, struct file *filp)
Quoted 7 lines
fs/9p/vfs_dir.c int v9fs_dir_release(struct inode *inode, struct file *filp) · line 296
Quoted 5 lines
fs/9p/vfs_dir.c +2
-1fid = filp->private_data;P9_DPRINTK (P9_DEBUG_VFS , -"inode: %p filp: %p fid: %d\n" , inode, filp, fid->fid); +"JV: inode: %p filp: %p fid: %d\n" , inode, filp, + fid ? fid->fid :-1 );Did you really mean to insert a JV: debug label in there?
Oops!!
Quoted 24 lines
Quoted 9 lines
fs/9p/vfs_dir.c +0
-0filemap_write_and_wait (inode->i_mapping);p9_client_clunk (fid);return 0 ;net/9p/client.c +0
-0net/9p/client.c int p9_client_clunk(struct p9_fid *fid) · line 1207
Quoted 7 lines
net/9p/client.c +3
-0@@ -1201,6 +1201,9 @@ int p9_client_clunk(struct p9_fid *fid)struct p9_client *clnt;struct p9_req_t *req; +if (!fid) +return 0 ; +While this will solve the NULL pointer dereference, it will do so silently which may lead to us leaking fids/memory/resources/etc. If we were to do such a thing, I'd want warning messages. However, I wouldn't want warning messages in the generic, because now we have places we are calling
p9_client_clunkfrom where we expect null fids to be valid.
Quoted 7 lines
I'd suggest keeping the fid check in
v9fs_dir_releaseto parameterize sending the clunk since we expect to sometimes not have a fid here, and then in a separate patch adding some code top9_client_clunkwhich complains loudly any time it gets called with a NULL fid. Its unclear to me whether this should be aBUG()or just a warning, a warning would probably suffice as it'll help us track down such cases during testing without breaking users.
So basically you need a conditional call to p9_client_clunk() .
v9fs_dir_release()
{
...
if (fid)
p9_client_clunk(); }
Do you recall any cases where we end up calling clunk w/o a valid fid? So .. may be we should go with BUG(!fid) in clunck code?
Thanks,
JV
Quoted 2 lines
-eric