--- sys/fs/nfs/nfs_var.h.orig +++ sys/fs/nfs/nfs_var.h @@ -368,7 +368,7 @@ struct ucred *, NFSPROC_T *); /* nfs_clcomsubs.c */ -void nfsm_uiombuf(struct nfsrv_descript *, struct uio *, int); +int nfsm_uiombuf(struct nfsrv_descript *, struct uio *, int); struct mbuf *nfsm_uiombuflist(struct uio *, int, u_int); u_int8_t *nfscl_getmyip(struct nfsmount *, struct in6_addr *, int *); int nfsm_getfh(struct nfsrv_descript *, struct nfsfh **); --- sys/fs/nfsclient/nfs_clcomsubs.c.orig +++ sys/fs/nfsclient/nfs_clcomsubs.c @@ -53,12 +53,12 @@ * copies a uio scatter/gather list to an mbuf chain. * NOTE: can only handle iovcnt == 1 */ -void +int nfsm_uiombuf(struct nfsrv_descript *nd, struct uio *uiop, int siz) { char *uiocp; struct mbuf *mp, *mp2; - int xfer, left, mlen; + int error, xfer, left, mlen; int uiosiz, clflg, rem; char *mcp, *tcp; @@ -106,8 +106,11 @@ xfer = (left > mlen) ? mlen : left; if (uiop->uio_segflg == UIO_SYSSPACE) NFSBCOPY(uiocp, mcp, xfer); - else - copyin(uiocp, mcp, xfer); + else { + error = copyin(uiocp, mcp, xfer); + if (error != 0) + return (error); + } mp->m_len += xfer; left -= xfer; uiocp += xfer; @@ -150,6 +153,7 @@ } nd->nd_bpos = mcp; nd->nd_mb = mp; + return (0); } /* @@ -162,7 +166,7 @@ { char *uiocp; struct mbuf *mp, *mp2, *firstmp; - int extpg, extpgsiz = 0, i, left, mlen, rem, xfer; + int error, extpg, extpgsiz = 0, i, left, mlen, rem, xfer; int uiosiz, clflg; char *mcp, *tcp; @@ -220,8 +224,13 @@ xfer = (left > mlen) ? mlen : left; if (uiop->uio_segflg == UIO_SYSSPACE) NFSBCOPY(uiocp, mcp, xfer); - else - copyin(uiocp, mcp, xfer); + else { + error = copyin(uiocp, mcp, xfer); + if (error != 0) { + m_freem(firstmp); + return (NULL); + } + } mp->m_len += xfer; mcp += xfer; if (maxext > 0) { --- sys/fs/nfsclient/nfs_clrpcops.c.orig +++ sys/fs/nfsclient/nfs_clrpcops.c @@ -1890,7 +1890,12 @@ *tl++ = x; /* total to this offset */ *tl = x; /* size of this write */ } - nfsm_uiombuf(nd, uiop, len); + error = nfsm_uiombuf(nd, uiop, len); + if (error != 0) { + m_freem(nd->nd_mreq); + free(nd, M_TEMP); + return (error); + } /* * Although it is tempting to do a normal Getattr Op in the * NFSv4 compound, the result can be a nearly hung client @@ -5981,6 +5986,10 @@ iovlen = uiop->uio_iov->iov_len; m = nfsm_uiombuflist(uiop, len, 0); + if (m == NULL) { + error = EFAULT; + break; + } } tdrpc = drpc = malloc(sizeof(*drpc) * (mirrorcnt - 1), M_TEMP, M_WAITOK | @@ -6553,7 +6562,11 @@ *tl++ = txdr_unsigned(len); *tl++ = txdr_unsigned(*iomode); *tl = txdr_unsigned(len); - nfsm_uiombuf(nd, uiop, len); + error = nfsm_uiombuf(nd, uiop, len); + if (error != 0) { + m_freem(nd->nd_mreq); + return (error); + } nrp = dsp->nfsclds_sockp; if (nrp == NULL) /* If NULL, use the MDS socket. */ @@ -8639,7 +8652,11 @@ nfsm_strtom(nd, name, strlen(name)); NFSM_BUILD(tl, uint32_t *, NFSX_UNSIGNED); *tl = txdr_unsigned(uiop->uio_resid); - nfsm_uiombuf(nd, uiop, uiop->uio_resid); + error = nfsm_uiombuf(nd, uiop, uiop->uio_resid); + if (error != 0) { + m_freem(nd->nd_mreq); + return (error); + } NFSM_BUILD(tl, uint32_t *, NFSX_UNSIGNED); *tl = txdr_unsigned(NFSV4OP_GETATTR); NFSGETATTR_ATTRBIT(&attrbits); --- sys/fs/nfsclient/nfs_clvnops.c.orig +++ sys/fs/nfsclient/nfs_clvnops.c @@ -1579,7 +1579,7 @@ error = nfscl_doiods(vp, uiop, NULL, NULL, NFSV4OPEN_ACCESSREAD, 0, cred, uiop->uio_td); NFSCL_DEBUG(4, "readrpc: aft doiods=%d\n", error); - if (error != 0) + if (error != 0 && error != EFAULT) error = nfsrpc_read(vp, uiop, cred, uiop->uio_td, &nfsva, &attrflag, NULL); if (attrflag) { @@ -1610,7 +1610,7 @@ error = nfscl_doiods(vp, uiop, iomode, must_commit, NFSV4OPEN_ACCESSWRITE, 0, cred, uiop->uio_td); NFSCL_DEBUG(4, "writerpc: aft doiods=%d\n", error); - if (error != 0) + if (error != 0 && error != EFAULT) error = nfsrpc_write(vp, uiop, iomode, must_commit, cred, uiop->uio_td, &nfsva, &attrflag, called_from_strategy, ioflag);