[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <41aac020-b7af-e83f-0639-252efa4f7fff@iogearbox.net>
Date: Fri, 20 Nov 2020 17:01:57 +0100
From: Daniel Borkmann <daniel@...earbox.net>
To: David Ahern <dsahern@...il.com>, xiakaixu1987@...il.com,
ast@...nel.org, kafai@...com, songliubraving@...com, yhs@...com,
andrii@...nel.org, john.fastabend@...il.com, kpsingh@...omium.org
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org,
linux-kernel@...r.kernel.org, Kaixu Xia <kaixuxia@...cent.com>
Subject: Re: [PATCH] bpf: Check the return value of dev_get_by_index_rcu()
On 11/20/20 4:19 PM, David Ahern wrote:
> On 11/20/20 8:13 AM, Daniel Borkmann wrote:
>> [ +David ]
>>
>> On 11/19/20 8:04 AM, xiakaixu1987@...il.com wrote:
>>> From: Kaixu Xia <kaixuxia@...cent.com>
>>>
>>> The return value of dev_get_by_index_rcu() can be NULL, so here it
>>> is need to check the return value and return error code if it is NULL.
>>>
>>> Signed-off-by: Kaixu Xia <kaixuxia@...cent.com>
>>> ---
>>> net/core/filter.c | 2 ++
>>> 1 file changed, 2 insertions(+)
>>>
>>> diff --git a/net/core/filter.c b/net/core/filter.c
>>> index 2ca5eecebacf..1263fe07170a 100644
>>> --- a/net/core/filter.c
>>> +++ b/net/core/filter.c
>>> @@ -5573,6 +5573,8 @@ BPF_CALL_4(bpf_skb_fib_lookup, struct sk_buff *,
>>> skb,
>>> struct net_device *dev;
>>> dev = dev_get_by_index_rcu(net, params->ifindex);
>>> + if (unlikely(!dev))
>>> + return -EINVAL;
>>> if (!is_skb_forwardable(dev, skb))
>>> rc = BPF_FIB_LKUP_RET_FRAG_NEEDED;
>
> rcu lock is held right? It is impossible for dev to return NULL here.
Yes, we're under RCU read side. Was wondering whether we could unlink it
from the list but not yet free it, but also that seems not possible since
we'd first need to close it which already has a synchronize_net(). So not
an issue what Kaixu describes in the commit msg, agree.
Powered by blists - more mailing lists