Two hardening fixes for junction handling
Subsystems (2)
cover Two hardening fixes for junction handling
The first patch fixes a buffer overrun in junction_parse_xml_read() and the second fixes a use-after-free when parsing multi-location junctions in locations_to_fslocdata().
Scott Mayhew (2):
junction: fix buffer over-read in junction_parse_xml_read()
junction: fix use-after-free in locations_to_fslocdata()
support/export/cache.c | 6 ++++++ support/junction/junction.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
2.55.0
PATCH 1/2 junction: fix buffer over-read in junction_parse_xml_read()
junction_get_xattr() returns an opaque buffer, but junction_parse_xml_read() treats it as a string by passing it to xlog(). Fix it by allocating an extra byte and null-terminating the buffer in junction_get_xattr().
--- support/junction/junction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
support/junction/junction.c +2 -1
@@ -293,7 +293,7 @@ junction_get_xattr(int fd, const char *path, const char *name, void **contents,return FEDFS_ERR_ACCESS ; } - xattrbuf =malloc ((size_t )len); + xattrbuf =malloc ((size_t )len +1 );if (xattrbuf ==NULL ) {xlog (D_GENERAL ,"%s: failed to get buffer for xattr %s on %s" , __func__, name, path);
@@ -307,6 +307,7 @@ junction_get_xattr(int fd, const char *path, const char *name, void **contents,return FEDFS_ERR_ACCESS ; } + ((char *) xattrbuf)[len] ='\0' ;xlog (D_CALL ,"%s: read xattr %s from path %s" , __func__, name, path); *contents = xattrbuf;
Signature · 1 line
2.55.0
Re: [nfs-utils PATCH 1/2] junction: fix buffer over-read in junction_parse_xml_read()
Quoted 6 lines · Scott Mayhew
junction_get_xattr()returns an opaque buffer, butjunction_parse_xml_read()treats it as a string by passing it toxlog(). Fix it by allocating an extra byte and null-terminating the buffer injunction_get_xattr().Signed-off-by Scott Mayhew <[email protected]>
Committed... (tag: nfs-utils-2-9-3-rc4)
steved.
Quoted 25 lines
--- support/junction/junction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)support/junction/junction.c +2
-1@@ -293,7 +293,7 @@ junction_get_xattr(int fd, const char *path, const char *name, void **contents,return FEDFS_ERR_ACCESS ; } - xattrbuf =malloc ((size_t )len); + xattrbuf =malloc ((size_t )len +1 );if (xattrbuf ==NULL ) {xlog (D_GENERAL ,"%s: failed to get buffer for xattr %s on %s" , __func__, name, path);@@ -307,6 +307,7 @@ junction_get_xattr(int fd, const char *path, const char *name, void **contents,return FEDFS_ERR_ACCESS ; } + ((char *) xattrbuf)[len] ='\0' ;xlog (D_CALL ,"%s: read xattr %s from path %s" , __func__, name, path); *contents = xattrbuf;
PATCH 2/2 junction: fix use-after-free in locations_to_fslocdata()
In reply to Scott MayhewWhile parsing a multi-location junction, locations_to_fslocdata() sets last_path = root_path and then frees root_path, leaving last_path dangling. On the next iteration, strcmp(rootpath, last_path) dereferences freed memory.
Fix it by transferring ownership of root_path to last_path when they should be aliased.
--- support/export/cache.c | 6 ++++++ 1 file changed, 6 insertions(+)
support/export/cache.c +6 -0
@@ -2806,19 +2806,25 @@ static bool locations_to_fslocdata(struct nfs_fsloc_set *locations, } remaining -= (size_t )len; ptr += len; +free (last_path); last_path = rootpath; + rootpath =NULL ; } seen = true;free (rootpath); + rootpath =NULL ;free (server); + server =NULL ; } +free (last_path);xlog (D_CALL ,"%s: fslocdata='%s', ttl=%d" , __func__, fslocdata, *ttl);return seen; out_false: +free (last_path);free (rootpath);free (server);return false;
Signature · 1 line
2.55.0
Re: [nfs-utils PATCH 2/2] junction: fix use-after-free in locations_to_fslocdata()
Quoted 9 lines · Scott Mayhew
While parsing a multi-location junction,
locations_to_fslocdata()setslast_path=root_pathand then freesroot_path, leavinglast_pathdangling. On the next iteration,strcmp(rootpath, last_path)dereferences freed memory.Fix it by transferring ownership of
root_pathtolast_pathwhen they should be aliased.Signed-off-by Scott Mayhew <[email protected]>
Committed... (tag: nfs-utils-2-9-3-rc4)
steved.
Quoted 34 lines
--- support/export/cache.c | 6 ++++++ 1 file changed, 6 insertions(+)support/export/cache.c +6
-0@@ -2806,19 +2806,25 @@ static bool locations_to_fslocdata(struct nfs_fsloc_set *locations, } remaining -= (size_t )len; ptr += len; +free (last_path); last_path = rootpath; + rootpath =NULL ; } seen = true;free (rootpath); + rootpath =NULL ;free (server); + server =NULL ; } +free (last_path);xlog (D_CALL ,"%s: fslocdata='%s', ttl=%d" , __func__, fslocdata, *ttl);return seen; out_false: +free (last_path);free (rootpath);free (server);return false;