Explorar o código

[SCTP] Fix leak in sctp_getsockopt_local_addrs when copy_to_user fails

If the copy_to_user or copy_user calls fail in sctp_getsockopt_local_addrs(),
the function should free locally allocated storage before returning error.
Spotted by Coverity.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Acked-by: Sridhar Samudrala <sri@us.ibm.com>
Vlad Yasevich %!s(int64=18) %!d(string=hai) anos
pai
achega
fe979ac169
Modificáronse 1 ficheiros con 5 adicións e 4 borrados
  1. 5 4
      net/sctp/socket.c

+ 5 - 4
net/sctp/socket.c

@@ -4352,11 +4352,12 @@ copy_getaddrs:
 		err = -EFAULT;
 		goto error;
 	}
-	if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num))
-		return -EFAULT;
+	if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) {
+		err = -EFAULT;
+		goto error;
+	}
 	if (put_user(bytes_copied, optlen))
-		return -EFAULT;
-
+		err = -EFAULT;
 error:
 	kfree(addrs);
 	return err;