9pfs: fix offset error in v9fs_xattr_read()
PATCH 1/1 9pfs: fix offset error in v9fs_xattr_read()
The current code tries to copy read_count' bytes starting at offset offset' from a read_count-sized iovec. This causes v9fs_pack() to fail with ENOBUFS.
Since the PDU iovec is already partially filled with offset' bytes, let's skip them when creating qiov_full' and have v9fs_pack() to copy the whole of it. Moreover, this is consistent with the other places where v9fs_init_qiov_from_pdu() is called.
This fixes commit "bcb8998fac16 9pfs: call v9fs_init_qiov_from_pdu before v9fs_pack".
--- hw/9pfs/9p.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/9pfs/9p.c +2 -2
@@ -1685,8 +1685,8 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, } offset += err; -v9fs_init_qiov_from_pdu (&qiov_full, pdu,0 , read_count, false); - err =v9fs_pack (qiov_full.iov, qiov_full.niov, offset, +v9fs_init_qiov_from_pdu (&qiov_full, pdu, offset, read_count, false); + err =v9fs_pack (qiov_full.iov, qiov_full.niov,0 , ((char *)fidp->fs.xattr.value) + off, read_count);qemu_iovec_destroy (&qiov_full);
Quoted 11 lines · Greg Kurz
The current code tries to copy
read_count' bytes starting at offsetoffset' from aread_count-sized iovec. This causesv9fs_pack()to fail with ENOBUFS.Since the PDU iovec is already partially filled with
offset' bytes, let's skip them when creatingqiov_full' and havev9fs_pack()to copy the whole of it. Moreover, this is consistent with the other places wherev9fs_init_qiov_from_pdu()is called.This fixes commit "
bcb8998fac169pfs: callv9fs_init_qiov_from_pdubeforev9fs_pack".
Sorry about that!
Quoted 10 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/9p.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/9pfs/9p.c +0
-0
hw/9pfs/9p.c static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, · line 1688
Quoted 6 lines
hw/9pfs/9p.c +1
-2@@ -1685,8 +1685,8 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, } offset += err; -v9fs_init_qiov_from_pdu (&qiov_full, pdu,0 , read_count, false); - err = v9fs_pack(qiov_full.iov, qiov_full.niov, offset, +v9fs_init_qiov_from_pdu (&qiov_full, pdu, offset, read_count, false);
v9fs_init_qiov_from_pdu calls init_in_iov_from_pdu passing read_count as size argument. offset is not passed to init_in_iov_from_pdu, it is only used to initialized qiov_full.
In other words, don't we need to:
v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset, read_count + offset, false);
To make sure that qiov_full has "read_count + offset" bytes in it, and qiov_full is initialized skipping the first "offset" bytes?
Quoted 5 lines
hw/9pfs/9p.c +1
-0+ err =v9fs_pack (qiov_full.iov, qiov_full.niov,0 , ((char *)fidp->fs.xattr.value) + off, read_count);qemu_iovec_destroy (&qiov_full);
Quoted 37 lines · On Mon, 23 Jan 2017 12:20:57 -0800 (PST) Stefano Stabellini…
Quoted 11 lines · Greg Kurz
The current code tries to copy
read_count' bytes starting at offsetoffset' from aread_count-sized iovec. This causesv9fs_pack()to fail with ENOBUFS.Since the PDU iovec is already partially filled with
offset' bytes, let's skip them when creatingqiov_full' and havev9fs_pack()to copy the whole of it. Moreover, this is consistent with the other places wherev9fs_init_qiov_from_pdu()is called.This fixes commit "
bcb8998fac169pfs: callv9fs_init_qiov_from_pdubeforev9fs_pack".Sorry about that!
Quoted 10 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/9p.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/9pfs/9p.c +0
-0hw/9pfs/9p.c static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, · line 1688
Quoted 6 lines
hw/9pfs/9p.c +1
-2@@ -1685,8 +1685,8 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, } offset += err; -v9fs_init_qiov_from_pdu (&qiov_full, pdu,0 , read_count, false); - err = v9fs_pack(qiov_full.iov, qiov_full.niov, offset, +v9fs_init_qiov_from_pdu (&qiov_full, pdu, offset, read_count, false);
v9fs_init_qiov_from_pducallsinit_in_iov_from_pdupassingread_countas size argument. offset is not passed toinit_in_iov_from_pdu, it is only used to initializedqiov_full.
Quoted 7 lines
In other words, don't we need to:
v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset, read_count + offset, false);To make sure that
qiov_fullhas "read_count+ offset" bytes in it, andqiov_fullis initialized skipping the first "offset" bytes?
If we do that then qemu_iovec_concat() will skip offset bytes and then copy read_count + offset bytes or am I missing something ?
Quoted 6 lines
Quoted 6 lines
hw/9pfs/9p.c +1
-0+ err =v9fs_pack (qiov_full.iov, qiov_full.niov,0 , ((char *)fidp->fs.xattr.value) + off, read_count);qemu_iovec_destroy (&qiov_full);
Quoted 42 lines · Greg Kurz
Quoted 39 lines · On Mon, 23 Jan 2017 12:20:57 -0800 (PST) Stefano Stabellini…
Quoted 11 lines · Greg Kurz
The current code tries to copy
read_count' bytes starting at offsetoffset' from aread_count-sized iovec. This causesv9fs_pack()to fail with ENOBUFS.Since the PDU iovec is already partially filled with
offset' bytes, let's skip them when creatingqiov_full' and havev9fs_pack()to copy the whole of it. Moreover, this is consistent with the other places wherev9fs_init_qiov_from_pdu()is called.This fixes commit "
bcb8998fac169pfs: callv9fs_init_qiov_from_pdubeforev9fs_pack".Sorry about that!
Quoted 10 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/9p.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/9pfs/9p.c +0
-0hw/9pfs/9p.c static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, · line 1688
Quoted 6 lines
hw/9pfs/9p.c +1
-2@@ -1685,8 +1685,8 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, } offset += err; -v9fs_init_qiov_from_pdu (&qiov_full, pdu,0 , read_count, false); - err = v9fs_pack(qiov_full.iov, qiov_full.niov, offset, +v9fs_init_qiov_from_pdu (&qiov_full, pdu, offset, read_count, false);
v9fs_init_qiov_from_pducallsinit_in_iov_from_pdupassingread_countas size argument. offset is not passed toinit_in_iov_from_pdu, it is only used to initializedqiov_full.In other words, don't we need to:
Quoted 8 lines
Quoted 5 lines
v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset, read_count + offset, false);To make sure that
qiov_fullhas "read_count+ offset" bytes in it, andqiov_fullis initialized skipping the first "offset" bytes?If we do that then
qemu_iovec_concat()will skip offset bytes and then copyread_count+ offset bytes or am I missing something ?
You are right, sorry. qemu_iovec_concat didn't do what I thought it would. In that case, I think we need to change v9fs_init_qiov_from_pdu (in addition to the changes already in this patch):
@@ -1659,12 +1659,14 @@ static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu,
if (is_write) {
pdu->s->transport->init_out_iov_from_pdu(pdu, &iov, &niov);
} else {
- pdu->s->transport->init_in_iov_from_pdu(pdu, &iov, &niov, size);
+ pdu->s->transport->init_in_iov_from_pdu(pdu, &iov, &niov, size + skip);
}The reason is the same as before: iov needs to have offset+read_count bytes in it, for qemu_iovec_concat to skip offset and iov still have read_count bytes left.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
hw/9pfs/9p.c +1
-0+ err =v9fs_pack (qiov_full.iov, qiov_full.niov,0 , ((char *)fidp->fs.xattr.value) + off, read_count);qemu_iovec_destroy (&qiov_full);
Quoted 64 lines · On Tue, 24 Jan 2017 14:24:23 -0800 (PST) Stefano Stabellini…
Quoted 42 lines · Greg Kurz
Quoted 39 lines · On Mon, 23 Jan 2017 12:20:57 -0800 (PST) Stefano Stabellini…
Quoted 11 lines · Greg Kurz
The current code tries to copy
read_count' bytes starting at offsetoffset' from aread_count-sized iovec. This causesv9fs_pack()to fail with ENOBUFS.Since the PDU iovec is already partially filled with
offset' bytes, let's skip them when creatingqiov_full' and havev9fs_pack()to copy the whole of it. Moreover, this is consistent with the other places wherev9fs_init_qiov_from_pdu()is called.This fixes commit "
bcb8998fac169pfs: callv9fs_init_qiov_from_pdubeforev9fs_pack".Sorry about that!
Quoted 10 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/9p.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/9pfs/9p.c +0
-0hw/9pfs/9p.c static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, · line 1688
Quoted 6 lines
hw/9pfs/9p.c +1
-2@@ -1685,8 +1685,8 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, } offset += err; -v9fs_init_qiov_from_pdu (&qiov_full, pdu,0 , read_count, false); - err = v9fs_pack(qiov_full.iov, qiov_full.niov, offset, +v9fs_init_qiov_from_pdu (&qiov_full, pdu, offset, read_count, false);
v9fs_init_qiov_from_pducallsinit_in_iov_from_pdupassingread_countas size argument. offset is not passed toinit_in_iov_from_pdu, it is only used to initializedqiov_full.In other words, don't we need to:
Quoted 8 lines
Quoted 5 lines
v9fs_init_qiov_from_pdu(&qiov_full, pdu, offset, read_count + offset, false);To make sure that
qiov_fullhas "read_count+ offset" bytes in it, andqiov_fullis initialized skipping the first "offset" bytes?If we do that then
qemu_iovec_concat()will skip offset bytes and then copyread_count+ offset bytes or am I missing something ?You are right, sorry.
qemu_iovec_concatdidn't do what I thought it would. In that case, I think we need to changev9fs_init_qiov_from_pdu(in addition to the changes already in this patch):(quoted diff) +1
-1@@ -1659,12 +1659,14 @@ static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu, if (is_write) { pdu->s->transport->init_out_iov_from_pdu(pdu, &iov, &niov); } else { - pdu->s->transport->init_in_iov_from_pdu(pdu, &iov, &niov, size); + pdu->s->transport->init_in_iov_from_pdu(pdu, &iov, &niov, size + skip); }
Quoted 4 lines
The reason is the same as before: iov needs to have offset+read_count bytes in it, for
qemu_iovec_concatto skip offset and iov still haveread_countbytes left.
Ah! I had missed that since virtio_init_in_iov_from_pdu doesn't use the size argument, but I now understand :)
Thanks for the clarification.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
hw/9pfs/9p.c +1
-0+ err =v9fs_pack (qiov_full.iov, qiov_full.niov,0 , ((char *)fidp->fs.xattr.value) + off, read_count);qemu_iovec_destroy (&qiov_full);