9pfs fixes for 2.11 20170920
The following changes since commit c51700273ad9802a21c19f8d2b4bcb67c38e74ac:
Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20170919-v2' into staging (2017-09-19 18:08:48 +0100)
are available in the git repository at:
https://github.com/gkurz/qemu.git tags/for-upstream
for you to fetch changes up to 772a73692ecb52bace0cff6f95df62f59b8cabe0:
9pfs: check the size of transport buffer before marshaling (2017-09-20 08:48:52 +0200)
----------------------------------------------------------------
These patches fix regressions in 2.10
----------------------------------------------------------------
Jan Dakinevich (3):
9pfs: fix readdir() for 9p2000.u
9pfs: fix name_to_path assertion in v9fs_complete_rename() 9pfs: check the size of transport buffer before marshaling
hw/9pfs/9p.c | 60 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 30 deletions(-)
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 1/3] 9pfs: fix readdir() for 9p2000.u
From: Jan Dakinevich <[email protected]>
If the client is using 9p2000.u, the following occurs:
$ cd ${virtfs_shared_dir}
$ mkdir -p a/b/c
$ ls a/b
ls: cannot access 'a/b/a': No such file or directory
ls: cannot access 'a/b/b': No such file or directory
a b cinstead of the expected:
$ ls a/b c
This is a regression introduced by commit f57f5878578a; local_name_to_path() now resolves ".." and "." in paths, and v9fs_do_readdir_with_stat()->stat_to_v9stat() then copies the basename of the resulting path to the response. With the example above, this means that "." and ".." are turned into "b" and "a" respectively...
stat_to_v9stat() currently assumes it is passed a full canonicalized path and uses it to do two different things:
1) to pass it to v9fs_co_readlink() in case the file is a symbolic link
2) to set the name field of the V9fsStat structure to the basename part of the given path
It only has two users: v9fs_stat() and v9fs_do_readdir_with_stat().
v9fs_stat() really needs 1) and 2) to be performed since it starts with the full canonicalized path stored in the fid. It is different for v9fs_do_readdir_with_stat() though because the name we want to put into the V9fsStat structure is the d_name field of the dirent actually (ie, we want to keep the "." and ".." special names). So, we only need 1) in this case.
This patch hence adds a basename argument to stat_to_v9stat(), to be used to set the name field of the V9fsStat structure, and moves the basename logic to v9fs_stat().
(groug, renamed old name argument to path and updated changelog)
--- hw/9pfs/9p.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
hw/9pfs/9p.c +9 -13
@@ -803,12 +803,12 @@ static uint32_t stat_to_v9mode(const struct stat *stbuf)return mode; } -static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name, +static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *path, +const char *basename,const struct stat *stbuf,V9fsStat *v9stat) {int err; -const char *str;memset (v9stat,0 ,sizeof (*v9stat));
@@ -829,7 +829,7 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name,v9fs_string_free (&v9stat->extension);if (v9stat->mode &P9_STAT_MODE_SYMLINK ) { - err =v9fs_co_readlink (pdu, name, &v9stat->extension); + err =v9fs_co_readlink (pdu, path, &v9stat->extension);if (err <0 ) {return err; }
@@ -842,14 +842,7 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name, "HARDLINKCOUNT", (unsigned long)stbuf->st_nlink); } - str =strrchr (name->data,'/' ); -if (str) { - str +=1 ; - }else { - str = name->data; - } - -v9fs_string_sprintf (&v9stat->name,"%s" , str); +v9fs_string_sprintf (&v9stat->name,"%s" , basename); v9stat->size =61 + v9fs_string_size(&v9stat->name) +
@@ -1056,6 +1049,7 @@ static void coroutine_fn v9fs_stat(void *opaque)struct stat stbuf;V9fsFidState *fidp;V9fsPDU *pdu = opaque; +char *basename; err =pdu_unmarshal (pdu, offset,"d" , &fid);if (err <0 ) {
@@ -1072,7 +1066,9 @@ static void coroutine_fn v9fs_stat(void *opaque)if (err <0 ) { goto out; } - err =stat_to_v9stat (pdu, &fidp->path, &stbuf, &v9stat); + basename =g_path_get_basename (fidp->path.data); + err =stat_to_v9stat (pdu, &fidp->path, basename, &stbuf, &v9stat); +g_free (basename);if (err <0 ) { goto out; }
@@ -1748,7 +1744,7 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu,if (err <0 ) {break ; } - err =stat_to_v9stat (pdu, &path, &stbuf, &v9stat); + err =stat_to_v9stat (pdu, &path, dent->d_name, &stbuf, &v9stat);if (err <0 ) {break ; }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 2/3] 9pfs: fix name_to_path assertion in v9fs_complete_rename()
In reply to Greg KurzFrom: Jan Dakinevich <[email protected]>
The third parameter of v9fs_co_name_to_path() must not contain `/' character.
The issue is most likely related to 9p2000.u protocol only.
--- hw/9pfs/9p.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
hw/9pfs/9p.c +9 -14
@@ -2553,13 +2553,11 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp,int32_t newdirfid, V9fsString *name) { - char *end; int err = 0;V9fsPath new_path;V9fsFidState *tfidp;V9fsState *s = pdu->s;V9fsFidState *dirfidp =NULL ; -char *old_name, *new_name;v9fs_path_init (&new_path);if (newdirfid !=-1 ) {
@@ -2577,18 +2575,15 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp, goto out; } }else { - old_name = fidp->path.data; - end =strrchr (old_name,'/' ); -if (end) { - end++; - }else { - end = old_name; - } - new_name =g_malloc0 (end - old_name + name->size +1 ); -strncat (new_name, old_name, end - old_name); -strncat (new_name + (end - old_name), name->data, name->size); - err =v9fs_co_name_to_path (pdu,NULL , new_name, &new_path); -g_free (new_name); +char *dir_name =g_path_get_dirname (fidp->path.data); +V9fsPath dir_path; + +v9fs_path_init (&dir_path); +v9fs_path_sprintf (&dir_path,"%s" , dir_name); +g_free (dir_name); + + err =v9fs_co_name_to_path (pdu, &dir_path, name->data, &new_path); +v9fs_path_free (&dir_path);if (err <0 ) { goto out; }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 3/3] 9pfs: check the size of transport buffer before marshaling
In reply to Greg KurzFrom: Jan Dakinevich <[email protected]>
v9fs_do_readdir_with_stat() should check for a maximum buffer size before an attempt to marshal gathered data. Otherwise, buffers assumed as misconfigured and the transport would be broken.
The patch brings v9fs_do_readdir_with_stat() in conformity with v9fs_do_readdir() behavior.
--- hw/9pfs/9p.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
hw/9pfs/9p.c +12 -3
@@ -1748,17 +1748,26 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu,if (err <0 ) {break ; } +if ((count + v9stat.size +2 ) > max_count) { +v9fs_readdir_unlock (&fidp->fs.dir); + +/* Ran out of buffer. Set dir back to old position and return */ +v9fs_co_seekdir (pdu, fidp, saved_dir_pos); +v9fs_stat_free (&v9stat); +v9fs_path_free (&path); +return count; + } +/* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len =pdu_marshal (pdu,11 + count,"S" , &v9stat);v9fs_readdir_unlock (&fidp->fs.dir); -if ((len != (v9stat.size +2 )) || ((count + len) > max_count)) { -/* Ran out of buffer. Set dir back to old position and return */ +if (len <0 ) {v9fs_co_seekdir (pdu, fidp, saved_dir_pos);v9fs_stat_free (&v9stat);v9fs_path_free (&path); -return count; +return len; } count += len;v9fs_stat_free (&v9stat);
Signature · 1 line
2.13.5
Peter Maydell
AppliedQuoted 21 lines · Greg Kurz
The following changes since commit
c51700273ad9802a21c19f8d2b4bcb67c38e74ac:Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20170919-v2' into staging (2017-09-19 18:08:48 +0100)
are available in the git repository at:
https://github.com/gkurz/qemu.git tags/for-upstream
for you to fetch changes up to
772a73692ecb52bace0cff6f95df62f59b8cabe0:9pfs: check the size of transport buffer before marshaling (2017-09-20 08:48:52 +0200)
----------------------------------------------------------------
These patches fix regressions in 2.10----------------------------------------------------------------
Jan Dakinevich (3):
9pfs: fixreaddir()for 9p2000.u
9pfs: fixname_to_pathassertion inv9fs_complete_rename()9pfs: check the size of transport buffer before marshaling
Quoted 4 lines
hw/9pfs/9p.c | 60 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 30 deletions(-)--
2.13.5
Applied, thanks.
-- PMM