mptcp_getsockopt_info() reads optlen as a signed int but converts it to
unsigned int in min_t(). A negative value therefore selects the full
MPTCP_INFO structure instead of being rejected.
Reject negative lengths before the zero-length check and unsigned
conversion.
Tested on x86_64 with QEMU TCG. Negative lengths return -EINVAL without
changing optlen or the output buffer; nonnegative length controls pass.
Link: https://gist.github.com/shaos26/a719048f273e0e3bd14b1fb9feee1e4a
Fixes: 55c42fa7fa33 ("mptcp: add MPTCP_INFO getsockopt")
Signed-off-by: Shawn Shao <shaw…@163.com>
---
net/mptcp/sockopt.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index fcf6feb2a9eb5..84d9ce2a9ba81 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -1038,6 +1038,8 @@ static int mptcp_getsockopt_info(struct mptcp_sock *msk, char __user *optval, in
if (get_user(len, optlen))
return -EFAULT;
+ if (len < 0)
+ return -EINVAL;
/* When used only to check if a fallback to TCP happened. */
if (len == 0)
--
2.34.1