From: Jesper Dangaard Brouer <hawk@kernel.org>
To: Edward Adam Davis <eadavis@qq.com>
Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org,
daniel@iogearbox.net, davem@davemloft.net, eddyz87@gmail.com,
haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org,
kpsingh@kernel.org, kuba@kernel.org,
linux-kernel@vger.kernel.org, martin.lau@linux.dev,
netdev@vger.kernel.org, sdf@google.com, song@kernel.org,
syzbot+af9492708df9797198d6@syzkaller.appspotmail.com,
syzkaller-bugs@googlegroups.com, yonghong.song@linux.dev
Subject: Re: [PATCH] bpf: fix null ptr deref in dev_map_enqueue
Date: Thu, 4 Apr 2024 13:03:17 +0200 [thread overview]
Message-ID: <15064d90-e89d-4522-90a8-52aad643d7c8@kernel.org> (raw)
In-Reply-To: <tencent_A4FA0DA89270DDAC5D8519424F9B0DB42507@qq.com>
On 02/04/2024 05.03, Edward Adam Davis wrote:
> On Mon, 1 Apr 2024 13:00:12 +0200, Jesper Dangaard Brouer wrote:
>>> [Fix]
>>> On the execution path of bpf_prog_test_run(), due to ri->map being NULL,
>>> ri->tgtvalue was not set correctly.
>>>
>>> Reported-and-tested-by:syzbot+af9492708df9797198d6@syzkaller.appspotmail.com
>>> Signed-off-by: Edward Adam Davis<eadavis@qq.com>
>>> ---
>>> kernel/bpf/devmap.c | 6 +++++-
>>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
>>> index 4e2cdbb5629f..ef20de14154a 100644
>>> --- a/kernel/bpf/devmap.c
>>> +++ b/kernel/bpf/devmap.c
>>> @@ -86,6 +86,7 @@ struct bpf_dtab {
>>> static DEFINE_PER_CPU(struct list_head, dev_flush_list);
>>> static DEFINE_SPINLOCK(dev_map_lock);
>>> static LIST_HEAD(dev_map_list);
>>> +static bool is_valid_dst(struct bpf_dtab_netdev *obj, struct xdp_frame *xdpf);
>>>
>>> static struct hlist_head *dev_map_create_hash(unsigned int entries,
>>> int numa_node)
>>> @@ -536,7 +537,10 @@ int dev_xdp_enqueue(struct net_device *dev, struct xdp_frame *xdpf,
>>> int dev_map_enqueue(struct bpf_dtab_netdev *dst, struct xdp_frame *xdpf,
>>> struct net_device *dev_rx)
>>> {
>>> - struct net_device *dev = dst->dev;
>>> + struct net_device *dev;
>>> + if (!is_valid_dst(dst, xdpf))
>> This is overkill, because __xdp_enqueue() already contains most of the
>> checks in is_valid_dst().
>>
>> Why not:
>>
>> if (!dst)
>> return -EINVAL;
> This can work, but I think is_valid_dst() is better, as its internal inspection
> of dst is more thorough.
No, is_valid_dst() is not better, because it will repeat almost same
checks (as I said) as __xdp_enqueue() already contains these checks.
This is fast-path code, we don't want to repeat checks.
--Jesper
(copy-pasted function below to easier compare)
static inline int __xdp_enqueue(struct net_device *dev, struct xdp_frame
*xdpf,
struct net_device *dev_rx,
struct bpf_prog *xdp_prog)
{
int err;
if (!(dev->xdp_features & NETDEV_XDP_ACT_NDO_XMIT))
return -EOPNOTSUPP;
if (unlikely(!(dev->xdp_features & NETDEV_XDP_ACT_NDO_XMIT_SG) &&
xdp_frame_has_frags(xdpf)))
return -EOPNOTSUPP;
err = xdp_ok_fwd_dev(dev, xdp_get_frame_len(xdpf));
if (unlikely(err))
return err;
bq_enqueue(dev, xdpf, dev_rx, xdp_prog);
return 0;
}
static bool is_valid_dst(struct bpf_dtab_netdev *obj, struct xdp_frame
*xdpf)
{
if (!obj)
return false;
if (!(obj->dev->xdp_features & NETDEV_XDP_ACT_NDO_XMIT))
return false;
if (unlikely(!(obj->dev->xdp_features & NETDEV_XDP_ACT_NDO_XMIT_SG) &&
xdp_frame_has_frags(xdpf)))
return false;
if (xdp_ok_fwd_dev(obj->dev, xdp_get_frame_len(xdpf)))
return false;
return true;
}
next prev parent reply other threads:[~2024-04-04 11:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-26 19:00 [syzbot] [bpf?] [net?] general protection fault in dev_map_enqueue syzbot
2024-03-27 8:10 ` syzbot
2024-03-27 15:19 ` Alexei Starovoitov
2024-03-28 8:58 ` Jesper Dangaard Brouer
2024-03-28 20:39 ` Toke Høiland-Jørgensen
2024-03-31 9:08 ` [PATCH] bpf: fix null ptr deref " Edward Adam Davis
2024-04-01 11:00 ` Jesper Dangaard Brouer
2024-04-02 3:03 ` Edward Adam Davis
2024-04-04 11:03 ` Jesper Dangaard Brouer [this message]
2024-04-04 21:02 ` Toke Høiland-Jørgensen
2024-04-05 3:55 ` [syzbot] [bpf?] [net?] general protection fault " syzbot
2024-04-08 15:30 ` Toke Høiland-Jørgensen
2024-04-08 22:03 ` syzbot
2024-04-16 20:55 ` Toke Høiland-Jørgensen
2024-04-17 14:49 ` syzbot
2024-04-17 19:18 ` Toke Høiland-Jørgensen
2024-04-18 2:51 ` syzbot
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=15064d90-e89d-4522-90a8-52aad643d7c8@kernel.org \
--to=hawk@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eadavis@qq.com \
--cc=eddyz87@gmail.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=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=syzbot+af9492708df9797198d6@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=yonghong.song@linux.dev \
/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;
as well as URLs for NNTP newsgroup(s).