diff mbox series

[mptcp-next,1/2] mptcp: getsockopt: add support for IP_TOS

Message ID 20211122112205.16752-1-fw@strlen.de (mailing list archive)
State Superseded, archived
Delegated to: Matthieu Baerts
Headers show
Series [mptcp-next,1/2] mptcp: getsockopt: add support for IP_TOS | expand

Commit Message

Florian Westphal Nov. 22, 2021, 11:22 a.m. UTC
earlier patch added IP_TOS setsockopt support, this allows to get
the value set by earlier setsockopt.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/mptcp/sockopt.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Matthieu Baerts Nov. 22, 2021, 2:35 p.m. UTC | #1
Hi Florian,

On 22/11/2021 12:22, Florian Westphal wrote:
> earlier patch added IP_TOS setsockopt support, this allows to get
> the value set by earlier setsockopt.

Thank you for sharing the patches, good idea to add this!

> diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
> index 11cda8629993..5626b49c0270 100644
> --- a/net/mptcp/sockopt.c
> +++ b/net/mptcp/sockopt.c
> @@ -1066,6 +1066,24 @@ static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval,
>  	return 0;
>  }
>  
> +static int mptcp_put_int8_option(struct mptcp_sock *msk, char __user *optval,
> +				 int __user *optlen, u8 val)
> +{
> +	int len;
> +
> +	if (get_user(len, optlen))
> +		return -EFAULT;
> +
> +	if (len) {

What can be the possible values of 'len' here? Can it be negative?

I'm asking this question because when I'm looking at similar code in
mptcp/sockopt.c, I see different behaviours:

- mptcp_getsockopt_info(): no additional check but we suppose 'len' is
unsigned

- mptcp_put_int_option(): same but we return an error if len < 0

- mptcp_get_subflow_data(): we check if len is not < the expected size

In ipv4/ip_sockglue.c, we check if len < 0

I don't know if we should uniform that and always do:

    if (len < 0 (or expected value))
        return (...);

But I'm fine with the current version if we would never have a negative
value.

Cheers,
Matt
diff mbox series

Patch

diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 11cda8629993..5626b49c0270 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -1066,6 +1066,24 @@  static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval,
 	return 0;
 }
 
+static int mptcp_put_int8_option(struct mptcp_sock *msk, char __user *optval,
+				 int __user *optlen, u8 val)
+{
+	int len;
+
+	if (get_user(len, optlen))
+		return -EFAULT;
+
+	if (len) {
+		if (put_user(1, optlen))
+			return -EFAULT;
+		if (copy_to_user(optval, &val, 1))
+			return -EFAULT;
+	}
+
+	return 0;
+}
+
 static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 				    char __user *optval, int __user *optlen)
 {
@@ -1082,6 +1100,19 @@  static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 	return -EOPNOTSUPP;
 }
 
+static int mptcp_getsockopt_v4(struct mptcp_sock *msk, int optname,
+			       char __user *optval, int __user *optlen)
+{
+	struct sock *sk = (void *)msk;
+
+	switch (optname) {
+	case IP_TOS:
+		return mptcp_put_int8_option(msk, optval, optlen, inet_sk(sk)->tos);
+	}
+
+	return -EOPNOTSUPP;
+}
+
 static int mptcp_getsockopt_sol_mptcp(struct mptcp_sock *msk, int optname,
 				      char __user *optval, int __user *optlen)
 {
@@ -1117,6 +1148,8 @@  int mptcp_getsockopt(struct sock *sk, int level, int optname,
 	if (ssk)
 		return tcp_getsockopt(ssk, level, optname, optval, option);
 
+	if (level == SOL_IP)
+		return mptcp_getsockopt_v4(msk, optname, optval, option);
 	if (level == SOL_TCP)
 		return mptcp_getsockopt_sol_tcp(msk, optname, optval, option);
 	if (level == SOL_MPTCP)