Module Name: src Committed By: jakllsch Date: Fri Jan 20 22:07:58 UTC 2012
Modified Files: src/usr.sbin/puffs/mount_psshfs: node.c Log Message: Ensure psshfs_node_read() completely reads all data before return. Fixes file corruption in psshfs exposed with kernel MAXPHYS at 128KiB. To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 src/usr.sbin/puffs/mount_psshfs/node.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/puffs/mount_psshfs/node.c diff -u src/usr.sbin/puffs/mount_psshfs/node.c:1.63 src/usr.sbin/puffs/mount_psshfs/node.c:1.64 --- src/usr.sbin/puffs/mount_psshfs/node.c:1.63 Fri Aug 12 04:14:00 2011 +++ src/usr.sbin/puffs/mount_psshfs/node.c Fri Jan 20 22:07:58 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: node.c,v 1.63 2011/08/12 04:14:00 riastradh Exp $ */ +/* $NetBSD: node.c,v 1.64 2012/01/20 22:07:58 jakllsch Exp $ */ /* * Copyright (c) 2006-2009 Antti Kantee. All Rights Reserved. @@ -27,7 +27,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: node.c,v 1.63 2011/08/12 04:14:00 riastradh Exp $"); +__RCSID("$NetBSD: node.c,v 1.64 2012/01/20 22:07:58 jakllsch Exp $"); #endif /* !lint */ #include <assert.h> @@ -525,6 +525,7 @@ psshfs_node_read(struct puffs_usermount goto farout; } +again: readlen = *resid; psbuf_req_data(pb, SSH_FXP_READ, reqid, psn->fhand_r, psn->fhand_r_len); psbuf_put_8(pb, offset); @@ -546,8 +547,11 @@ psshfs_node_read(struct puffs_usermount GETRESPONSE(pb, pctx->sshfd_data); rv = psbuf_do_data(pb, buf, &readlen); - if (rv == 0) + if (rv == 0) { *resid -= readlen; + buf += readlen; + offset += readlen; + } out: if (max_reads && --psn->readcount >= max_reads) { @@ -559,6 +563,12 @@ psshfs_node_read(struct puffs_usermount TAILQ_REMOVE(&psn->pw, pwp, pw_entries); } + if (rv == 0 && *resid > 0) { + reqid = NEXTREQ(pctx); + psbuf_recycleout(pb); + goto again; + } + farout: /* check if we need a lazyclose */ if (psn->stat & PSN_HANDLECLOSE && psn->fhand_r) {