nfs client: handle long symlinks properly
PATCH 1/1 nfs client: handle long symlinks properly
commit 87e03738fc15dc3ea4acde3a5dcb5f84b6b6152b
tree be323c0a65d7e380ad04cad1c3a80015a82056dd
parent bb52ef60b5caa8f973523eda15d3c3941f298e63
author Assar <[email protected]> Wed, 14 Sep 2005 16:59:25 -0400 committer Marcelo Tosatti <[email protected]> Thu, 22 Sep 2005 13:11:18 -0300
[PATCH] nfs client: handle long symlinks properly
In 2.4.31, the v2/3 nfs readlink accepts too long symlinks. I have tested this by having a server return long symlinks.
fs/nfs/nfs2xdr.c +5 -2
@@ -571,8 +571,11 @@ nfs_xdr_readlinkres(struct rpc_rqst *req strlen = (u32 *)kmap (rcvbuf->pages[0 ]);/* Convert length of symlink */ len =ntohl (*strlen); -if (len > rcvbuf->page_len) - len = rcvbuf->page_len; +if (len >= rcvbuf->page_len -sizeof (u32) || len >NFS2_MAXPATHLEN ) { +printk (KERN_WARNING "NFS: server returned giant symlink!\n" ); +kunmap (rcvbuf->pages[0 ]); +return -ENAMETOOLONG ; + } *strlen = len;/* NULL terminate the string we got */ string = (char *)(strlen +1 );
fs/nfs/nfs3xdr.c +5 -2
@@ -759,8 +759,11 @@ nfs3_xdr_readlinkres(struct rpc_rqst *re strlen = (u32 *)kmap (rcvbuf->pages[0 ]);/* Convert length of symlink */ len =ntohl (*strlen); -if (len > rcvbuf->page_len) - len = rcvbuf->page_len; +if (len >= rcvbuf->page_len -sizeof (u32)) { +printk (KERN_WARNING "NFS: server returned giant symlink!\n" ); +kunmap (rcvbuf->pages[0 ]); +return -ENAMETOOLONG ; + } *strlen = len;/* NULL terminate the string we got */ string = (char *)(strlen +1 );
to den 22.09.2005 Klokka 13:14 (-0300) skreiv Marcelo Tosatti:
Quoted 15 lines
commit
87e03738fc15dc3ea4acde3a5dcb5f84b6b6152b
treebe323c0a65d7e380ad04cad1c3a80015a82056dd
parentbb52ef60b5caa8f973523eda15d3c3941f298e63
author Assar <[email protected]> Wed, 14 Sep 2005 16:59:25 -0400 committer Marcelo Tosatti <[email protected]> Thu, 22 Sep 2005 13:11:18 -0300[PATCH] nfs client: handle long symlinks properly
In 2.4.31, the v2/3 nfs readlink accepts too long symlinks. I have tested this by having a server return long symlinks.
fs/nfs/nfs2xdr.c nfs_xdr_readlinkres(struct rpc_rqst *req · line 574
Quoted 6 lines
fs/nfs/nfs2xdr.c +1
-2@@ -571,8 +571,11 @@ nfs_xdr_readlinkres(struct rpc_rqst *req strlen = (u32 *)kmap (rcvbuf->pages[0 ]);/* Convert length of symlink */ len =ntohl (*strlen); -if (len > rcvbuf->page_len) - len = rcvbuf->page_len; +if (len >= rcvbuf->page_len -sizeof (u32) || len >NFS2_MAXPATHLEN ) {
Shouldn't that be
if (len > rcvbuf->page_len - sizeof(u32) || len > NFS2_MAXPATHLEN)
? As long as we use page_len == PAGE_SIZE, we probably don't care, but if someone some day decides to set a different value for page_len, then we want to make sure that we don't end up overflowing the buffer when we NUL-terminate.
fs/nfs/nfs2xdr.c nfs_xdr_readlinkres(struct rpc_rqst *req · line 575
Quoted 1 line
fs/nfs/nfs2xdr.c +1
-0+printk (KERN_WARNING "NFS: server returned giant symlink!\n" );
Please make this a dprintk().
Quoted 10 lines
fs/nfs/nfs2xdr.c +3
-0+kunmap (rcvbuf->pages[0 ]); +return -ENAMETOOLONG ; + } *strlen = len;/* NULL terminate the string we got */ string = (char *)(strlen +1 );
fs/nfs/nfs3xdr.c nfs3_xdr_readlinkres(struct rpc_rqst *re · line 762
Quoted 6 lines
fs/nfs/nfs3xdr.c +1
-2@@ -759,8 +759,11 @@ nfs3_xdr_readlinkres(struct rpc_rqst *re strlen = (u32 *)kmap (rcvbuf->pages[0 ]);/* Convert length of symlink */ len =ntohl (*strlen); -if (len > rcvbuf->page_len) - len = rcvbuf->page_len; +if (len >= rcvbuf->page_len -sizeof (u32)) {
Ditto.
fs/nfs/nfs3xdr.c nfs3_xdr_readlinkres(struct rpc_rqst *re · line 763
Quoted 1 line
fs/nfs/nfs3xdr.c +1
-0+printk (KERN_WARNING "NFS: server returned giant symlink!\n" );
...and ditto.
fs/nfs/nfs3xdr.c nfs3_xdr_readlinkres(struct rpc_rqst *re · line 769
Quoted 6 lines
fs/nfs/nfs3xdr.c +3
-0+kunmap (rcvbuf->pages[0 ]); +return -ENAMETOOLONG ; + } *strlen = len;/* NULL terminate the string we got */ string = (char *)(strlen +1 );
Cheers,
Trond
Quoted 13 lines · Trond Myklebust
fs/nfs/nfs2xdr.c nfs_xdr_readlinkres(struct rpc_rqst *req · line 574
Quoted 10 lines
fs/nfs/nfs2xdr.c +1
-2@@ -571,8 +571,11 @@ nfs_xdr_readlinkres(struct rpc_rqst *req strlen = (u32 *)kmap (rcvbuf->pages[0 ]);/* Convert length of symlink */ len =ntohl (*strlen); -if (len > rcvbuf->page_len) - len = rcvbuf->page_len; +if (len >= rcvbuf->page_len -sizeof (u32) || len >NFS2_MAXPATHLEN ) {Shouldn't that be
Quoted 6 lines
if (len > rcvbuf->page_len - sizeof(u32) || len > NFS2_MAXPATHLEN)? As long as we use
page_len==PAGE_SIZE, we probably don't care, but if someone some day decides to set a different value forpage_len, then we want to make sure that we don't end up overflowing the buffer when we NUL-terminate.
Wouldn't len == rcvbuf->page_len - sizeof(u32) mean that there isn't room for writing the terminating NUL?
to den 22.09.2005 Klokka 12:38 (-0400) skreiv Assar:
Quoted 2 lines
Wouldn't len ==
rcvbuf->page_len- sizeof(u32) mean that there isn't room for writing the terminating NUL?
Yep. My bad... I was screwing up the test in my mind.
Cheers,
Trond