Skip to content

Commit 6624664

Browse files
jongwumartinetd
authored andcommitted
9p: retrieve fid from file when file instance exist.
In the current setattr implementation in 9p, fid is always retrieved from dentry no matter file instance exists or not. If so, there may be some info related to opened file instance dropped. So it's better to retrieve fid from file instance when it is passed to setattr. for example: fd=open("tmp", O_RDWR); ftruncate(fd, 10); The file context related with the fd will be lost as fid is always retrieved from dentry, then the backend can't get the info of file context. It is against the original intention of user and may lead to bug. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Jianyong Wu <[email protected]> Signed-off-by: Dominique Martinet <[email protected]>
1 parent 74d6a5d commit 6624664

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

fs/9p/vfs_inode.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
10901090
{
10911091
int retval;
10921092
struct v9fs_session_info *v9ses;
1093-
struct p9_fid *fid;
1093+
struct p9_fid *fid = NULL;
10941094
struct p9_wstat wstat;
10951095

10961096
p9_debug(P9_DEBUG_VFS, "\n");
@@ -1100,7 +1100,12 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
11001100

11011101
retval = -EPERM;
11021102
v9ses = v9fs_dentry2v9ses(dentry);
1103-
fid = v9fs_fid_lookup(dentry);
1103+
if (iattr->ia_valid & ATTR_FILE) {
1104+
fid = iattr->ia_file->private_data;
1105+
WARN_ON(!fid);
1106+
}
1107+
if (!fid)
1108+
fid = v9fs_fid_lookup(dentry);
11041109
if(IS_ERR(fid))
11051110
return PTR_ERR(fid);
11061111

fs/9p/vfs_inode_dotl.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static int v9fs_mapped_iattr_valid(int iattr_valid)
540540
int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
541541
{
542542
int retval;
543-
struct p9_fid *fid;
543+
struct p9_fid *fid = NULL;
544544
struct p9_iattr_dotl p9attr;
545545
struct inode *inode = d_inode(dentry);
546546

@@ -560,7 +560,12 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
560560
p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
561561
p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
562562

563-
fid = v9fs_fid_lookup(dentry);
563+
if (iattr->ia_valid & ATTR_FILE) {
564+
fid = iattr->ia_file->private_data;
565+
WARN_ON(!fid);
566+
}
567+
if (!fid)
568+
fid = v9fs_fid_lookup(dentry);
564569
if (IS_ERR(fid))
565570
return PTR_ERR(fid);
566571

0 commit comments

Comments
 (0)