BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Eric Dumazet <edumazet@google.com>,
	Feng zhou <zhoufeng.zf@bytedance.com>
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, dsahern@kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org, yangzhenze@bytedance.com,
	wangdongdong.6@bytedance.com
Subject: Re: [PATCH bpf-next v2] bpf: Fix bpf_get/setsockopt to tos not take effect when TCP over IPv4 via INET6 API
Date: Fri, 23 Aug 2024 11:48:44 -0700	[thread overview]
Message-ID: <173d3b06-57ed-4e2e-9034-91b99f41512b@linux.dev> (raw)
In-Reply-To: <CANn89i+ZsktuirATK0nhUmJu+TiqB9Kbozh+HhmCiP3qdnW3Ew@mail.gmail.com>

On 8/23/24 6:35 AM, Eric Dumazet wrote:
> On Fri, Aug 23, 2024 at 10:53 AM Feng zhou <zhoufeng.zf@bytedance.com> wrote:
>>
>> From: Feng Zhou <zhoufeng.zf@bytedance.com>
>>
>> when TCP over IPv4 via INET6 API, bpf_get/setsockopt with ipv4 will
>> fail, because sk->sk_family is AF_INET6. With ipv6 will success, not
>> take effect, because inet_csk(sk)->icsk_af_ops is ipv6_mapped and
>> use ip_queue_xmit, inet_sk(sk)->tos.
>>
>> So bpf_get/setsockopt needs add the judgment of this case. Just check
>> "inet_csk(sk)->icsk_af_ops == &ipv6_mapped".
>>
>> | Reported-by: kernel test robot <lkp@intel.com>
>> | Closes: https://lore.kernel.org/oe-kbuild-all/202408152034.lw9Ilsj6-lkp@intel.com/
>> Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
>> ---
>> Changelog:
>> v1->v2: Addressed comments from kernel test robot
>> - Fix compilation error
>> Details in here:
>> https://lore.kernel.org/bpf/202408152058.YXAnhLgZ-lkp@intel.com/T/
>>
>>   include/net/tcp.h   | 2 ++
>>   net/core/filter.c   | 6 +++++-
>>   net/ipv6/tcp_ipv6.c | 6 ++++++
>>   3 files changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/net/tcp.h b/include/net/tcp.h
>> index 2aac11e7e1cc..ea673f88c900 100644
>> --- a/include/net/tcp.h
>> +++ b/include/net/tcp.h
>> @@ -493,6 +493,8 @@ struct request_sock *cookie_tcp_reqsk_alloc(const struct request_sock_ops *ops,
>>                                              struct tcp_options_received *tcp_opt,
>>                                              int mss, u32 tsoff);
>>
>> +bool is_tcp_sock_ipv6_mapped(struct sock *sk);
>> +
>>   #if IS_ENABLED(CONFIG_BPF)
>>   struct bpf_tcp_req_attrs {
>>          u32 rcv_tsval;
>> diff --git a/net/core/filter.c b/net/core/filter.c
>> index ecf2ddf633bf..02a825e35c4d 100644
>> --- a/net/core/filter.c
>> +++ b/net/core/filter.c
>> @@ -5399,7 +5399,11 @@ static int sol_ip_sockopt(struct sock *sk, int optname,
>>                            char *optval, int *optlen,
>>                            bool getopt)
>>   {
>> -       if (sk->sk_family != AF_INET)
>> +       if (sk->sk_family != AF_INET
>> +#if IS_BUILTIN(CONFIG_IPV6)
>> +           && !is_tcp_sock_ipv6_mapped(sk)
>> +#endif
>> +           )
>>                  return -EINVAL;
> 
> This does not look right to me.
> 
> I would remove the test completely.
> 
> SOL_IP socket options are available on AF_INET6 sockets just fine.

Good point on the SOL_IP options.

The sk could be neither AF_INET nor AF_INET6. e.g. the bpf_get/setsockopt 
calling from the bpf_lsm's socket_post_create). so the AF_INET test is still needed.

Adding "&& sk->sk_family != AF_INET6" should do. From ipv6_setsockopt, I think 
it also needs to consider the "sk->sk_type != SOCK_RAW".

Please add a test in the next re-spin.

pw-bot: cr

  reply	other threads:[~2024-08-23 18:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-23  8:53 [PATCH bpf-next v2] bpf: Fix bpf_get/setsockopt to tos not take effect when TCP over IPv4 via INET6 API Feng zhou
2024-08-23 13:35 ` Eric Dumazet
2024-08-23 18:48   ` Martin KaFai Lau [this message]
2024-08-23 18:53     ` Eric Dumazet
2024-08-27  8:08       ` [External] " Feng Zhou
2024-09-13 14:44         ` Eric Dumazet
2024-09-14  2:19           ` Feng Zhou

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=173d3b06-57ed-4e2e-9034-91b99f41512b@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=wangdongdong.6@bytedance.com \
    --cc=yangzhenze@bytedance.com \
    --cc=yonghong.song@linux.dev \
    --cc=zhoufeng.zf@bytedance.com \
    /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