BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Rongfeng Ji <SikoJobs@outlook.com>
Cc: ast@kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf] bpf: Return -EINVAL on calling bpf_setsockopt(TCP_SAVED_SYN)
Date: Tue, 25 Oct 2022 17:02:51 -0700	[thread overview]
Message-ID: <f48318a0-b155-fd3f-cbaa-39de793bf2f4@linux.dev> (raw)
In-Reply-To: <DU0P192MB1547197315863E8092FC603AD6319@DU0P192MB1547.EURP192.PROD.OUTLOOK.COM>

On 10/25/22 4:22 AM, Rongfeng Ji wrote:
> TCP_SAVED_SYN is not supported by do_tcp_setsockopt(), but it is not
> rejected by sol_tcp_sockopt() during calling bpf_setsockopt(), which
> results in returning -ENOPROTOOPT instead of common -EINVAL.
> 
> This patch fixes the issue.
> 
> Signed-off-by: Rongfeng Ji <SikoJobs@outlook.com>
> ---
>   net/core/filter.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/net/core/filter.c b/net/core/filter.c
> index bb0136e7a8e4..42cd7ec8cc4c 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -5206,6 +5206,9 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
>   		return do_tcp_getsockopt(sk, SOL_TCP, optname,
>   					 KERNEL_SOCKPTR(optval),
>   					 KERNEL_SOCKPTR(optlen));
> +	} else {
> +		if (optname == TCP_SAVED_SYN)
> +			return -EINVAL;

ENOPROTOOPT is fine and is better imo.  man 7 setsockopt:

        ENOPROTOOPT
                  The option is unknown at the level indicated.

It is why I did not single out the TCP_SAVED_SYN again to return -EINVAL.
I don't see how the bpf_prog would handle them differently (bpf prog does not 
allow it -EINVAL or the underlying kernel's setsockopt does not know it 
-ENOPROTOOPT).  In general, the bpf_{get,set}sockopt caller has to be ready to 
handle any errno from the kernel underlying {get,set}sockopt.

Also, some of the -EINVAL in bpf_{get,set}sockopt() is not the best one to 
return.  It is not very helpful for the bpf prog to figure out what is wrong. 
They should be fixed in the future also.


      reply	other threads:[~2022-10-26  0:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 11:22 [PATCH bpf] bpf: Return -EINVAL on calling bpf_setsockopt(TCP_SAVED_SYN) Rongfeng Ji
2022-10-26  0:02 ` Martin KaFai Lau [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f48318a0-b155-fd3f-cbaa-39de793bf2f4@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=SikoJobs@outlook.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox