mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 02:03:56 -06:00
9pfs: fix 'Twalk' protocol violation
Actual fix is patch 5, whereas patch 4 being preparatory, all other patches are test cases to guard this Twalk issue. -----BEGIN PGP SIGNATURE----- iQJLBAABCgA1FiEEltjREM96+AhPiFkBNMK1h2Wkc5UFAmKrDSAXHHFlbXVfb3Nz QGNydWRlYnl0ZS5jb20ACgkQNMK1h2Wkc5VgoQ//bA/lXYa6hds4f73+opq7iiJ/ 88gnJO8uPctNWXJ5f6ufXcTFtC99QRcl97jgSQhSIUdaZCfcpg7Pq3fONc060cMt MNxi5Da31Fq7xz4UhSQHgWlgAfomfClYoBSOtrrxjVbXChA2rB7FXhD9aewimUtt TlolXdJuPbGR3F6H0glN1itij12Ay5c0DMqFPy5npYlzjNhxmPb8QgFZ8E+lxhcT hG+OMmS9O5Mk7WKYWC1Iij7tWm45RbThPEUsfCPt6jIJYQqheOQs0ohJG9wyCZu3 JUCgSBPG1nNY0hgBJ/X7un7e89BoRw8edwqP+sSigfDf+LquUggqRFgz+joTbfvj Prq+1NTDIckDRZF6CDUSkZE3+Gq3qlIhw/2vS+bjYZrk04lP4x8d9JYPSkT3i8xc +YT/apDUkT68FjJ6PudfS2j6xRtYt86nOuWuhYukTZ2z5FJ0c9XAJlJX2ZS9Az3n AqKFCT+8UE4VYKnAJ61xDdqvAdEmKJUi5YutfuwH+j6sS4peLX0gg8mGlNi7y8JK bsqNjE1ve8rkp24DuUoHmivs/m1ogJi9Jxp5IjB4d26MPhgojrxOpaYUVg98QS7d os2ES47CSn4KFxqsFMZnZpgzKxIvRQ4C9bBbSClDOffHWHRJub6PCw5F9eCTH4dO z/QPJ+smDY7bolF+gSg= =3ejn -----END PGP SIGNATURE----- Merge tag 'pull-9p-20220616' of https://github.com/cschoenebeck/qemu into staging 9pfs: fix 'Twalk' protocol violation Actual fix is patch 5, whereas patch 4 being preparatory, all other patches are test cases to guard this Twalk issue. # -----BEGIN PGP SIGNATURE----- # # iQJLBAABCgA1FiEEltjREM96+AhPiFkBNMK1h2Wkc5UFAmKrDSAXHHFlbXVfb3Nz # QGNydWRlYnl0ZS5jb20ACgkQNMK1h2Wkc5VgoQ//bA/lXYa6hds4f73+opq7iiJ/ # 88gnJO8uPctNWXJ5f6ufXcTFtC99QRcl97jgSQhSIUdaZCfcpg7Pq3fONc060cMt # MNxi5Da31Fq7xz4UhSQHgWlgAfomfClYoBSOtrrxjVbXChA2rB7FXhD9aewimUtt # TlolXdJuPbGR3F6H0glN1itij12Ay5c0DMqFPy5npYlzjNhxmPb8QgFZ8E+lxhcT # hG+OMmS9O5Mk7WKYWC1Iij7tWm45RbThPEUsfCPt6jIJYQqheOQs0ohJG9wyCZu3 # JUCgSBPG1nNY0hgBJ/X7un7e89BoRw8edwqP+sSigfDf+LquUggqRFgz+joTbfvj # Prq+1NTDIckDRZF6CDUSkZE3+Gq3qlIhw/2vS+bjYZrk04lP4x8d9JYPSkT3i8xc # +YT/apDUkT68FjJ6PudfS2j6xRtYt86nOuWuhYukTZ2z5FJ0c9XAJlJX2ZS9Az3n # AqKFCT+8UE4VYKnAJ61xDdqvAdEmKJUi5YutfuwH+j6sS4peLX0gg8mGlNi7y8JK # bsqNjE1ve8rkp24DuUoHmivs/m1ogJi9Jxp5IjB4d26MPhgojrxOpaYUVg98QS7d # os2ES47CSn4KFxqsFMZnZpgzKxIvRQ4C9bBbSClDOffHWHRJub6PCw5F9eCTH4dO # z/QPJ+smDY7bolF+gSg= # =3ejn # -----END PGP SIGNATURE----- # gpg: Signature made Thu 16 Jun 2022 03:59:44 AM PDT # gpg: using RSA key 96D8D110CF7AF8084F88590134C2B58765A47395 # gpg: issuer "qemu_oss@crudebyte.com" # gpg: Good signature from "Christian Schoenebeck <qemu_oss@crudebyte.com>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: ECAB 1A45 4014 1413 BA38 4926 30DB 47C3 A012 D5F4 # Subkey fingerprint: 96D8 D110 CF7A F808 4F88 5901 34C2 B587 65A4 7395 * tag 'pull-9p-20220616' of https://github.com/cschoenebeck/qemu: tests/9pfs: check fid being unaffected in fs_walk_2nd_nonexistent tests/9pfs: guard recent 'Twalk' behaviour fix 9pfs: fix 'Twalk' to only send error if no component walked 9pfs: refactor 'name_idx' -> 'nwalked' in v9fs_walk() tests/9pfs: compare QIDs in fs_walk_none() test tests/9pfs: Twalk with nwname=0 tests/9pfs: walk to non-existent dir Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
213fda642d
2 changed files with 238 additions and 28 deletions
63
hw/9pfs/9p.c
63
hw/9pfs/9p.c
|
@ -1766,9 +1766,9 @@ static bool same_stat_id(const struct stat *a, const struct stat *b)
|
|||
|
||||
static void coroutine_fn v9fs_walk(void *opaque)
|
||||
{
|
||||
int name_idx;
|
||||
int name_idx, nwalked;
|
||||
g_autofree V9fsQID *qids = NULL;
|
||||
int i, err = 0;
|
||||
int i, err = 0, any_err = 0;
|
||||
V9fsPath dpath, path;
|
||||
P9ARRAY_REF(V9fsPath) pathes = NULL;
|
||||
uint16_t nwnames;
|
||||
|
@ -1834,54 +1834,61 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
|||
* driver code altogether inside the following block.
|
||||
*/
|
||||
v9fs_co_run_in_worker({
|
||||
nwalked = 0;
|
||||
if (v9fs_request_cancelled(pdu)) {
|
||||
err = -EINTR;
|
||||
any_err |= err = -EINTR;
|
||||
break;
|
||||
}
|
||||
err = s->ops->lstat(&s->ctx, &dpath, &fidst);
|
||||
if (err < 0) {
|
||||
err = -errno;
|
||||
any_err |= err = -errno;
|
||||
break;
|
||||
}
|
||||
stbuf = fidst;
|
||||
for (name_idx = 0; name_idx < nwnames; name_idx++) {
|
||||
for (; nwalked < nwnames; nwalked++) {
|
||||
if (v9fs_request_cancelled(pdu)) {
|
||||
err = -EINTR;
|
||||
any_err |= err = -EINTR;
|
||||
break;
|
||||
}
|
||||
if (!same_stat_id(&pdu->s->root_st, &stbuf) ||
|
||||
strcmp("..", wnames[name_idx].data))
|
||||
strcmp("..", wnames[nwalked].data))
|
||||
{
|
||||
err = s->ops->name_to_path(&s->ctx, &dpath,
|
||||
wnames[name_idx].data,
|
||||
&pathes[name_idx]);
|
||||
wnames[nwalked].data,
|
||||
&pathes[nwalked]);
|
||||
if (err < 0) {
|
||||
err = -errno;
|
||||
any_err |= err = -errno;
|
||||
break;
|
||||
}
|
||||
if (v9fs_request_cancelled(pdu)) {
|
||||
err = -EINTR;
|
||||
any_err |= err = -EINTR;
|
||||
break;
|
||||
}
|
||||
err = s->ops->lstat(&s->ctx, &pathes[name_idx], &stbuf);
|
||||
err = s->ops->lstat(&s->ctx, &pathes[nwalked], &stbuf);
|
||||
if (err < 0) {
|
||||
err = -errno;
|
||||
any_err |= err = -errno;
|
||||
break;
|
||||
}
|
||||
stbufs[name_idx] = stbuf;
|
||||
v9fs_path_copy(&dpath, &pathes[name_idx]);
|
||||
stbufs[nwalked] = stbuf;
|
||||
v9fs_path_copy(&dpath, &pathes[nwalked]);
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
* Handle all the rest of this Twalk request on main thread ...
|
||||
*
|
||||
* NOTE: -EINTR is an exception where we deviate from the protocol spec
|
||||
* and simply send a (R)Lerror response instead of bothering to assemble
|
||||
* a (deducted) Rwalk response; because -EINTR is always the result of a
|
||||
* Tflush request, so client would no longer wait for a response in this
|
||||
* case anyway.
|
||||
*/
|
||||
if (err < 0) {
|
||||
if ((err < 0 && !nwalked) || err == -EINTR) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = stat_to_qid(pdu, &fidst, &qid);
|
||||
if (err < 0) {
|
||||
any_err |= err = stat_to_qid(pdu, &fidst, &qid);
|
||||
if (err < 0 && !nwalked) {
|
||||
goto out;
|
||||
}
|
||||
stbuf = fidst;
|
||||
|
@ -1890,20 +1897,29 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
|||
v9fs_path_copy(&dpath, &fidp->path);
|
||||
v9fs_path_copy(&path, &fidp->path);
|
||||
|
||||
for (name_idx = 0; name_idx < nwnames; name_idx++) {
|
||||
for (name_idx = 0; name_idx < nwalked; name_idx++) {
|
||||
if (!same_stat_id(&pdu->s->root_st, &stbuf) ||
|
||||
strcmp("..", wnames[name_idx].data))
|
||||
{
|
||||
stbuf = stbufs[name_idx];
|
||||
err = stat_to_qid(pdu, &stbuf, &qid);
|
||||
any_err |= err = stat_to_qid(pdu, &stbuf, &qid);
|
||||
if (err < 0) {
|
||||
goto out;
|
||||
break;
|
||||
}
|
||||
v9fs_path_copy(&path, &pathes[name_idx]);
|
||||
v9fs_path_copy(&dpath, &path);
|
||||
}
|
||||
memcpy(&qids[name_idx], &qid, sizeof(qid));
|
||||
}
|
||||
if (any_err < 0) {
|
||||
if (!name_idx) {
|
||||
/* don't send any QIDs, send Rlerror instead */
|
||||
goto out;
|
||||
} else {
|
||||
/* send QIDs (not Rlerror), but fid MUST remain unaffected */
|
||||
goto send_qids;
|
||||
}
|
||||
}
|
||||
if (fid == newfid) {
|
||||
if (fidp->fid_type != P9_FID_NONE) {
|
||||
err = -EINVAL;
|
||||
|
@ -1921,8 +1937,9 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
|||
newfidp->uid = fidp->uid;
|
||||
v9fs_path_copy(&newfidp->path, &path);
|
||||
}
|
||||
err = v9fs_walk_marshal(pdu, nwnames, qids);
|
||||
trace_v9fs_walk_return(pdu->tag, pdu->id, nwnames, qids);
|
||||
send_qids:
|
||||
err = v9fs_walk_marshal(pdu, name_idx, qids);
|
||||
trace_v9fs_walk_return(pdu->tag, pdu->id, name_idx, qids);
|
||||
out:
|
||||
put_fid(pdu, fidp);
|
||||
if (newfidp) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue