Browse Source

NFS: Address memory leaks in the NFS client mount option parser

David Howells noticed that repeating the same mount option twice during an
NFS mount request can result in orphaned memory in certain cases.

Only the client_address and mount_server.hostname strings are initialized
in the mount parsing loop, so those appear to be the only two pointers that
might be written over by repeating a mount option.  The strings in the
nfs_server section of the nfs_parsed_mount_data structure are set only once
after the options are parsed, thus these are not susceptible to being
overwritten.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Chuck Lever 17 years ago
parent
commit
fc6014771b
1 changed files with 2 additions and 0 deletions
  1. 2 0
      fs/nfs/super.c

+ 2 - 0
fs/nfs/super.c

@@ -1006,12 +1006,14 @@ static int nfs_parse_mount_options(char *raw,
 			string = match_strdup(args);
 			string = match_strdup(args);
 			if (string == NULL)
 			if (string == NULL)
 				goto out_nomem;
 				goto out_nomem;
+			kfree(mnt->client_address);
 			mnt->client_address = string;
 			mnt->client_address = string;
 			break;
 			break;
 		case Opt_mounthost:
 		case Opt_mounthost:
 			string = match_strdup(args);
 			string = match_strdup(args);
 			if (string == NULL)
 			if (string == NULL)
 				goto out_nomem;
 				goto out_nomem;
+			kfree(mnt->mount_server.hostname);
 			mnt->mount_server.hostname = string;
 			mnt->mount_server.hostname = string;
 			break;
 			break;
 		case Opt_mountaddr:
 		case Opt_mountaddr: